/// <summary>
        /// Override default provider creation by using custom options
        /// </summary>
        /// <param name="sectionName"></param>
        /// <param name="configData"></param>
        /// <returns></returns>
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            
            var provider = new ConfigurationFileConfigurationProvider<ApplicationConfiguration>()
            {
                // use the machine key to seed encoding key string or provide any other string
                EncryptionKey = MachineKey.Encode(new byte[] { 3, 233, 8, 11, 32, 44 }, 
                                                    MachineKeyProtection.Encryption),                    
                PropertiesToEncrypt = "MailServerPassword,ConnectionString",
                // Custom section - if not specified goes to AppSettings
                ConfigurationSection = "ApplicationConfiguration"
            };

            return provider;

            // Example of Sql configuration
            //var provider = new SqlServerConfigurationProvider<ApplicationConfiguration>()
            //{
            //    FieldsToEncrypt = "MailServerPassword,ConnectionString",
            //    EncryptKey = "secret",
            //    ConnectionString = "DevSampleConnectionString",
            //    Tablename = "Configuration",
            //    Key = 1
            //};
            // Example of external XML configuration - advantage: Supports complex object hierarchies
            //var provider = new XmlFileConfigurationProvider<ApplicationConfiguration>()
            //{
            //    FieldsToEncrypt = "MailServerPassword,ConnectionString",
            //    EncryptKey = "secret",
            //    XmlConfigurationFile = HttpContext.Current.Server.MapPath("~/Configuration.xml")
            //};
        }
예제 #2
0
        /// <summary>
        /// Override default provider creation by using custom options
        /// </summary>
        /// <param name="sectionName"></param>
        /// <param name="configData"></param>
        /// <returns></returns>
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            var provider = new ConfigurationFileConfigurationProvider <ApplicationConfiguration>()
            {
                // use the machine key to seed encoding key string or provide any other string
                EncryptionKey = MachineKey.Encode(new byte[] { 3, 233, 8, 11, 32, 44 },
                                                  MachineKeyProtection.Encryption),
                PropertiesToEncrypt = "MailServerPassword,ConnectionString",
                // Custom section - if not specified goes to AppSettings
                ConfigurationSection = "ApplicationConfiguration"
            };

            return(provider);

            // Example of Sql configuration
            //var provider = new SqlServerConfigurationProvider<ApplicationConfiguration>()
            //{
            //    FieldsToEncrypt = "MailServerPassword,ConnectionString",
            //    EncryptKey = "secret",
            //    ConnectionString = "DevSampleConnectionString",
            //    Tablename = "Configuration",
            //    Key = 1
            //};
            // Example of external XML configuration - advantage: Supports complex object hierarchies
            //var provider = new XmlFileConfigurationProvider<ApplicationConfiguration>()
            //{
            //    FieldsToEncrypt = "MailServerPassword,ConnectionString",
            //    EncryptKey = "secret",
            //    XmlConfigurationFile = HttpContext.Current.Server.MapPath("~/Configuration.xml")
            //};
        }
        /// <summary>
        /// Override this method to create the custom default provider. Here we allow for different
        /// configuration providers so we don't have to rely on .NET configuration classed (for vNext)
        /// </summary>
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            if (string.IsNullOrEmpty(sectionName))
            {
                sectionName = "DbResourceConfiguration";
            }

            IConfigurationProvider provider;

            if (ConfigurationMode == ConfigurationModes.JsonFile)
            {
                provider = new JsonFileConfigurationProvider <DbResourceConfiguration>()
                {
                    JsonConfigurationFile =
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbResourceConfiguration.json")
                };
            }
            else if (ConfigurationMode == ConfigurationModes.XmlFile)
            {
                provider = new XmlFileConfigurationProvider <DbResourceConfiguration>()
                {
                    XmlConfigurationFile =
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbResourceConfiguration.xml")
                };
            }
            else
            {
                provider = new ConfigurationFileConfigurationProvider <DbResourceConfiguration>()
                {
                    ConfigurationSection = sectionName
                };
            }

            return(provider);
        }
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            var provider = new ConfigurationFileConfigurationProvider <ApplicationConfiguration>()
            {
                ConfigurationSection = "appSettings",
            };

            return(provider);
        }
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            var provider = new ConfigurationFileConfigurationProvider <AppSettings>()
            {
                EncryptionKey = "appSettings"
            };

            return(provider);
        }
