Esempio n. 1
0
		private static IEnumerable<ConfigurationSectionEntry> GetConfigurationSections(ConfigurationSectionGroup group, ConfigurationSectionGroupPath groupPath, ConfigurationSectionErrorHandler errorHandler, bool recursive)
		{
			if (recursive)
			{
				foreach (ConfigurationSectionGroup childGroup in group.SectionGroups)
				{
					foreach (var sectionEntry in GetConfigurationSections(childGroup, groupPath.GetChildGroupPath(childGroup.Name), errorHandler, true))
						yield return sectionEntry;
				}
			}

			for (var n = 0; n < group.Sections.Count; ++n)
			{
				ConfigurationSection section = null;
				try
				{
					section = group.Sections[n];
				}
				catch (ConfigurationErrorsException)
				{
					if (errorHandler != null) section = errorHandler.Invoke(groupPath, group.Sections.Keys[n]);
				}
				if (section != null) yield return new ConfigurationSectionEntry(groupPath, section);
			}
		}
Esempio n. 2
0
        private static IEnumerable <ConfigurationSectionEntry> GetConfigurationSections(Configuration configuration, ConfigurationSectionErrorHandler errorHandler)
        {
            ConfigurationSectionGroupPath rootPath = ConfigurationSectionGroupPath.Root;

            foreach (var childSection in GetConfigurationSections(configuration.RootSectionGroup, rootPath, errorHandler, true))
            {
                yield return(childSection);
            }
        }
Esempio n. 3
0
        private static void MigrateSection(ConfigurationSection sourceSection, ConfigurationSectionGroupPath groupPath, Configuration destinationConfiguration)
        {
            if (sourceSection.GetType().IsDefined(typeof(SharedSettingsMigrationDisabledAttribute), false))
            {
                return;                 //disabled
            }
            var destinationGroup = groupPath.GetSectionGroup(destinationConfiguration, true);

            var destinationSection = destinationGroup.Sections[sourceSection.SectionInformation.Name];

            if (destinationSection == null)
            {
                destinationSection = (ConfigurationSection)Activator.CreateInstance(sourceSection.GetType(), true);
                destinationGroup.Sections.Add(sourceSection.SectionInformation.Name, destinationSection);
            }

            var customMigrator = sourceSection as IMigrateSettings;

            foreach (PropertyInformation sourceProperty in sourceSection.ElementInformation.Properties)
            {
                var destinationProperty = destinationSection.ElementInformation.Properties[sourceProperty.Name];
                if (destinationProperty == null)
                {
                    continue;
                }

                if (customMigrator != null)
                {
                    var migrationValues = new SettingsPropertyMigrationValues(
                        sourceProperty.Name, MigrationScope.Shared, destinationProperty.Value, sourceProperty.Value);

                    customMigrator.MigrateSettingsProperty(migrationValues);
                    if (!Equals(migrationValues.CurrentValue, destinationProperty.Value))
                    {
                        destinationSection.SectionInformation.ForceSave = true;
                        destinationProperty.Value = migrationValues.CurrentValue;
                    }
                }
                else
                {
                    destinationSection.SectionInformation.ForceSave = true;
                    destinationProperty.Value = sourceProperty.Value;
                }
            }
        }
Esempio n. 4
0
        private static IEnumerable <ConfigurationSectionEntry> GetConfigurationSections(ConfigurationSectionGroup group, ConfigurationSectionGroupPath groupPath, ConfigurationSectionErrorHandler errorHandler, bool recursive)
        {
            if (recursive)
            {
                foreach (ConfigurationSectionGroup childGroup in group.SectionGroups)
                {
                    foreach (var sectionEntry in GetConfigurationSections(childGroup, groupPath.GetChildGroupPath(childGroup.Name), errorHandler, true))
                    {
                        yield return(sectionEntry);
                    }
                }
            }

            for (var n = 0; n < group.Sections.Count; ++n)
            {
                ConfigurationSection section = null;
                try
                {
                    section = group.Sections[n];
                }
                catch (ConfigurationErrorsException)
                {
                    if (errorHandler != null)
                    {
                        section = errorHandler.Invoke(groupPath, group.Sections.Keys[n]);
                    }
                }
                if (section != null)
                {
                    yield return(new ConfigurationSectionEntry(groupPath, section));
                }
            }
        }
