static void Main(string[] args) { try { //Configure Data Sources FileConfigurationSource configSource = new FileConfigurationSource(@"..\..\..\DataSources.config"); DatabaseProviderFactory providerFactory = new DatabaseProviderFactory(configSource); GetHEREDomainLists service = new GetHEREDomainLists(); service.DataSources[DataSourceParameterType.SourceDatabaseDataSource.ToString()] = providerFactory.Create("NODE_FLOW_KDHE"); service.DataSources[DataSourceParameterType.TargetDatabaseDataSource.ToString()] = providerFactory.Create("NODE_FLOW_KDHE"); service.RunTimeArguments[HERERunTimeArgs.EndpointUri.ToString()] = "https://deqnode.ne.gov/service/Service_v11.asmx"; service.RunTimeArguments[HERERunTimeArgs.IsFacilitySourceIndicator.ToString()] = "True"; service.RunTimeArguments[HERERunTimeArgs.SourceSystemName.ToString()] = "KS-FP"; service.CurrentTransaction = Guid.NewGuid().ToString(); service.ExecutingBy = "*****@*****.**"; Console.WriteLine("GetHEREDomainLists: " + service.Execute(new string[] { "365" }, @"..\..\..\temp")); } catch (Exception ex) { Console.Write(ex); } finally { Console.WriteLine("Done"); Console.ReadLine(); } }
public List <Error> ValidateRuleSet(object obj, string ruleSet) { string validacionConfig = ConfigurationManager.AppSettings["validacionConfig"].ToString(); IConfigurationSource source = new FileConfigurationSource(validacionConfig); Validator oValidator = ValidationFactory.CreateValidatorFromConfiguration(typeof(T), ruleSet, source); ValidationResults oValidationResults = oValidator.Validate(obj); List <Error> listError = new List <Error>(); if (!oValidationResults.IsValid) { foreach (ValidationResult result in oValidationResults) { Error oError = new Error(); oError.Codigo = result.Key; oError.Clase = this.GetType().Name; oError.Descripcion = result.Message; oError.DescripcionConcatenada += result.Message + " "; listError.Add(oError); } //"Incosistencia en Objeto Notificacion - Error/es : "; } return(listError); }
static void Main(string[] args) { try { //Configure Data Sources FileConfigurationSource configSource = new FileConfigurationSource(@"..\..\..\DataSources.config"); DatabaseProviderFactory providerFactory = new DatabaseProviderFactory(configSource); GetHEREManifest service = new GetHEREManifest(); service.DataSources[DataSourceParameterType.SourceDatabaseDataSource.ToString()] = providerFactory.Create("HEREFLOW"); service.CurrentTransaction = Guid.NewGuid().ToString(); service.ExecutingBy = "*****@*****.**"; File.WriteAllBytes(@"..\..\..\temp\GetHEREManifest.xml", service.Execute(new string[] { "1900-01-01" }, 0, Int64.MaxValue)); } catch (Exception ex) { Console.Write(ex); } finally { Console.WriteLine("Done"); Console.ReadLine(); } }
public void CanUseRelativePathToBaseDirectory() { var currentDirectory = Environment.CurrentDirectory; Environment.CurrentDirectory = Path.GetTempPath(); string fullConfigurationFilepath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; string otherConfigurationFilepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); File.Copy(fullConfigurationFilepath, otherConfigurationFilepath); try { using (FileConfigurationSource otherConfiguration = new FileConfigurationSource("Other.config", false)) { DummySection dummySection = otherConfiguration.GetSection(localSection) as DummySection; Assert.IsNotNull(dummySection); } } finally { Environment.CurrentDirectory = currentDirectory; if (File.Exists(otherConfigurationFilepath)) { File.Delete(otherConfigurationFilepath); } } }
public void CanDeserializeSerializedConfiguration() { string sourceName1 = "source1"; string sourceName2 = "source2"; string sourceFile1 = "file 1"; ConfigurationSourceSection settings = new ConfigurationSourceSection(); FileConfigurationSource.ResetImplementation(sourceFile1, false); ConfigurationSourceElement data1 = new FileConfigurationSourceElement(sourceName1, sourceFile1); ConfigurationSourceElement data2 = new SystemConfigurationSourceElement(sourceName2); settings.Sources.Add(data1); settings.Sources.Add(data2); settings.SelectedSource = sourceName1; IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>(); sections[ConfigurationSourceSection.SectionName] = settings; IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections); ConfigurationSourceSection roSettigs = (ConfigurationSourceSection)configurationSource.GetSection(ConfigurationSourceSection.SectionName); Assert.IsNotNull(roSettigs); Assert.AreEqual(2, roSettigs.Sources.Count); Assert.AreEqual(sourceName1, roSettigs.SelectedSource); Assert.IsNotNull(roSettigs.Sources.Get(sourceName1)); Assert.AreSame(typeof(FileConfigurationSourceElement), roSettigs.Sources.Get(sourceName1).GetType()); Assert.AreEqual(sourceFile1, ((FileConfigurationSourceElement)roSettigs.Sources.Get(sourceName1)).FilePath); Assert.IsNotNull(roSettigs.Sources.Get(sourceName2)); Assert.AreSame(typeof(SystemConfigurationSourceElement), roSettigs.Sources.Get(sourceName2).GetType()); }
public void CreateAuthorizationCallHandlerFromConfiguration() { PolicyInjectionSettings settings = new PolicyInjectionSettings(); PolicyData policyData = new PolicyData("policy"); AuthorizationCallHandlerData data = new AuthorizationCallHandlerData("foo", 2); policyData.MatchingRules.Add(new CustomMatchingRuleData("matchesEverything", typeof(AlwaysMatchingRule))); policyData.Handlers.Add(data); settings.Policies.Add(policyData); using (var configSource = new FileConfigurationSource("Authorization.config", false)) { IUnityContainer container = new UnityContainer().AddNewExtension <Interception>(); settings.ConfigureContainer(container, configSource); new UnityContainerConfigurator(container) .RegisterAll( configSource, (ITypeRegistrationsProvider)configSource.GetSection(SecuritySettings.SectionName)); InjectionFriendlyRuleDrivenPolicy policy = container.Resolve <InjectionFriendlyRuleDrivenPolicy>("policy"); ICallHandler handler = (policy.GetHandlersFor(new MethodImplementationInfo(null, (MethodInfo)MethodBase.GetCurrentMethod()), container)).ElementAt(0); Assert.IsNotNull(handler); Assert.AreEqual(handler.Order, data.Order); //Assert.AreSame(authorizationProvider, ((AuthorizationCallHandler)handler).AutorizationProvider); // TODO this test only checked for provider name, so it didn't fail even though the configuration source supplied didn't have the settings required to build it } }
public void NonExistentSectionReturnsNullThroughFileConfigurationSource() { string fullConfigurationFilepath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; string otherConfigurationFilepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); File.Copy(fullConfigurationFilepath, otherConfigurationFilepath); try { using (FileConfigurationSource otherConfiguration = new FileConfigurationSource(otherConfigurationFilepath, false)) { object wrongSection = otherConfiguration.GetSection("wrong section"); Assert.IsNull(wrongSection); } } finally { if (File.Exists(otherConfigurationFilepath)) { File.Delete(otherConfigurationFilepath); } } }
public void CanUseRelativePathToBaseDirectory() { var currentDirectory = Environment.CurrentDirectory; Environment.CurrentDirectory = Path.GetTempPath(); string fullConfigurationFilepath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; string otherConfigurationFilepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); File.Copy(fullConfigurationFilepath, otherConfigurationFilepath); try { using (FileConfigurationSource otherConfiguration = new FileConfigurationSource("Other.config", false)) { DummySection dummySection = otherConfiguration.GetSection(localSection) as DummySection; Assert.IsNotNull(dummySection); } } finally { Environment.CurrentDirectory = currentDirectory; if (File.Exists(otherConfigurationFilepath)) { File.Delete(otherConfigurationFilepath); } } }
/// <summary> /// /// </summary> /// <param name="configurationFile"></param> public void Load(string configurationFile) { loading = true; try { FileConfigurationSource.ResetImplementation(configurationFile, false); IConfigurationUIHierarchyService hierarchyService = (IConfigurationUIHierarchyService)serviceProvider.GetService(typeof(IConfigurationUIHierarchyService)); foreach (ConfigurationUIHierarchy hierarchy in hierarchyService.GetAllHierarchies()) { hierarchyService.RemoveHierarchy(hierarchy); } ConfigurationApplicationFile data = new ConfigurationApplicationFile(Path.GetDirectoryName(configurationFile), configurationFile); ConfigurationUIHierarchy newhierarchy = new ConfigurationUIHierarchy(new ConfigurationApplicationNode(data), serviceProvider); hierarchyService.AddHierarchy(newhierarchy); hierarchyService.SelectedHierarchy = newhierarchy; configurationEditor.SetMainHierarchy(newhierarchy); newhierarchy.Open(); configurationEditor.ClearDirtyState(); } finally { loading = false; } }
public MimeTypeDatabaseConfigurationProvider( FileConfigurationSource source, string[] basePath) : base(source) { _basePath = basePath; }
private void CopyEpiserverFindConfigurationSection() { FileConfigurationSource instance = (FileConfigurationSource)ConfigurationSource.Instance; var episerverFindSection = (EPiServer.Find.Configuration)instance.ConfigurationInstance.GetSection("episerver.find"); var currentAppConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (currentAppConfig.AppSettings.Settings["episerver:FindServiceUrl"] != null) { currentAppConfig.AppSettings.Settings.Remove("episerver:FindServiceUrl"); } if (currentAppConfig.AppSettings.Settings["episerver:FindDefaultIndex"] != null) { currentAppConfig.AppSettings.Settings.Remove("episerver:FindDefaultIndex"); } currentAppConfig.AppSettings.Settings.Add("episerver:FindServiceUrl", episerverFindSection.ServiceUrl); currentAppConfig.AppSettings.Settings.Add("episerver:FindDefaultIndex", episerverFindSection.DefaultIndex); currentAppConfig.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("appSettings"); }
public void CanMonitorFileWhichDoesNotExist() { using (var fileSource = new FileConfigurationSource(this.fullSampleFilename)) { fileSource.SourceUpdated += () => Assert.Fail("Should not be called."); } }
static void Main(string[] args) { var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var section = config.GetSection(ConfigurationSourceSection.SectionName) as ConfigurationSourceSection; var dbConfigSourceElement = section.Sources.Get("DatabaseBlockSettings") as FileConfigurationSourceElement; var dbConfigSource = new FileConfigurationSource(dbConfigSourceElement.FilePath); var dbFactory = new DatabaseProviderFactory(dbConfigSource); DatabaseFactory.SetDatabaseProviderFactory(dbFactory); var logConfigSourceElement = section.Sources.Get("LoggingBlockSettings") as FileConfigurationSourceElement; var logConfigSource = new FileConfigurationSource(logConfigSourceElement.FilePath); var logFactory = new LogWriterFactory(logConfigSource); var logWriter = logFactory.Create(); Logger.SetLogWriter(logWriter); logWriter.Write("123333"); var exceptionConfigSourceElement = section.Sources.Get("ExceptionHandlingBlockSettings") as FileConfigurationSourceElement; var exceptionConfigSource = new FileConfigurationSource(exceptionConfigSourceElement.FilePath); var exceptionFactory = new ExceptionPolicyFactory(exceptionConfigSource); var exceptionManager = exceptionFactory.CreateManager(); ExceptionPolicy.SetExceptionManager(exceptionManager); ProcessException(exceptionManager, () => int.Parse("A")); Console.WriteLine("主函数执行完成,按任意键退出……"); Console.ReadKey(); }
public void CanMonitorFileWhichDoesNotExist() { using (var fileSource = new FileConfigurationSource(this.fullSampleFilename)) { fileSource.SourceUpdated += () => Assert.Fail("Should not be called."); } }
public void TestInitialize() { IConfigurationSource authorizationConfiguration = new FileConfigurationSource("Authorization.config"); RuleDrivenPolicy allowFredPolicy = new RuleDrivenPolicy("allowFred"); allowFredPolicy.Handlers.Add(new AuthorizationCallHandler("RuleProvider", "OnlyFredHasAccess", authorizationConfiguration)); allowFredPolicy.RuleSet.Add(new AlwaysMatchingRule()); AllowFredPolicySet = new PolicySet(allowFredPolicy); RuleDrivenPolicy allowJackPolicy = new RuleDrivenPolicy("allowJack"); allowJackPolicy.Handlers.Add(new AuthorizationCallHandler(string.Empty, "OnlyJackHasAccess", authorizationConfiguration)); allowJackPolicy.RuleSet.Add(new AlwaysMatchingRule()); AllowJackPolicySet = new PolicySet(allowJackPolicy); RuleDrivenPolicy tokenBasedPolicy = new RuleDrivenPolicy("tokens"); tokenBasedPolicy.RuleSet.Add(new AlwaysMatchingRule()); tokenBasedPolicy.Handlers.Add( new AuthorizationCallHandler(string.Empty, "{type}-{method}", authorizationConfiguration)); AllowBasedOnTokensPolicySet = new PolicySet(tokenBasedPolicy); }
public void AddIsReflectedInNextRequestWithoutRefresh() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); try { File.Copy(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath, otherConfigurationFile); using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, false)) { DummySection otherSection = otherSource.GetSection(localSection) as DummySection; // update twice, just to make sure DummySection newSection = new DummySection(); newSection.Value = 13; otherSource.Add(localSection, newSection); newSection = new DummySection(); newSection.Value = 12; otherSource.Add(localSection, newSection); otherSection = otherSource.GetSection(localSection) as DummySection; Assert.IsNotNull(otherSection); Assert.AreEqual(12, otherSection.Value); } } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
public void RemoveIsReflectedInNextRequestWithoutRefresh() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); try { File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, false)) { DummySection otherSection = otherSource.GetSection(localSection) as DummySection; DummySection newSection = new DummySection(); newSection.Value = 13; otherSource.Add(localSection, newSection); otherSource.Remove(localSection); otherSection = otherSource.GetSection(localSection) as DummySection; Assert.IsNull(otherSection); } } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
public void AddIsReflectedInNextRequestWithoutRefresh() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); FileConfigurationParameter parameter = new FileConfigurationParameter(otherConfigurationFile); FileConfigurationSource.ResetImplementation(otherConfigurationFile, false); try { File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile); DummySection otherSection = otherSource.GetSection(localSection) as DummySection; // update twice, just to make sure DummySection newSection = new DummySection(); newSection.Value = 13; otherSource.Add(parameter, localSection, newSection); newSection = new DummySection(); newSection.Value = 12; otherSource.Add(parameter, localSection, newSection); otherSection = otherSource.GetSection(localSection) as DummySection; Assert.IsNotNull(otherSection); Assert.AreEqual(12, otherSection.Value); } finally { FileConfigurationSource.ResetImplementation(otherConfigurationFile, true); if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
public void SectionsCanBeAccessedThroughFileConfigurationSource() { string fullConfigurationFilepath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; string otherConfigurationFilepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); File.Copy(fullConfigurationFilepath, otherConfigurationFilepath); try { using (FileConfigurationSource otherConfiguration = new FileConfigurationSource(otherConfigurationFilepath, false)) { DummySection dummySection = otherConfiguration.GetSection(localSection) as DummySection; Assert.IsNotNull(dummySection); } } finally { if (File.Exists(otherConfigurationFilepath)) { File.Delete(otherConfigurationFilepath); } } }
public void FileConfigurationAndSystemConfigurationDoNotShareImplementation() { BaseFileConfigurationSourceImplementation configSourceImpl1 = FileConfigurationSource.GetImplementation(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); BaseFileConfigurationSourceImplementation configSourceImpl2 = SystemConfigurationSource.Implementation; Assert.IsFalse(object.ReferenceEquals(configSourceImpl1, configSourceImpl2)); }
public void TestGetExceptionManagerFromServiceLocator() { // Create the container var container = new UnityContainer(); // Configurator will read Enterprise Library configuration // and set up the container var configurator = new UnityContainerConfigurator(container); // Configuration source holds the new configuration we want to use // load this in your own code var configSource = new FileConfigurationSource("EntLib.config.xml"); // Configure the container EnterpriseLibraryContainer.CreateDefaultContainer(configSource); // Wrap in ServiceLocator var locator = new UnityServiceLocator(container); // And set Enterprise Library to use it EnterpriseLibraryContainer.Current = locator; var exceptionManager = EnterpriseLibraryContainer.Current.GetInstance <ExceptionManager>(); Assert.NotNull(exceptionManager); }
protected override void Arrange() { waitForChangedEvents = new CountdownEvent(2); ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(1000); originalConfigurationFileContents = File.ReadAllText(@"ExternalFileSource.config"); using (var externalConfigurationFileSource = new FileConfigurationSource(@"ExternalFileSource.config", false)) { externalConfigurationFileSource.Save(FileSourceDummySectionName, new DummySection { }); } base.Arrange(); this.CompositeSource.SourceChanged += (sender, e) => { sourceChangedEvents++; waitForChangedEvents.Signal(); }; this.CompositeSource.AddSectionChangeHandler( FileSourceDummySectionName, (sender, e) => { sectionChangedEvents++; waitForChangedEvents.Signal(); }); }
//private void InitThems() //{ // AsyncOperation operation = AsyncOperationManager.CreateOperation(null); // AutoResetEvent autoResetEvent = new AutoResetEvent(false); // _autoResetEvents.Add(autoResetEvent); // ThreadPool.QueueUserWorkItem(o => // { // AsyncOperation asyncOperation = o as AsyncOperation; // try // { // ResourceDictionary defaultDictionary = new ResourceDictionary() // { // Source = new Uri("/GuoKun.Themes;component/Themes/Default.xaml", UriKind.RelativeOrAbsolute), // }; // _application.Resources.MergedDictionaries.Add(defaultDictionary); // } // catch(Exception e) // { // _log.Fatal("初始化系统样式异常:", e); // asyncOperation.Post // ( // x => // { // MessageBox.Show("初始化系统样式异常,系统将退出!"); // Environment.Exit(-1); // }, // null // ); // } // asyncOperation.OperationCompleted(); // autoResetEvent.Set(); // }, operation); //} private void InitializeDatabase() { AsyncOperation operation = AsyncOperationManager.CreateOperation(null); AutoResetEvent autoResetEvent = new AutoResetEvent(false); _autoResetEvents.Add(autoResetEvent); ThreadPool.QueueUserWorkItem(o => { AsyncOperation asyncOperation = o as AsyncOperation; try { string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, _configuration.DbConfigFile); IConfigurationSource configurationSource = new FileConfigurationSource(path); DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory(configurationSource)); DatabaseFactory.CreateDatabase().CreateConnection().Open(); } catch (Exception e) { _log.Fatal("初始化数据库异常:", e); asyncOperation.Post ( x => { MessageBox.Show("初始化数据库异常,系统将退出!"); Environment.Exit(-1); }, null ); } asyncOperation.OperationCompleted(); autoResetEvent.Set(); }, operation); }
private void GetSecondConfigurationSource() { var configSourceSection = (ConfigurationSourceSection)RootConfiguration.GetSection(ConfigurationSourceSection.SectionName); secondSource = (FileConfigurationSource)configSourceSection.Sources.Get(SecondSourceName).CreateSource(); }
public void DifferentFileConfigurationSourcesDoNotShareEvents() { ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(50); string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); FileConfigurationSource.ResetImplementation(otherConfigurationFile, true); SystemConfigurationSource.ResetImplementation(true); File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); try { bool sysSourceChanged = false; bool otherSourceChanged = false; SystemConfigurationSource systemSource = new SystemConfigurationSource(); FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile); DummySection sysDummySection = systemSource.GetSection(localSection) as DummySection; DummySection otherDummySection = otherSource.GetSection(localSection) as DummySection; Assert.IsTrue(sysDummySection != null); Assert.IsTrue(otherDummySection != null); systemSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { sysSourceChanged = true; }); otherSource.AddSectionChangeHandler(localSection, delegate(object o, ConfigurationChangedEventArgs args) { Assert.AreEqual(12, ((DummySection)otherSource.GetSection(localSection)).Value); otherSourceChanged = true; }); DummySection rwSection = new DummySection(); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(otherConfigurationFile); rwConfiguration.Sections.Remove(localSection); rwConfiguration.Sections.Add(localSection, rwSection = new DummySection()); rwSection.Name = localSection; rwSection.Value = 12; rwSection.SectionInformation.ConfigSource = localSectionSource; rwConfiguration.SaveAs(otherConfigurationFile); Thread.Sleep(200); Assert.AreEqual(false, sysSourceChanged); Assert.AreEqual(true, otherSourceChanged); } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
public void ReadingFileWhichDoesNotExistReturnsEmptyObject() { using (var fileSource = new FileConfigurationSource(this.fullSampleFilename)) { var obj = fileSource.Read(); Assert.IsTrue(JToken.DeepEquals(obj, new JObject())); } }
public void then_attributes_with_omitted_values_are_overridden() { FileConfigurationSource source = new FileConfigurationSource(TargetFile); LoggingSettings settings = (LoggingSettings)source.GetSection(LoggingSettings.SectionName); Assert.IsFalse(settings.RevertImpersonation); Assert.IsFalse(settings.LogWarningWhenNoCategoriesMatch); }
/// <summary> /// Gets a <see cref="FileConfigurationSource"/> based on the applications configuration file. /// </summary> /// <param name="serviceProvider">The a mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param> /// <returns>A <see cref="FileConfigurationSource"/> based on the applications configuration file.</returns> protected override IConfigurationSource GetConfigurationSource(IServiceProvider serviceProvider) { string configurationFile = ServiceHelper.GetCurrentRootNode(serviceProvider).ConfigurationFile; FileConfigurationSource.ResetImplementation(configurationFile, false); return(new FileConfigurationSource(configurationFile)); }
public void CanSaveConfigurationSectionToFile() { FileConfigurationSource source = new FileConfigurationSource(file, false); source.Save(TestConfigurationSection.SectionName, CreateTestSection()); ValidateConfiguration(file); }
public void TryToSaveWithAFileConfigurationSaveParameter() { FileConfigurationSource source = new FileConfigurationSource(file, false); source.Add(TestConfigurationSection.SectionName, CreateTestSection()); ValidateConfiguration(file); }
/// <summary> /// 返回数据库实例 /// </summary> /// <param name="connName"></param> /// <returns></returns> public static DatabaseAdmin getInstance(string connName) { Database db = null; try { FileConfigurationSource fileSource = GetFileConfigurationSource(); if (fileSource != null) { DatabaseProviderFactory dbFactory = new DatabaseProviderFactory(fileSource); if (string.IsNullOrEmpty(connName)) { db = dbFactory.CreateDefault(); } else { db = dbFactory.Create(connName); } } else { if (string.IsNullOrEmpty(connName)) { db = DatabaseFactory.CreateDatabase(); } else { db = DatabaseFactory.CreateDatabase(connName); } } if (db is SqlDatabase) { return(new SqlDatabaseAdmin(db)); } else if (db is OracleDatabase) { return(new OracleDatabaseAdmin(db)); } else if (db is MySqlDatabase) { return(new MySqlDatabaseAdmin(db)); } else if (db.DbProviderFactory.ToString() == "System.Data.OleDb.OleDbFactory") { return(new OleDbDatabaseAdmin(db)); } else { return(null); } } catch (System.Exception ex) { throw ex; } }
private void InitializeCacheManager() { if (null == _cacheManager) { var fileSource = new FileConfigurationSource("SUT.PrintEngine.App.config"); var factory = new CacheManagerFactory(fileSource); _cacheManager = factory.CreateDefault(); } }
public void CreatingFileCausesUpdate() { using (var fileSource = new FileConfigurationSource(this.fullSampleFilename)) using (var updatedEvent = new ManualResetEventSlim(false)) { var updated = false; fileSource.SourceUpdated += () => { updated = true; updatedEvent.Set(); }; this.CreateDefaultFile(); // updates are async so give it some time updatedEvent.Wait(TimeSpan.FromSeconds(60)); Assert.IsTrue(updated, "File update did not occur."); } }
public void SectionsCanBeAccessedThroughFileConfigurationSource() { string fullConfigurationFilepath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; string otherConfigurationFilepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); File.Copy(fullConfigurationFilepath, otherConfigurationFilepath); try { using (FileConfigurationSource otherConfiguration = new FileConfigurationSource(otherConfigurationFilepath, false)) { DummySection dummySection = otherConfiguration.GetSection(localSection) as DummySection; Assert.IsNotNull(dummySection); } } finally { if (File.Exists(otherConfigurationFilepath)) { File.Delete(otherConfigurationFilepath); } } }
public void NonExistentSectionReturnsNullThroughFileConfigurationSource() { string fullConfigurationFilepath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; string otherConfigurationFilepath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); File.Copy(fullConfigurationFilepath, otherConfigurationFilepath); try { using (FileConfigurationSource otherConfiguration = new FileConfigurationSource(otherConfigurationFilepath, false)) { object wrongSection = otherConfiguration.GetSection("wrong section"); Assert.IsNull(wrongSection); } } finally { if (File.Exists(otherConfigurationFilepath)) { File.Delete(otherConfigurationFilepath); } } }
public void AddingUnprotectedSectionsWithProtectionProviderWillProtectThem() { DummySection dummySection = new DummySection(); string configurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; FileConfigurationSource fileConfigSource = new FileConfigurationSource(configurationFile, false); fileConfigSource.Add(protectedSection, dummySection, ProtectedConfiguration.DefaultProvider); ConfigurationSection section = fileConfigSource.GetSection(protectedSection); Assert.IsTrue(section.SectionInformation.IsProtected); Assert.IsNotNull(section.SectionInformation); Assert.AreEqual(ProtectedConfiguration.DefaultProvider, section.SectionInformation.ProtectionProvider.Name); }
public void CreatingFileConfigurationSourceForNonExistingFileThrows() { FileConfigurationSource source = new FileConfigurationSource("this.config.file.doesnt.exist.config"); }
public void UpdatingExistingFileCausesUpdate() { this.CreateDefaultFile(); using (var updated = new ManualResetEventSlim(false)) using (var fileSource = new FileConfigurationSource(this.fullSampleFilename)) { fileSource.SourceUpdated += updated.Set; using (var fs = new FileStream(this.fullSampleFilename, FileMode.Open, FileAccess.ReadWrite)) { fs.Seek(0, SeekOrigin.Begin); var content = Encoding.UTF8.GetBytes(@"{""jenny"":8675309}"); fs.Write(content, 0, content.Length); fs.Close(); } Assert.IsTrue(updated.Wait(TimeSpan.FromSeconds(60))); } }
public void DifferentFileConfigurationSourcesDoNotShareEvents() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); try { bool sysSourceChanged = false; bool otherSourceChanged = false; using (SystemConfigurationSource systemSource = new SystemConfigurationSource(true, 50)) using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, true, 50)) { DummySection sysDummySection = systemSource.GetSection(localSection) as DummySection; DummySection otherDummySection = otherSource.GetSection(localSection) as DummySection; Assert.IsTrue(sysDummySection != null); Assert.IsTrue(otherDummySection != null); systemSource.AddSectionChangeHandler( localSection, delegate(object o, ConfigurationChangedEventArgs args) { sysSourceChanged = true; }); otherSource.AddSectionChangeHandler( localSection, delegate(object o, ConfigurationChangedEventArgs args) { Assert.AreEqual(12, ((DummySection)otherSource.GetSection(localSection)).Value); otherSourceChanged = true; }); DummySection rwSection = new DummySection(); System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(otherConfigurationFile); rwConfiguration.Sections.Remove(localSection); rwConfiguration.Sections.Add(localSection, rwSection = new DummySection()); rwSection.Name = localSection; rwSection.Value = 12; rwSection.SectionInformation.ConfigSource = localSectionSource; rwConfiguration.SaveAs(otherConfigurationFile); Thread.Sleep(500); Assert.AreEqual(false, sysSourceChanged); Assert.AreEqual(true, otherSourceChanged); } } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
public void RemovingSectionCausesChangeNotification() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); try { bool otherSourceChanged = false; using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, true, 50)) { DummySection otherDummySection = otherSource.GetSection(localSection) as DummySection; Assert.IsTrue(otherDummySection != null); otherSource.AddSectionChangeHandler( localSection, delegate(object o, ConfigurationChangedEventArgs args) { Assert.IsNull(otherSource.GetSection(localSection)); otherSourceChanged = true; }); otherSource.Remove(localSection); Thread.Sleep(300); Assert.AreEqual(true, otherSourceChanged); } } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
// this test relied on lazily initialization of the Configuration object, and would only work if changes // happened before any section was requested public void ReadsLatestVersionOnFirstRequest() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); try { File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, false)) { DummySection rwSection = null; ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap(); fileMap.ExeConfigFilename = otherConfigurationFile; System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); rwConfiguration.Sections.Remove(localSection); rwConfiguration.Sections.Add(localSection, rwSection = new DummySection()); rwSection.Name = localSection; rwSection.Value = 12; rwSection.SectionInformation.ConfigSource = localSectionSource; rwConfiguration.Save(); DummySection otherSection = otherSource.GetSection(localSection) as DummySection; Assert.IsNotNull(otherSection); Assert.AreEqual(12, otherSection.Value); } } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
public YamlConfigurationProvider(FileConfigurationSource source) : base(source) { }
public void RemoveIsReflectedInNextRequestWithoutRefresh() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); try { File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, false)) { DummySection otherSection = otherSource.GetSection(localSection) as DummySection; DummySection newSection = new DummySection(); newSection.Value = 13; otherSource.Add(localSection, newSection); otherSource.Remove(localSection); otherSection = otherSource.GetSection(localSection) as DummySection; Assert.IsNull(otherSection); } } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
public void ReadingFileWhichDoesNotExistReturnsEmptyObject() { using (var fileSource = new FileConfigurationSource(this.fullSampleFilename)) { var obj = fileSource.Read(); Assert.IsTrue(JToken.DeepEquals(obj, new JObject())); } }
public void SavingWithEmptyProtectionProviderThrowsArgumentException() { string configurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; FileConfigurationSource fileConfigSource = new FileConfigurationSource(configurationFile, false); DummySection newSection = new DummySection(); fileConfigSource.Add(localSection, newSection, string.Empty); }
public void ChangeInExternalConfigSourceIsDetected() { string otherConfigurationFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Other.config"); try { File.Copy(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, otherConfigurationFile); using (FileConfigurationSource otherSource = new FileConfigurationSource(otherConfigurationFile, true, 50)) { DummySection rwSection; System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(otherConfigurationFile); rwConfiguration.Sections.Remove(externalSection); rwConfiguration.Sections.Add(externalSection, rwSection = new DummySection()); rwSection.Name = externalSection; rwSection.Value = 12; rwSection.SectionInformation.ConfigSource = externalSectionSource; rwConfiguration.Save(ConfigurationSaveMode.Full); DummySection otherSection = otherSource.GetSection(externalSection) as DummySection; Assert.AreEqual(12, otherSection.Value); rwSection.Value = 13; rwConfiguration.Save(ConfigurationSaveMode.Modified); Thread.Sleep(300); otherSection = otherSource.GetSection(externalSection) as DummySection; Assert.AreEqual(13, otherSection.Value); } } finally { if (File.Exists(otherConfigurationFile)) { File.Delete(otherConfigurationFile); } } }
private static void ValidateConfigurationFile(XDocument resultDocument) { string tempValidationFilePath = TempRandomConfigFilePath; resultDocument.SaveToFile(tempValidationFilePath); try { IConfigurationSource testConfigSource = new FileConfigurationSource(tempValidationFilePath); foreach (XElement sectionElement in resultDocument.Root.Element("configSections").Elements()) { if (sectionElement.Attribute("name") != null) { string sectionName = sectionElement.Attribute("name").Value; try { testConfigSource.GetSection(sectionName); } catch (ConfigurationErrorsException exception) { if(exception.InnerException != null && exception.InnerException is AppCodeTypeNotFoundConfigurationException) { // App_Code classes aren't compiled during package installation, therefore related exceptions are ignored } else { throw; } } } } DeleteTempConfigurationFile(tempValidationFilePath); } catch (Exception) { DeleteTempConfigurationFile(tempValidationFilePath); throw; } }
public void CreatingFileConfigurationSourceWithNullArgumentThrows() { FileConfigurationSource source = new FileConfigurationSource(null); }