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 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 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);

        }
 private static void AddExceptionHandlingConfiguration(IUnityContainer factory)
 {
     var configSource = new SystemConfigurationSource(false);
     new UnityContainerConfigurator(factory).RegisterAll(
         configSource,
         (ITypeRegistrationsProvider)configSource.GetSection(ExceptionHandlingSettings.SectionName));
 }
Example #5
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);
                 }
             }
         }
     }
 }
		public void SystemConfigurationSourceReturnsReadOnlySections()
		{

			SystemConfigurationSource.ResetImplementation(false);

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

			Assert.IsTrue(dummySection.IsReadOnly());
		}
		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);
		}