예제 #6
0
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            Provider = new ConfigurationFileConfigurationProvider <AppSettingsConfigFileConfiguration>()
            {
                ConfigurationSection = null  // Forces to AppSettings
            };

            return(Provider);
        }
예제 #7
0
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            ConfigurationFileConfigurationProvider <Userconfig> provider = new ConfigurationFileConfigurationProvider <Userconfig>()
            {
                ConfigurationFile    = System.AppDomain.CurrentDomain.BaseDirectory + @"\arma3.config",
                ConfigurationSection = sectionName,
            };

            return(provider);
        }
예제 #8
0
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            var provider = new ConfigurationFileConfigurationProvider <ApplicationConfiguration>()
            {
                ConfigurationSection = "CodePaste",
                //ConfigurationFile = "CodePaste.config"
            };

            return(provider);
        }
예제 #9
0
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            ConfigurationFileConfigurationProvider<Userconfig> provider = new ConfigurationFileConfigurationProvider<Userconfig>()
            {
                ConfigurationFile = System.AppDomain.CurrentDomain.BaseDirectory + @"\arma3.config",
                ConfigurationSection = sectionName,
            };

            return provider;
        }
예제 #10
0
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            var provider = new ConfigurationFileConfigurationProvider<ApplicationConfiguration>()
            {
                ConfigurationSection = "CodePaste",
                //ConfigurationFile = "CodePaste.config"
            };

            return provider;            
        }
예제 #11
0
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            ConfigurationFileConfigurationProvider<Userconfigs> provider = new ConfigurationFileConfigurationProvider<Userconfigs>()
            {
                ConfigurationFile = System.AppDomain.CurrentDomain.BaseDirectory + @"\modlist.config",
                ConfigurationSection = sectionName,
                EncryptionKey = "6251a0f048e9a93e3c70eb7fd6da641d",
                PropertiesToEncrypt = "urlTo,user,password",
            };

            return provider;
        }
예제 #12
0
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            ConfigurationFileConfigurationProvider <Userconfigs> provider = new ConfigurationFileConfigurationProvider <Userconfigs>()
            {
                ConfigurationFile    = System.AppDomain.CurrentDomain.BaseDirectory + @"\modlist.config",
                ConfigurationSection = sectionName,
                EncryptionKey        = "6251a0f048e9a93e3c70eb7fd6da641d",
                PropertiesToEncrypt  = "urlTo,user,password",
            };

            return(provider);
        }
        /// <summary>
        /// Override to provide a custom default provider (created when Initialize() is
        /// called with no parameters).
        /// </summary>
        /// <param name="sectionName"></param>
        /// <param name="configData"></param>
        /// <returns></returns>
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            var provider = new ConfigurationFileConfigurationProvider<CustomConfigFileConfiguration>()
            {
                //ConfigurationFile = "CustomConfiguration.config",
                ConfigurationSection = sectionName,
                EncryptionKey = "ultra-seekrit",  // use a generated value here
                PropertiesToEncrypt = "Password,AppConnectionString"
            };

            return provider;
        }
        /// <summary>
        /// Override to provide a custom default provider (created when Initialize() is
        /// called with no parameters).
        /// </summary>
        /// <param name="sectionName"></param>
        /// <param name="configData"></param>
        /// <returns></returns>
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            var provider = new ConfigurationFileConfigurationProvider <CustomConfigFileConfiguration>()
            {
                //ConfigurationFile = "CustomConfiguration.config",
                ConfigurationSection = sectionName,
                EncryptionKey        = "ultra-seekrit", // use a generated value here
                PropertiesToEncrypt  = "Password,AppConnectionString,License.LicenseKey"
            };

            return(provider);
        }
예제 #15
0
        protected override void OnInitialize(IConfigurationProvider provider, string sectionName, object configData)
        {
            if (provider == null)
            {
                provider = new ConfigurationFileConfigurationProvider <LogManagerConfiguration>()
                {
                    ConfigurationSection = "LogManager"
                };
            }

            Provider = provider;
            Read();
        }
 protected override void OnInitialize(IConfigurationProvider provider, string sectionName, object configData)
 {
     if (provider == null)
     {
         provider = new ConfigurationFileConfigurationProvider<LogManagerConfiguration>()
         {
             ConfigurationSection = "LogManager"
         };
     }
     
     Provider = provider;            
     Read();
 }
