public void CanSaveConfigurationSectionToFile()
        {
            SystemConfigurationSource source = new SystemConfigurationSource();
            source.Save(file, InstrumentationConfigurationSection.SectionName, CreateInstrumentationSection());

            ValidateConfiguration(file);
        }
        public void ConfigurationChangeNotificationRefreshesLogger()
        {
            using (var configurationSource = new SystemConfigurationSource(false))
            using (var serviceLocator = (UnityServiceLocator)EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource))
            {
                EnterpriseLibraryContainer.Current = serviceLocator;

                Logger.Reset();
                MockTraceListener.Reset();

                Logger.Write("test", "MockCategoryOne");
                Assert.AreEqual(1, MockTraceListener.Entries.Count);

                System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                LoggingSettings rwSettings = rwConfiguration.GetSection(LoggingSettings.SectionName) as LoggingSettings;
                ((CategoryFilterData)rwSettings.LogFilters.Get("Category")).CategoryFilters.Add(new CategoryFilterEntry("MockCategoryOne"));
                rwConfiguration.Save();

                ((IConfigurationSourceTest)configurationSource).ConfigSourceChanged(string.Empty);

                MockTraceListener.Reset();
                Logger.Write("test", "MockCategoryOne");
                Assert.AreEqual(0, MockTraceListener.Entries.Count, "should have been filtered out by the new category filter");
            }
        }
 public void Setup()
 {
     container = new UnityContainer();
     var configurationSource =
         new SystemConfigurationSource();
     EnterpriseLibraryContainer.ConfigureContainer(new UnityContainerConfigurator(container), configurationSource);
 }
        public void TryToSaveWithAFileConfigurationSaveParameter()
        {
            SystemConfigurationSource source = new SystemConfigurationSource();
            source.Add(new FileConfigurationParameter(file), InstrumentationConfigurationSection.SectionName, CreateInstrumentationSection());

            ValidateConfiguration(file);
        }
        public void AddingCategoryFilterToConfigIsReflectedInContainer()
        {
            using (var configurationSource = new SystemConfigurationSource(false))
            using (var serviceLocator = (UnityServiceLocator)EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource))
            {
                EnterpriseLibraryContainer.Current = serviceLocator;

                Logger.Reset();
                MockTraceListener.Reset();

                Logger.Write("test", "MockCategoryOne");
                Assert.AreEqual(1, MockTraceListener.Entries.Count);

                System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                LoggingSettings rwSettings = rwConfiguration.GetSection(LoggingSettings.SectionName) as LoggingSettings;
                ((CategoryFilterData)rwSettings.LogFilters.Get("Category")).CategoryFilters.Add(new CategoryFilterEntry("MockCategoryOne"));
                rwConfiguration.Save();

                ((IConfigurationSourceTest)configurationSource).ConfigSourceChanged(string.Empty);

                var categoryFilter = EnterpriseLibraryContainer.Current.GetInstance<CategoryFilter>("Category");
                Assert.AreEqual(1,
                    categoryFilter.CategoryFilters.Count(c => c == "MockCategoryOne"));
            }
        }
        public void CanReadSettingsFromConfigurationFile()
        {
            using (var configurationSource = new SystemConfigurationSource(false))
            {
                MsmqDistributorSettings settings = MsmqDistributorSettings.GetSettings(configurationSource);

                Assert.IsNotNull(settings);
                Assert.AreEqual(CommonUtil.MessageQueuePath, settings.MsmqPath);
                Assert.AreEqual(1000, settings.QueueTimerInterval);
                Assert.AreEqual("Msmq Distributor", settings.ServiceName);
            }
        }
		public void CanBuildCustomAuthorizationProviderFromSystemConfiguration()
		{
			IConfigurationSource configurationSource
				= new SystemConfigurationSource();

			IAuthorizationProvider custom
				= EnterpriseLibraryFactory.BuildUp<IAuthorizationProvider>("custom", configurationSource);

			Assert.IsNotNull(custom);
			Assert.AreSame(typeof(MockCustomAuthorizationProvider), custom.GetType());
			Assert.AreEqual("value1", ((MockCustomAuthorizationProvider)custom).customValue);
		}
        public void CanReceiveNotificationsFromImplementation()
        {
            SystemConfigurationSource.ResetImplementation(false);

            SystemConfigurationSource source = new SystemConfigurationSource();
            source.GetSection(localSection);
            source.AddSectionChangeHandler(localSection, new ConfigurationChangedEventHandler(OnConfigurationChanged));

            SystemConfigurationSource.Implementation.ConfigSourceChanged(localSectionSource);

            Assert.AreEqual(1, updatedSectionsTally[localSection]);
        }
        public void CanBuildCustomAuthorizationProviderFromSystemConfiguration()
        {
            using (var configurationSource = new SystemConfigurationSource(false))
            {
                IAuthorizationProvider custom = 
                    EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource)
                        .GetInstance<IAuthorizationProvider>("custom");

                Assert.IsNotNull(custom);
                Assert.AreSame(typeof(MockCustomAuthorizationProvider), custom.GetType());
                Assert.AreEqual("value1", ((MockCustomAuthorizationProvider)custom).customValue);
            }
        }
		public void SameImplementationSurvivesAcrossInstances()
		{
			SystemConfigurationSource source1 = new SystemConfigurationSource();
			object section = source1.GetSection(localSection);

			Assert.IsNotNull(section);
			Assert.AreEqual(1, SystemConfigurationSource.Implementation.WatchedSections.Count);
			Assert.IsTrue(SystemConfigurationSource.Implementation.WatchedSections.Contains(localSection));

			source1 = null;

			GC.Collect(3);
		
			Assert.AreEqual(1, SystemConfigurationSource.Implementation.WatchedSections.Count);
			Assert.IsTrue(SystemConfigurationSource.Implementation.WatchedSections.Contains("dummy.local"));
		}
        public static UnityContainer Create()
        {
            var container = new UnityContainer();
            container.InstallCoreExtensions();

            // 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
            IConfigurationSource configSource = new SystemConfigurationSource(true);

            // Configure the container
            EnterpriseLibraryContainer.ConfigureContainer(configurator, configSource);

            // Self-register and set up service location
            container.RegisterInstance<IUnityContainer>(container);
            var locator = new UnityServiceLocator(container);
            ServiceLocator.SetLocatorProvider(() => locator);

            return container;
        }
        public void Initialization()
        {
            DistributorServiceTestFacade distributor = new DistributorServiceTestFacade();
            distributor.InitializeComponent();
            Assert.IsNotNull(distributor);
            Assert.AreEqual(ServiceStatus.OK, distributor.Status);

            using (var configurationSource = new SystemConfigurationSource(false))
            {
                MsmqDistributorSettings settings = MsmqDistributorSettings.GetSettings(configurationSource);

                Assert.AreEqual(settings.ServiceName, distributor.ApplicationName);

                // force log entry
                distributor.EventLogger
                    .LogServiceFailure(
                        string.Empty,
                        new Exception("simulated exception - forced event logger flush"),
                        TraceEventType.Error);

                Assert.IsTrue(CommonUtil.LogEntryExists(Resources.InitializeComponentStarted), "init begin");
                Assert.IsTrue(CommonUtil.LogEntryExists(Resources.InitializeComponentCompleted), "init end");
            }
        }
        public void DifferentSqlConfigurationSourcesDoNotShareEvents()
        {
            ConfigurationChangeWatcher.SetDefaultPollDelayInMilliseconds(50);

            SqlConfigurationSource.ResetImplementation(data1, true);
            SystemConfigurationSource.ResetImplementation(true);


            bool sysSourceChanged = false;
            bool otherSourceChanged = false;

            SystemConfigurationSource systemSource = new SystemConfigurationSource();
            DummySection sysDummySerializableSection = systemSource.GetSection(localSection) as DummySection;

            SqlConfigurationSource          otherSource =   new SqlConfigurationSource(
                                                                data1.ConnectionString,  
                                                                data1.GetStoredProcedure,  
                                                                data1.SetStoredProcedure, 
                                                                data1.RefreshStoredProcedure, 
                                                                data1.RemoveStoredProcedure);
            SqlConfigurationParameter   parameter =     new SqlConfigurationParameter(
                                                                data1.ConnectionString,  
                                                                data1.GetStoredProcedure,  
                                                                data1.SetStoredProcedure, 
                                                                data1.RefreshStoredProcedure, 
                                                                data1.RemoveStoredProcedure);
            otherSource.Add(parameter,localSection, sysDummySerializableSection);
            
            DummySection    otherDummySerializableSection = otherSource.GetSection(localSection) as DummySection;

            Assert.IsTrue(sysDummySerializableSection != null);
            Assert.IsTrue(otherDummySerializableSection != 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.OpenMachineConfiguration();
            rwConfiguration.Sections.Remove(localSection);
            rwConfiguration.Sections.Add(localSection, rwSection = new DummySection());
            rwSection.Name = localSection;
            rwSection.Value = 12;
            rwSection.SectionInformation.ConfigSource = data1.ConnectionString;

            SqlConfigurationManager.SaveSection(rwSection.Name, rwSection, data1);
            
            Thread.Sleep(200);

            Assert.AreEqual(false, sysSourceChanged);
            Assert.AreEqual(true, otherSourceChanged);

        }
        public void EmptyCategoriesRevertToDefaultCategory()
        {
            MockTraceListener.Reset();
            using (var configurationSource = new SystemConfigurationSource(false))
            {
                LoggingSettings settings = LoggingSettings.GetLoggingSettings(configurationSource);

                LogEntry log = new LogEntry();
                log.EventId = 1;
                log.Message = "test";
                log.Categories = new string[0];
                log.Severity = TraceEventType.Error;
                Logger.Write(log);

                Assert.IsNotNull(MockTraceListener.LastEntry);
                Assert.AreEqual("test", MockTraceListener.LastEntry.Message);
                Assert.AreEqual(1, MockTraceListener.LastEntry.Categories.Count);
                Assert.IsTrue(MockTraceListener.LastEntry.Categories.Contains(settings.DefaultCategory));
            }
        }
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:Cedar.Core.SettingSource.ConfigurationFileSettingSource" /> class.
 /// </summary>
 public ConfigurationFileSettingSource()
 {
     ConfigurationSource = new SystemConfigurationSource();
 }
 private static void AddExceptionHandlingConfiguration(IUnityContainer factory)
 {
     var configSource = new SystemConfigurationSource(false);
     new UnityContainerConfigurator(factory).RegisterAll(
         configSource,
         (ITypeRegistrationsProvider)configSource.GetSection(ExceptionHandlingSettings.SectionName));
 }
Esempio n. 17
0
 protected void SetModuleSettings()
 {
     using (IConfigurationSource source = new SystemConfigurationSource())
     {
         ModulesSettingsSection section = null;
         try
         {
             section = source.GetSection("module.definitions") as ModulesSettingsSection;
         }
         catch (Exception)
         {
             /*if (Log != null)
                 Log.Error(e);*/
         }
         if (section != null)
         {
             object module = "ew";
             /*
             if (section.DynamicContextSwitch == false || !ControllerContext.RouteData.Values.TryGetValue("module", out module))
             {
                 module = AppType;
             }
              * */
             if (module != null)
             {
                 var moduleName = module.ToString();
                 if (!string.IsNullOrWhiteSpace(moduleName) && section.Modules != null)
                 {
                     var settings = section.Modules.FirstOrDefault(x => x.Name == moduleName);
                     if (settings != null && settings.Settings != null)
                     {
                         CopySettings(ViewData, "", settings);
                         foreach (var p in settings.Pages)
                         {
                             CopySettings(ViewData, "pages." + p.Name + ".", p);
                         }
                     }
                     ViewData["module"] = moduleName.ToLowerInvariant();
                     HandleSettings(settings);
                 }
             }
         }
     }
 }
        /// <summary>
        /// Returns a new <see cref="SystemConfigurationSource"/>.
        /// </summary>
        /// <returns>A new configuration source.</returns>
        public override IConfigurationSource CreateSource()
        {
            IConfigurationSource createdObject = new SystemConfigurationSource();

            return(createdObject);
        }
        /// <summary>
        /// Returns a new <see cref="SystemConfigurationSource"/>.
        /// </summary>
        /// <returns>A new configuration source.</returns>
        protected internal override IConfigurationSource CreateSource()
        {
            IConfigurationSource createdObject = new SystemConfigurationSource();

            return(createdObject);
        }
 public void TryToSaveWithTheWrongConfigurationSaveParameterTypeThrows()
 {
     SystemConfigurationSource source = new SystemConfigurationSource();
     source.Add(new WrongConfigurationSaveParameter(), InstrumentationConfigurationSection.SectionName, CreateInstrumentationSection());
 }
 public void TryToSaveWithNullOrEmptyFileNameThrows()
 {
     SystemConfigurationSource source = new SystemConfigurationSource();
     source.Save((string)null, InstrumentationConfigurationSection.SectionName, CreateInstrumentationSection());
 }
		public void RemovingAndAddingSection()
		{
			SystemConfigurationSource.ResetImplementation(true);
			SystemConfigurationSource sysSource = new SystemConfigurationSource();

			DummySection dummySection = sysSource.GetSection(localSection) as DummySection;
			Assert.IsTrue(dummySection != null);

			System.Threading.Thread.Sleep(300);

			System.Configuration.Configuration rwConfiguration =
				ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
			string fileName = rwConfiguration.FilePath;
			int numSections = rwConfiguration.Sections.Count;
			FileConfigurationParameter parameter = new FileConfigurationParameter(fileName);
			sysSource.Remove(parameter, localSection);

			System.Threading.Thread.Sleep(300);

			rwConfiguration =
				ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
			Assert.AreEqual(rwConfiguration.Sections.Count, numSections - 1);
			sysSource.Add(parameter, localSection, new DummySection());	// can't be the same instance

			System.Threading.Thread.Sleep(300);
			rwConfiguration =
				ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
			Assert.AreEqual(rwConfiguration.Sections.Count, numSections);
		}
        public void ConfigurationChangeNotificationRefreshesLoggerAutomatically()
        {
            using (var configurationSource = new SystemConfigurationSource(true, 100))
            using (var serviceLocator = (UnityServiceLocator)EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource))
            {
                EnterpriseLibraryContainer.Current = serviceLocator;

                Logger.Reset();
                MockTraceListener.Reset();

                Logger.Write("test", "MockCategoryOne");
                Assert.AreEqual(1, MockTraceListener.Entries.Count);

                System.Configuration.Configuration rwConfiguration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                LoggingSettings rwSettings = rwConfiguration.GetSection(LoggingSettings.SectionName) as LoggingSettings;
                ((CategoryFilterData)rwSettings.LogFilters.Get("Category")).CategoryFilters.Add(new CategoryFilterEntry("MockCategoryOne"));
                rwConfiguration.Save();

                Thread.Sleep(1000);

                MockTraceListener.Reset();
                Logger.Write("test", "MockCategoryOne");
                Assert.AreEqual(0, MockTraceListener.Entries.Count);
            }
        }
 public void TryToSaveWithNullOrEmptySectionNameThrows()
 {
     SystemConfigurationSource source = new SystemConfigurationSource();
     source.Save(file, null, CreateInstrumentationSection());
 }
 public void TryToSaveWithNullSectionThrows()
 {
     SystemConfigurationSource source = new SystemConfigurationSource();
     source.Save(file, InstrumentationConfigurationSection.SectionName, null);
 }
		/// <summary>
		/// Returns a new <see cref="SystemConfigurationSource"/>.
		/// </summary>
		/// <returns>A new configuration source.</returns>
		protected internal override IConfigurationSource CreateSource()
		{
			IConfigurationSource createdObject = new SystemConfigurationSource();

			return createdObject;
		}
		public void SystemConfigurationSourceReturnsReadOnlySections()
		{

			SystemConfigurationSource.ResetImplementation(false);

			SystemConfigurationSource source = new SystemConfigurationSource();
			ConfigurationSection dummySection = source.GetSection(localSection);

			Assert.IsTrue(dummySection.IsReadOnly());
		}
 public void SaveConfigurationSectionWithNoConfigurationFileThrows()
 {
     SystemConfigurationSource source = new SystemConfigurationSource();
     source.Save("foo.exe.cofig", InstrumentationConfigurationSection.SectionName, CreateInstrumentationSection());
 }
        /// <summary>
        /// Returns a new <see cref="SystemConfigurationSource"/>.
        /// </summary>
        /// <returns>A new configuration source.</returns>
        public override IConfigurationSource CreateSource()
        {
            IConfigurationSource createdObject = new SystemConfigurationSource();

            return createdObject;
        }