diff --git a/Server/KonfDB.Infrastructure/Configuration/HostConfig.cs b/Server/KonfDB.Infrastructure/Configuration/HostConfig.cs index 8923eea..8d1ffb5 100644 --- a/Server/KonfDB.Infrastructure/Configuration/HostConfig.cs +++ b/Server/KonfDB.Infrastructure/Configuration/HostConfig.cs @@ -26,6 +26,8 @@ using KonfDB.Infrastructure.Configuration.Caching; using KonfDB.Infrastructure.Configuration.Interfaces; using KonfDB.Infrastructure.Configuration.Providers; +using KonfDB.Infrastructure.Configuration.Providers.Certificate; +using KonfDB.Infrastructure.Configuration.Providers.Database; using KonfDB.Infrastructure.Configuration.Runtime; using Newtonsoft.Json; @@ -39,14 +41,18 @@ internal class HostConfig : IHostConfig [JsonProperty("cache")] public CacheConfigurationSection Caching { get; private set; } - [JsonProperty("providers")] - public ProvidersConfiguration Providers { get; private set; } + [JsonProperty("database")] + public DatabaseProviderCollection Database { get; set; } + + [JsonProperty("certificates")] + public CertificateProviderCollection Certificate { get; set; } public HostConfig() { Runtime = new HostRuntimeConfiguration(); Caching = new CacheConfigurationSection(); - Providers = new ProvidersConfiguration(); + Database = new DatabaseProviderCollection(); + Certificate = new CertificateProviderCollection(); } } } \ No newline at end of file diff --git a/Server/KonfDB.Infrastructure/Configuration/Interfaces/IHostConfig.cs b/Server/KonfDB.Infrastructure/Configuration/Interfaces/IHostConfig.cs index 9138b65..2866589 100644 --- a/Server/KonfDB.Infrastructure/Configuration/Interfaces/IHostConfig.cs +++ b/Server/KonfDB.Infrastructure/Configuration/Interfaces/IHostConfig.cs @@ -25,6 +25,8 @@ using KonfDB.Infrastructure.Configuration.Caching; using KonfDB.Infrastructure.Configuration.Providers; +using KonfDB.Infrastructure.Configuration.Providers.Certificate; +using KonfDB.Infrastructure.Configuration.Providers.Database; using KonfDB.Infrastructure.Configuration.Runtime; namespace KonfDB.Infrastructure.Configuration.Interfaces @@ -33,6 +35,7 @@ internal interface IHostConfig { HostRuntimeConfiguration Runtime { get; } CacheConfigurationSection Caching { get; } - ProvidersConfiguration Providers { get; } + DatabaseProviderCollection Database { get; set; } + CertificateProviderCollection Certificate { get; set; } } } \ No newline at end of file diff --git a/Server/KonfDB.Infrastructure/Configuration/Interfaces/IProvidersConfiguration.cs b/Server/KonfDB.Infrastructure/Configuration/Interfaces/IProvidersConfiguration.cs deleted file mode 100644 index af05bb8..0000000 --- a/Server/KonfDB.Infrastructure/Configuration/Interfaces/IProvidersConfiguration.cs +++ /dev/null @@ -1,38 +0,0 @@ -#region License and Product Information - -// -// This file 'IProvidersConfiguration.cs' is part of KonfDB application - -// a project perceived and developed by Punit Ganshani. -// -// KonfDB is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// KonfDB is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with KonfDB. If not, see . -// -// You can also view the documentation and progress of this project 'KonfDB' -// on the project website, or on -// - -#endregion - -using KonfDB.Infrastructure.Configuration.Providers.Certificate; -using KonfDB.Infrastructure.Configuration.Providers.Database; -using KonfDB.Infrastructure.Configuration.Providers.Types; - -namespace KonfDB.Infrastructure.Configuration.Interfaces -{ - internal interface IProvidersConfiguration - { - DatabaseProviderCollection Database { get; set; } - CertificateProviderCollection Certificate { get; set; } - ProviderTypesCollection Types { get; set; } - } -} \ No newline at end of file diff --git a/Server/KonfDB.Infrastructure/Configuration/Providers/ProvidersConfiguration.cs b/Server/KonfDB.Infrastructure/Configuration/Providers/ProvidersConfiguration.cs deleted file mode 100644 index a1d42fa..0000000 --- a/Server/KonfDB.Infrastructure/Configuration/Providers/ProvidersConfiguration.cs +++ /dev/null @@ -1,52 +0,0 @@ -#region License and Product Information - -// -// This file 'ProvidersConfiguration.cs' is part of KonfDB application - -// a project perceived and developed by Punit Ganshani. -// -// KonfDB is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// KonfDB is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with KonfDB. If not, see . -// -// You can also view the documentation and progress of this project 'KonfDB' -// on the project website, or on -// - -#endregion - -using KonfDB.Infrastructure.Configuration.Interfaces; -using KonfDB.Infrastructure.Configuration.Providers.Certificate; -using KonfDB.Infrastructure.Configuration.Providers.Database; -using KonfDB.Infrastructure.Configuration.Providers.Types; -using Newtonsoft.Json; - -namespace KonfDB.Infrastructure.Configuration.Providers -{ - internal class ProvidersConfiguration : IProvidersConfiguration - { - [JsonProperty("databaseProviders")] - public DatabaseProviderCollection Database { get; set; } - - [JsonProperty("certificates")] - public CertificateProviderCollection Certificate { get; set; } - - [JsonProperty("providerTypes")] - public ProviderTypesCollection Types { get; set; } - - public ProvidersConfiguration() - { - Database = new DatabaseProviderCollection(); - Certificate = new CertificateProviderCollection(); - Types = new ProviderTypesCollection(); - } - } -} \ No newline at end of file diff --git a/Server/KonfDB.Infrastructure/Configuration/Providers/Types/ProviderTypeConfiguration.cs b/Server/KonfDB.Infrastructure/Configuration/Providers/Types/ProviderTypeConfiguration.cs deleted file mode 100644 index 6474333..0000000 --- a/Server/KonfDB.Infrastructure/Configuration/Providers/Types/ProviderTypeConfiguration.cs +++ /dev/null @@ -1,39 +0,0 @@ -#region License and Product Information - -// -// This file 'ProviderTypeConfiguration.cs' is part of KonfDB application - -// a project perceived and developed by Punit Ganshani. -// -// KonfDB is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// KonfDB is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with KonfDB. If not, see . -// -// You can also view the documentation and progress of this project 'KonfDB' -// on the project website, or on -// - -#endregion - -using KonfDB.Infrastructure.Configuration.Interfaces; -using Newtonsoft.Json; - -namespace KonfDB.Infrastructure.Configuration.Providers.Types -{ - internal class ProviderTypeConfiguration : IProviderTypeConfiguration - { - [JsonProperty("type")] - public string Type { get; set; } - - [JsonProperty("assemblyPath")] - public string AssemblyPath { get; set; } - } -} \ No newline at end of file diff --git a/Server/KonfDB.Infrastructure/Configuration/Providers/Types/ProviderTypesCollection.cs b/Server/KonfDB.Infrastructure/Configuration/Providers/Types/ProviderTypesCollection.cs deleted file mode 100644 index 434abeb..0000000 --- a/Server/KonfDB.Infrastructure/Configuration/Providers/Types/ProviderTypesCollection.cs +++ /dev/null @@ -1,55 +0,0 @@ -#region License and Product Information - -// -// This file 'ProviderTypesCollection.cs' is part of KonfDB application - -// a project perceived and developed by Punit Ganshani. -// -// KonfDB is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// KonfDB is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with KonfDB. If not, see . -// -// You can also view the documentation and progress of this project 'KonfDB' -// on the project website, or on -// - -#endregion - -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; - -namespace KonfDB.Infrastructure.Configuration.Providers.Types -{ - [ConfigurationCollection(typeof (ProviderTypeConfiguration))] - internal class ProviderTypesCollection : List - { - public ProviderTypeConfiguration this[string name] - { - get { return this.FirstOrDefault(x => x.Type == name); } - } - - public bool IsValid(string type) - { - bool isValid = this.Any(x => x.Type == type); - - if (isValid) - { - var providerType = this[type]; - var typeOf = Type.GetType(providerType.AssemblyPath); - return typeOf != null; - } - - return false; - } - } -} \ No newline at end of file diff --git a/Server/KonfDB.Infrastructure/KonfDB.Infrastructure.csproj b/Server/KonfDB.Infrastructure/KonfDB.Infrastructure.csproj index 7be08c6..aaf1953 100644 --- a/Server/KonfDB.Infrastructure/KonfDB.Infrastructure.csproj +++ b/Server/KonfDB.Infrastructure/KonfDB.Infrastructure.csproj @@ -95,7 +95,6 @@ - @@ -121,7 +120,6 @@ - diff --git a/Server/KonfDB.Infrastructure/Shell/CurrentHostContext.cs b/Server/KonfDB.Infrastructure/Shell/CurrentHostContext.cs index 89c415d..bebca58 100644 --- a/Server/KonfDB.Infrastructure/Shell/CurrentHostContext.cs +++ b/Server/KonfDB.Infrastructure/Shell/CurrentHostContext.cs @@ -31,6 +31,8 @@ using KonfDB.Infrastructure.Configuration.Interfaces; using KonfDB.Infrastructure.Configuration.Runtime; using KonfDB.Infrastructure.Database.Providers; +using KonfDB.Infrastructure.Exceptions; +using KonfDB.Infrastructure.Extensions; using KonfDB.Infrastructure.Logging; using KonfDB.Infrastructure.Services; using KonfDB.Infrastructure.Utilities; @@ -122,32 +124,24 @@ public List GetUsers() private BaseProvider GetDatabaseProviderInstance(IHostConfig configuration) { - var defaultDatabaseConfig = configuration.Providers.Database.Default; - var providerTypesConfig = configuration.Providers.Types; + var defaultDatabaseConfig = configuration.Database.Default; + Type providerType = Type.GetType(defaultDatabaseConfig.ProviderType); + if (providerType == null) + throw new InvalidConfigurationException("Could not locate Database Provider :" + defaultDatabaseConfig.ProviderType); - if (!providerTypesConfig.IsValid(defaultDatabaseConfig.ProviderType)) - throw new ConfigurationErrorsException("Provider type not found: " + defaultDatabaseConfig.ProviderType + - " for database provider: " + - defaultDatabaseConfig.Key); - var providerConfiguration = providerTypesConfig[defaultDatabaseConfig.ProviderType]; + if (!providerType.ImplementsClass()) + throw new InvalidConfigurationException("Database Provider does not implement BaseProvider:" + defaultDatabaseConfig.ProviderType); - Type providerType = Type.GetType(providerConfiguration.AssemblyPath); - if (providerType != null) - { - var instance = Activator.CreateInstance(providerType, defaultDatabaseConfig); + var instance = Activator.CreateInstance(providerType, defaultDatabaseConfig); - var baseProvider = instance as BaseProvider; - if (baseProvider != null) - { - baseProvider.Init(); - return baseProvider; - } - throw new InvalidOperationException("Type : " + providerType + " does not inherit from BaseProvider"); + var baseProvider = instance as BaseProvider; + if (baseProvider != null) + { + baseProvider.Init(); + return baseProvider; } - - throw new InvalidOperationException(string.Format("Unknown Case: Could not get database provider for :{0}", - defaultDatabaseConfig.ProviderType)); + throw new InvalidOperationException("Type : " + providerType + " does not inherit from BaseProvider"); } } } \ No newline at end of file diff --git a/Server/KonfDBHost/KonfDBService.cs b/Server/KonfDBHost/KonfDBService.cs index 05ede1d..6ea831c 100644 --- a/Server/KonfDBHost/KonfDBService.cs +++ b/Server/KonfDBHost/KonfDBService.cs @@ -104,7 +104,7 @@ protected override void OnStart(string[] args) { var serviceSecurity = new ServiceSecurity { - CertificateConfiguration = CurrentHostContext.Default.Config.Providers.Certificate.Default, + CertificateConfiguration = CurrentHostContext.Default.Config.Certificate.Default, SecurityMode = CurrentHostContext.Default.Config.Runtime.ServiceSecurity }; diff --git a/Server/KonfDBHost/konfdb.json b/Server/KonfDBHost/konfdb.json index 6e4caf8..2b1bcfe 100644 --- a/Server/KonfDBHost/konfdb.json +++ b/Server/KonfDBHost/konfdb.json @@ -3,7 +3,7 @@ "audit": true, "log": { "provider": "KonfDB.Infrastructure.Logging.Logger, KonfDBC", - "params": "-logConfigPath:log4net.xml -ShowOnConsole:true" + "params": "-logConfigPath:log4net-config.xml -ShowOnConsole:true" }, "securityMode": "None", "server": [ @@ -34,51 +34,39 @@ "mode": "Absolute", "duration": 30 }, - "providers": { - "databaseProviders": { - "default": "localsql", - "database": [ - { - "key": "localsql", - "providerType": "MsSql", - "host": "localhost\\sqlexpress", - "port": 8080, - "instanceName": "konf", - "username": "sa", - "password": "SomePwdStrong*0889", - "location": "c:\\temp" - }, - { - "key": "azure", - "providerType": "AzureSql", - "host": "tcp:lbxcft14aq.database.windows.net", - "port": 1433, - "instanceName": "dbName", - "username": "dbName@lbxcft14aq", - "password": "dBPassword" - } - ] - }, - "certificates": { - "default": "testCert", - "certificate": [ - { - "key": "testCert", - "storeLocation": "LocalMachine", - "storeName": "My", - "findBy": "FindBySubjectName", - "value": "localhost" - } - ] - }, - "providerTypes": [ + "database": { + "default": "localsql", + "database": [ { - "type": "MsSql", - "assemblyPath": "KonfDB.Engine.Database.Providers.MsSql.MsSqlProvider, KonfDBE" + "key": "localsql", + "providerType": "KonfDB.Engine.Database.Providers.MsSql.MsSqlProvider, KonfDBE", + "host": "localhost\\sqlexpress", + "port": 8080, + "instanceName": "konf", + "username": "sa", + "password": "SomePwdStrong*0889", + "location": "c:\\temp" }, { - "type": "AzureSql", - "assemblyPath": "KonfDB.Engine.Database.Providers.AzureSql.AzureSqlProvider, KonfDBE" + "key": "azure", + "providerType": "KonfDB.Engine.Database.Providers.AzureSql.AzureSqlProvider, KonfDBE", + "host": "tcp:lbxcft14aq.database.windows.net", + "port": 1433, + "instanceName": "dbName", + "username": "dbName@lbxcft14aq", + "password": "dBPassword" + } + ] + }, + "certificates": { + "default": "testCert", + "certificate": [ + { + "key": "testCert", + "storeLocation": "LocalMachine", + "storeName": "My", + "findBy": "FindBySubjectName", + "value": "localhost" } ] } diff --git a/UnitTests/KonfDB.Tests/Configuration/ConfigurationTests.cs b/UnitTests/KonfDB.Tests/Configuration/ConfigurationTests.cs index a5b8ad4..6488ae1 100644 --- a/UnitTests/KonfDB.Tests/Configuration/ConfigurationTests.cs +++ b/UnitTests/KonfDB.Tests/Configuration/ConfigurationTests.cs @@ -67,8 +67,8 @@ public void TestJsonCreationForHost() config.Caching.DurationInSeconds = 30; config.Caching.Mode = CacheMode.Absolute; - config.Providers.Certificate.DefaultKey = "testCert"; - config.Providers.Certificate.Certificates.Add(new CertificateProviderConfiguration + config.Certificate.DefaultKey = "testCert"; + config.Certificate.Certificates.Add(new CertificateProviderConfiguration { CertificateKey = "testCert", StoreLocation = StoreLocation.LocalMachine, @@ -77,8 +77,8 @@ public void TestJsonCreationForHost() Value = "localhost" }); - config.Providers.Database.DefaultKey = "localsql"; - config.Providers.Database.Databases.Add(new DatabaseProviderConfiguration + config.Database.DefaultKey = "localsql"; + config.Database.Databases.Add(new DatabaseProviderConfiguration { Key = "localsql", Host = @"localhost\sqlexpress", @@ -89,7 +89,7 @@ public void TestJsonCreationForHost() Location = @"c:\temp", ProviderType = "MsSql" }); - config.Providers.Database.Databases.Add(new DatabaseProviderConfiguration + config.Database.Databases.Add(new DatabaseProviderConfiguration { Key = "azure", Host = @"tcp:lbxcft14aq.database.windows.net", @@ -100,17 +100,6 @@ public void TestJsonCreationForHost() ProviderType = "AzureSql" }); - config.Providers.Types.Add(new ProviderTypeConfiguration - { - AssemblyPath = "KonfDB.Engine.Database.Providers.MsSql.MsSqlProvider, KonfDBE", - Type = "MsSql" - }); - config.Providers.Types.Add(new ProviderTypeConfiguration - { - AssemblyPath = "KonfDB.Engine.Database.Providers.AzureSql.AzureSqlProvider, KonfDBE", - Type = "AzureSql" - }); - var configJson = config.ToJson(); var readBack = configJson.FromJsonToObject(); Assert.IsNotNull(readBack);