예제 #17
0
        protected override void OnInitialize(IConfigurationProvider provider, string sectionName, object configData)
        {
            if (provider == null)
            {
#if NETFULL
                provider = new ConfigurationFileConfigurationProvider <LogManagerConfiguration>()
                {
                    ConfigurationSection = "LogManager"
                };
#else
                provider = new JsonFileConfigurationProvider <LogManagerConfiguration>()
                {
                    JsonConfigurationFile = "LogConfiguration.json"
                };
#endif
            }

            Provider = provider;
            Read();
        }
        public void DefaultConstructorWithCustomProviderTest()
        {
            var config = new AutoConfigFileConfiguration();

            // Create a customized provider to set provider options
            var provider = new ConfigurationFileConfigurationProvider<AutoConfigFileConfiguration>()
            {
                ConfigurationSection = "CustomConfiguration",
                EncryptionKey = "seekrit123",
                PropertiesToEncrypt = "MailServer,MailServerPassword"                
            };

            config.Initialize(provider);  
            
            // Config File and custom section should have been created in config file
            string text = File.ReadAllText(TestHelpers.GetTestConfigFilePath());

            Assert.IsFalse(string.IsNullOrEmpty(text));
            Assert.IsTrue(text.Contains("<CustomConfiguration>"));

            // MailServer/MailServerPassword value should be encrypted
            Console.WriteLine(text);
        }
        public void DefaultConstructorWithCustomProviderTest()
        {
            var config = new AutoConfigFileConfiguration();

            // Create a customized provider to set provider options
            var provider = new ConfigurationFileConfigurationProvider <AutoConfigFileConfiguration>()
            {
                ConfigurationSection = "CustomConfiguration",
                EncryptionKey        = "seekrit123",
                PropertiesToEncrypt  = "MailServer,MailServerPassword"
            };

            config.Initialize(provider);

            // Config File and custom section should have been created in config file
            string text = File.ReadAllText(TestHelpers.GetTestConfigFilePath());

            Assert.IsFalse(string.IsNullOrEmpty(text));
            Assert.IsTrue(text.Contains("<CustomConfiguration>"));

            // MailServer/MailServerPassword value should be encrypted
            Console.WriteLine(text);
        }
        public void DefaultConstructorWithAppSettingsProviderTest()
        {
            var config = new AutoConfigFileConfiguration();

            // Create a customized provider to set provider options
            var provider = new ConfigurationFileConfigurationProvider <AutoConfigFileConfiguration>()
            {
                ConfigurationSection = null, // forces to AppSettings
                EncryptionKey        = "seekrit123",
                PropertiesToEncrypt  = "MailServer,MailServerPassword"
            };

            config.Initialize(provider);

            // Config File and custom section should have been created in config file
            string text = File.ReadAllText(TestHelpers.GetTestConfigFilePath());

            Assert.IsFalse(string.IsNullOrEmpty(text));
            Assert.IsTrue(text.Contains("<appSettings>"));

            // MailServer/MailServerPassword value should be encrypted
            Console.WriteLine(text);

            config.ApplicationName = "Updated Configuration";
            config.Write();

            config = null;
            config = new AutoConfigFileConfiguration();
            config.Initialize(provider);

            config.Initialize(); // should reload, reread

            Console.WriteLine("Application Name: " + config.ApplicationName);

            Assert.IsTrue(config.ApplicationName == "Updated Configuration");
        }
        private void LoadAppConfiguration(SamplesViewModel model)
        {            
           
            // Default Web.Config read with Constructor
            // at first access
            if (model.ConfigTypeSelection == "Default Web.Config")
            {
                // Simply assign the default config object - it gets loaded via 
                // the default constructor defined in AppConfig.cs
                this.AppConfig = App.Configuration;
                
                // force to re-read in case we updated previously
                AppConfig.Read();
            }
            

            // Explicit object creation for the remaining objects, 
            // but you can use the same static constructor approach
            // as with the above

            // Separate Web.Config Section
            else if (model.ConfigTypeSelection == "Different Web.Config Section")
            {
                var provider = new ConfigurationFileConfigurationProvider<ApplicationConfiguration>()
                {
                     ConfigurationSection = "WebStoreConfiguration",
                     PropertiesToEncrypt = "ConnectionString,MailServerPassword", 
                     EncryptionKey = STR_SUPERSECRET
                };
                AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);
                //this.AppConfig.Read();
            }

                // Separate Web.AppConfig Section
            else if (model.ConfigTypeSelection == "Different .Config File")
            {
                
                var provider = new ConfigurationFileConfigurationProvider<ApplicationConfiguration>()
                {
                    ConfigurationFile= Server.MapPath("~/WebStore.config"),
                    ConfigurationSection = "WebStoreConfiguration",
                    PropertiesToEncrypt = "ConnectionString,MailServerPassword",
                    EncryptionKey = STR_SUPERSECRET
                };

                AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);
                //this.AppConfig.Read();
            }

            else if (model.ConfigTypeSelection == "Simple Xml File")
            {
                var provider = new XmlFileConfigurationProvider<ApplicationConfiguration>()
                {
                    XmlConfigurationFile = Server.MapPath("WebStoreConfig.xml"),
                    PropertiesToEncrypt = "ConnectionString,MailServerPassword",
                    EncryptionKey = STR_SUPERSECRET
                };

                this.AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);
                //this.AppConfig.Read();
            }
            else if (model.ConfigTypeSelection == "String")
            {

                string XmlString = HttpContext.Application["XmlString"] as string;
                AppConfig = new ApplicationConfiguration();

                if (XmlString != null)
                {
                    // You can always read from an XML Serialization string w/o
                    // any provider setup
                    AppConfig.Read(XmlString);
                }
            }

            // Not implemented since you will need a database
            // this example uses the connection string configured in the Web.Config
            else if (model.ConfigTypeSelection == "Database")
            {
                var provider = new SqlServerConfigurationProvider<ApplicationConfiguration>()
                {
                    ConnectionString = "DevSampleConnectionString",
                    Tablename = "ConfigData",
                    Key = 1,
                    PropertiesToEncrypt = "ConnectionString,MailServerPassword",
                    EncryptionKey = STR_SUPERSECRET
                };

                AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);

                if (!this.AppConfig.Read())
                    model.ShowError(
                      "Unable to connect to the Database.<hr>" +
                      "This database samle uses the connection string in the configuration settings " +
                      "with a table named 'ConfigData' and a field named 'ConfigData' to hold the " +
                      "configuration settings. If you have a valid connection string you can click " +
                      "on Save Settings to force the table and a single record to be created.<br><br>" +
                      "Note: The table name is parameterized (and you can change it in the default.aspx.cs page), but the field name always defaults to ConfigData.<hr/>" +
                      AppConfig.ErrorMessage);
            }
        }
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            var provider = new ConfigurationFileConfigurationProvider <LicenseConfiguration>();

            return(provider);
        }
        /// <summary>
        /// Override this method to create the custom default provider. Here we allow for different 
        /// configuration providers so we don't have to rely on .NET configuration classed (for vNext)
        /// </summary>
        protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
        {
            if (string.IsNullOrEmpty(sectionName))
                sectionName = "DbResourceConfiguration";

            IConfigurationProvider provider;

            if (ConfigurationMode == ConfigurationModes.JsonFile)
            {
                provider = new JsonFileConfigurationProvider<DbResourceConfiguration>()
                {
                    JsonConfigurationFile =
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbResourceConfiguration.json")
                };
            }
            else if (ConfigurationMode == ConfigurationModes.XmlFile)
            {
                provider = new XmlFileConfigurationProvider<DbResourceConfiguration>()
                {
                    XmlConfigurationFile =
                        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbResourceConfiguration.xml")
                };
            }
            else
            {
                provider = new ConfigurationFileConfigurationProvider<DbResourceConfiguration>()
                {
                    ConfigurationSection = sectionName
                };
            }

            return provider;
        }