Esempio n. 5
0
 public ConfigurationSectionEntry(ConfigurationSectionGroupPath parentPath, ConfigurationSection section)
 {
     ParentPath = parentPath;
     Section    = section;
 }
Esempio n. 6
0
        private static ConfigurationSection HandleLegacyConfigurationSection(string exeConfigFilename, ConfigurationSectionGroupPath groupPath, string sectionKey)
        {
            var sectionPath = groupPath.GetChildGroupPath(sectionKey).ToString();

            foreach (var shredSettingsType in _shredSettingsTypes)
            {
                if (LegacyShredConfigSectionAttribute.IsMatchingLegacyShredConfigSectionType(shredSettingsType, sectionPath))
                {
                    var xmlDocument = new ConfigXmlDocument();
                    xmlDocument.Load(exeConfigFilename);

                    var sectionElement = xmlDocument.SelectSingleNode("//" + sectionPath);
                    if (sectionElement != null)
                    {
                        var section = (ShredConfigSection)Activator.CreateInstance(shredSettingsType, true);
                        section.LoadXml(sectionElement.OuterXml);
                        return(section);
                    }
                }
            }
            return(null);
        }
Esempio n. 7
0
		private static void MigrateSection(ConfigurationSection sourceSection, ConfigurationSectionGroupPath groupPath, Configuration destinationConfiguration)
		{
			if (sourceSection.GetType().IsDefined(typeof(SharedSettingsMigrationDisabledAttribute), false))
				return; //disabled

			var destinationGroup = groupPath.GetSectionGroup(destinationConfiguration, true);

			var destinationSection = destinationGroup.Sections[sourceSection.SectionInformation.Name];
			if (destinationSection == null)
			{
				destinationSection = (ConfigurationSection)Activator.CreateInstance(sourceSection.GetType(), true);
				destinationGroup.Sections.Add(sourceSection.SectionInformation.Name, destinationSection);
			}

			var customMigrator = sourceSection as IMigrateSettings;
			foreach (PropertyInformation sourceProperty in sourceSection.ElementInformation.Properties)
			{
				var destinationProperty = destinationSection.ElementInformation.Properties[sourceProperty.Name];
				if (destinationProperty == null)
					continue;

				if (customMigrator != null)
				{
					var migrationValues = new SettingsPropertyMigrationValues(
						sourceProperty.Name, MigrationScope.Shared, destinationProperty.Value, sourceProperty.Value);

					customMigrator.MigrateSettingsProperty(migrationValues);
					if (!Equals(migrationValues.CurrentValue, destinationProperty.Value))
					{
						destinationSection.SectionInformation.ForceSave = true; 
						destinationProperty.Value = migrationValues.CurrentValue;
					}
				}
				else
				{
					destinationSection.SectionInformation.ForceSave = true;
					destinationProperty.Value = sourceProperty.Value;
				}
			}
		}
Esempio n. 8
0
			public ConfigurationSectionEntry(ConfigurationSectionGroupPath parentPath, ConfigurationSection section)
			{
				ParentPath = parentPath;
				Section = section;
			}
Esempio n. 9
0
		private static ConfigurationSection HandleLegacyConfigurationSection(string exeConfigFilename, ConfigurationSectionGroupPath groupPath, string sectionKey)
		{
			var sectionPath = groupPath.GetChildGroupPath(sectionKey).ToString();
			foreach (var shredSettingsType in _shredSettingsTypes)
			{
				if (LegacyShredConfigSectionAttribute.IsMatchingLegacyShredConfigSectionType(shredSettingsType, sectionPath))
				{
					var xmlDocument = new ConfigXmlDocument();
					xmlDocument.Load(exeConfigFilename);

					var sectionElement = xmlDocument.SelectSingleNode("//" + sectionPath);
					if (sectionElement != null)
					{
						var section = (ShredConfigSection) Activator.CreateInstance(shredSettingsType, true);
						section.LoadXml(sectionElement.OuterXml);
						return section;
					}
				}
			}
			return null;
		}