예제 #24
0
파일: AppSettings.cs 프로젝트: kfazi/AgarIo
 protected override IConfigurationProvider OnCreateDefaultProvider(string sectionName, object configData)
 {
     var provider = new ConfigurationFileConfigurationProvider<AppSettings>();
     return provider;
 }
예제 #25
0
        private void LoadAppConfiguration(SamplesViewModel model)
        {
            // Default Web.Config read with Constructor
            // at first access
            if (model.ConfigTypeSelection == "Default Web.Config")
            {
                // Simply assign the default config object - it gets loaded via
                // the default constructor defined in AppConfig.cs
                this.AppConfig = App.Configuration;

                // force to re-read in case we updated previously
                AppConfig.Read();
            }


            // Explicit object creation for the remaining objects,
            // but you can use the same static constructor approach
            // as with the above

            // Separate Web.Config Section
            else if (model.ConfigTypeSelection == "Different Web.Config Section")
            {
                var provider = new ConfigurationFileConfigurationProvider <ApplicationConfiguration>()
                {
                    ConfigurationSection = "WebStoreConfiguration",
                    PropertiesToEncrypt  = "ConnectionString,MailServerPassword",
                    EncryptionKey        = STR_SUPERSECRET
                };
                AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);
                //this.AppConfig.Read();
            }

            // Separate Web.AppConfig Section
            else if (model.ConfigTypeSelection == "Different .Config File")
            {
                var provider = new ConfigurationFileConfigurationProvider <ApplicationConfiguration>()
                {
                    ConfigurationFile    = Server.MapPath("~/WebStore.config"),
                    ConfigurationSection = "WebStoreConfiguration",
                    PropertiesToEncrypt  = "ConnectionString,MailServerPassword",
                    EncryptionKey        = STR_SUPERSECRET
                };

                AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);
                //this.AppConfig.Read();
            }

            else if (model.ConfigTypeSelection == "Simple Xml File")
            {
                var provider = new XmlFileConfigurationProvider <ApplicationConfiguration>()
                {
                    XmlConfigurationFile = Server.MapPath("WebStoreConfig.xml"),
                    PropertiesToEncrypt  = "ConnectionString,MailServerPassword",
                    EncryptionKey        = STR_SUPERSECRET
                };

                this.AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);
                //this.AppConfig.Read();
            }
            else if (model.ConfigTypeSelection == "String")
            {
                string XmlString = HttpContext.Application["XmlString"] as string;
                AppConfig = new ApplicationConfiguration();

                if (XmlString != null)
                {
                    // You can always read from an XML Serialization string w/o
                    // any provider setup
                    AppConfig.Read(XmlString);
                }
            }

            // Not implemented since you will need a database
            // this example uses the connection string configured in the Web.Config
            else if (model.ConfigTypeSelection == "Database")
            {
                var provider = new SqlServerConfigurationProvider <ApplicationConfiguration>()
                {
                    ConnectionString = "DevSampleConnectionString",
                    Tablename        = "ConfigData",
                    Key = 1,
                    PropertiesToEncrypt = "ConnectionString,MailServerPassword",
                    EncryptionKey       = STR_SUPERSECRET
                };

                AppConfig = new ApplicationConfiguration();
                AppConfig.Initialize(provider);

                if (!this.AppConfig.Read())
                {
                    model.ShowError(
                        "Unable to connect to the Database.<hr>" +
                        "This database samle uses the connection string in the configuration settings " +
                        "with a table named 'ConfigData' and a field named 'ConfigData' to hold the " +
                        "configuration settings. If you have a valid connection string you can click " +
                        "on Save Settings to force the table and a single record to be created.<br><br>" +
                        "Note: The table name is parameterized (and you can change it in the default.aspx.cs page), but the field name always defaults to ConfigData.<hr/>" +
                        AppConfig.ErrorMessage);
                }
            }
        }
        public void DefaultConstructorWithAppSettingsProviderTest()
        {
            var config = new AutoConfigFileConfiguration();

            // Create a customized provider to set provider options
            var provider = new ConfigurationFileConfigurationProvider<AutoConfigFileConfiguration>()
            {
                ConfigurationSection = null, // forces to AppSettings
                EncryptionKey = "seekrit123",
                PropertiesToEncrypt = "MailServer,MailServerPassword"
            };

            config.Initialize(provider);

            // Config File and custom section should have been created in config file
            string text = File.ReadAllText(TestHelpers.GetTestConfigFilePath());

            Assert.IsFalse(string.IsNullOrEmpty(text));
            Assert.IsTrue(text.Contains("<appSettings>"));

            // MailServer/MailServerPassword value should be encrypted
            Console.WriteLine(text);

            config.ApplicationName = "Updated Configuration";
            config.Write();

            config = null;
            config = new AutoConfigFileConfiguration();
            config.Initialize(provider);

            config.Initialize(); // should reload, reread

            Console.WriteLine("Application Name: " + config.ApplicationName);

            Assert.IsTrue(config.ApplicationName == "Updated Configuration");
        }