protected override void Arrange()
        {
            base.Arrange();

            File.Delete(MainConfigurationFile);
            File.Delete(SatelliteConfigurationSourcePath);

            var builder = new ConfigurationSourceBuilder();

            var configurationSettings = new ConfigurationSourceSection();
            configurationSettings.SelectedSource = "System Configuration";
            configurationSettings.Sources.Add(new FileConfigurationSourceElement(SatelliteSourceName, SatelliteConfigurationSourcePath));
            configurationSettings.Sources.Add(new SystemConfigurationSourceElement("System Configuration"));
            builder.AddSection(ConfigurationSourceSection.SectionName, configurationSettings);

            builder.ConfigureExceptionHandling()
                .GivenPolicyWithName("policy")
                .ForExceptionType<Exception>();

            var source = new DesignDictionaryConfigurationSource();
            builder.UpdateConfigurationWithReplace(source);

            ConfigurationSource = Container.Resolve<ConfigurationSourceModel>();
            ConfigurationSource.Load(source);
        }
        protected override void Arrange()
        {
            base.Arrange();

            targetFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "manageableSource.config");
            File.Create(targetFilePath).Dispose();
            File.WriteAllText(targetFilePath, "<configuration/>");

            var source = new DesignConfigurationSource(targetFilePath);

            var section =
                new ConfigurationSourceSection
                {
                    SelectedSource = "manageable",
                    Sources =
                    {
                        new ManageableConfigurationSourceElement
                        {
                            Name = "manageable",
                            FilePath = "file.config",
                        }
                    }
                };

            source.AddLocalSection(ConfigurationSourceSection.SectionName, section);


            var sourceModel = this.Container.Resolve<ConfigurationSourceModel>();
            sourceModel.Load(source);

            SectionViewModel =
                sourceModel.Sections.Where(x => x.ConfigurationType == typeof(ConfigurationSourceSection)).Single();

            ConfigurationSourceViewModel = SectionViewModel.GetDescendentsOfType<ManageableConfigurationSourceElement>().FirstOrDefault();
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new configuration sources based on the configuration information from the application's default
        /// configuration file.
        /// </summary>
        /// <param name="name">The name for the desired configuration source.</param>
        /// <returns>The new configuration source instance described in the configuration file.</returns>
        /// <exception cref="ConfigurationErrorsException">when no configuration information is found for name <paramref name="name"/>.</exception>
        /// <exception cref="ArgumentNullException">when <paramref name="name"/> is null or empty.</exception>
        public static IConfigurationSource Create(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            ConfigurationSourceSection configurationSourceSection
                = ConfigurationSourceSection.GetConfigurationSourceSection();

            if (configurationSourceSection == null)
            {
                throw new ConfigurationErrorsException(Resources.ExceptionConfigurationSourceSectionNotFound);
            }

            ConfigurationSourceElement objectConfiguration
                = configurationSourceSection.Sources.Get(name);

            if (objectConfiguration == null)
            {
                throw new ConfigurationErrorsException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              Resources.ExceptionNamedConfigurationNotFound,
                              name,
                              "ConfigurationSourceFactory"));
            }

            IConfigurationSource source = objectConfiguration.CreateSource();

            return(source);
        }
        protected override void Arrange()
        {
            base.Arrange();

            File.Delete(MainConfigurationFile);
            File.Delete(SatelliteConfigurationSourcePath);

            var builder = new ConfigurationSourceBuilder();

            var configurationSettings = new ConfigurationSourceSection();
            configurationSettings.SelectedSource = "System Configuration";
            configurationSettings.Sources.Add(new FileConfigurationSourceElement(SatelliteSourceName, SatelliteConfigurationSourcePath));
            configurationSettings.Sources.Add(new SystemConfigurationSourceElement("System Configuration"));
            builder.AddSection(ConfigurationSourceSection.SectionName, configurationSettings);

            builder.ConfigureCaching()
                .ForCacheManagerNamed("TestCacheManager")
                .StoreInMemory();

            var source = new DesignDictionaryConfigurationSource();
            builder.UpdateConfigurationWithReplace(source);

            ConfigurationSource = Container.Resolve<ConfigurationSourceModel>();
            ConfigurationSource.Load(source);
        }
        public void CanDeserializeSerializedConfiguration()
        {
            string sourceName1 = "source1";
            string sourceName2 = "source2";

            string sourceFile1 = "file 1";

            ConfigurationSourceSection settings = new ConfigurationSourceSection();

            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());
        }
		private ConfigurationSourceSectionNode GetSectionNode()
		{
			ConfigurationSourceSection section = new ConfigurationSourceSection();
			section.Sources.Add(new SystemConfigurationSourceElement("System"));
			section.Sources.Add(new FileConfigurationSourceElement("File", "app.config"));
			section.SelectedSource = "File";
			ConfigurationSourceSectionNodeBuilder builder = new ConfigurationSourceSectionNodeBuilder(ServiceProvider, section);
			return builder.Build();
		}
        protected override void Arrange()
        {
            base.Arrange();

            var section = new ConfigurationSourceSection();
            section.Sources.Add(new SystemConfigurationSourceElement() { Name = "System Source" });

            var configSource = Container.Resolve<ConfigurationSourceModel>();
            configSourceSectionViewModel = configSource.AddSection(ConfigurationSourceSection.SectionName, section);
        }
		public ConfigurationSourceSection Build()
		{
			ConfigurationSourceSection section = new ConfigurationSourceSection();
			section.SelectedSource = configurationSourceSectionNode.SelectedSource.Name;
			for (int index = 0; index < configurationSourceSectionNode.Nodes.Count; ++index)
			{
				ConfigurationSourceElementNode sourceNode = (ConfigurationSourceElementNode)configurationSourceSectionNode.Nodes[index];
				section.Sources.Add(sourceNode.ConfigurationSourceElement);
			}
			return section;  
		}
        private Dictionary <string, string> GetSectionRedirectTable()
        {
            ConfigurationSourceSection sourcesSection = mainConfigurationSource.GetSection(ConfigurationSourceSection.SectionName) as ConfigurationSourceSection;

            if (sourcesSection != null)
            {
                return(sourcesSection.RedirectedSections.ToDictionary(x => x.Name, x => x.SourceName));
            }

            return(new Dictionary <string, string>());
        }
        private static string GetParentConfigurationSourceName(IConfigurationSource source)
        {
            ConfigurationSourceSection configurationSourcesSection = source.GetSection(ConfigurationSourceSection.SectionName) as ConfigurationSourceSection;

            if (configurationSourcesSection != null && !string.IsNullOrEmpty(configurationSourcesSection.ParentSource))
            {
                return(configurationSourcesSection.ParentSource);
            }

            return(null);
        }
        protected override void Arrange()
        {
            base.Arrange();

            Mock<AssemblyLocator> assemblyLocator = new Mock<AssemblyLocator>();
            assemblyLocator.Setup(x => x.Assemblies).Returns(new Assembly[] { typeof(ManageableConfigurationSourceElement).Assembly });
            this.Container.RegisterType<ManageableConfigurationSourceViewModel>(
                new InjectionConstructor(
                    typeof(ElementCollectionViewModel),
                    typeof(ConfigurationElement),
                    new InjectionParameter<AssemblyLocator>(assemblyLocator.Object)));

            targetFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "manageableSourcetextnp.config");
            File.Create(targetFilePath).Dispose();
            File.WriteAllText(targetFilePath, "<configuration/>");

            var source = new DesignConfigurationSource(targetFilePath);

            ConfigurationSourceElement =
                new ManageableConfigurationSourceElement
                {
                    Name = "manageable",
                    FilePath = "file.config",
                    ConfigurationManageabilityProviders = 
                    {
                        new ConfigurationSectionManageabilityProviderData
                        {
                            Name = "provider",
                            TypeName = typeof(object).AssemblyQualifiedName
                        }
                    }
                };
            var section =
                new ConfigurationSourceSection
                {
                    SelectedSource = "manageable",
                    Sources =
                    {
                        ConfigurationSourceElement
                    }
                };

            source.AddLocalSection(ConfigurationSourceSection.SectionName, section);


            var sourceModel = this.Container.Resolve<ConfigurationSourceModel>();
            sourceModel.Load(source);

            SectionViewModel =
                sourceModel.Sections.Where(x => x.ConfigurationType == typeof(ConfigurationSourceSection)).Single();

            ConfigurationSourceViewModel = SectionViewModel.GetDescendentsOfType<ManageableConfigurationSourceElement>().FirstOrDefault();
            ConfigurationSourceElement = (ManageableConfigurationSourceElement)ConfigurationSourceViewModel.ConfigurationElement;
        }
        protected override void Arrange()
        {
            base.Arrange();

            ConfigurationSourceSection sourcesSection = new ConfigurationSourceSection
            {
                SelectedSource = "selected",
                ParentSource = "parent",
                Sources = { { new FileConfigurationSourceElement { Name = "selected" } }, { new FileConfigurationSourceElement { Name = "parent" } } }
            };

            ConfigurationSourceModel sourceModel = Container.Resolve<ConfigurationSourceModel>();
            sourceModel.AddSection(ConfigurationSourceSection.SectionName, sourcesSection);

            SourcesSectionViewModel = sourceModel.Sections.Where(x => x.SectionName == ConfigurationSourceSection.SectionName).Single();
        }
        protected ConfigurationSourceSection CreateConfigurationSourceSection()
        {
            ConfigurationSourceSection configurationSourcesSection = new ConfigurationSourceSection();
            configurationSourcesSection.Sources.Add(new TestConfigurationSourceElement("Source1"));
            configurationSourcesSection.Sources.Add(new TestConfigurationSourceElement("Source2"));
            configurationSourcesSection.RedirectedSections.Add(new RedirectedSectionElement
            {
                Name = "sectionInChild1",
                SourceName = "Source1"
            });
            configurationSourcesSection.RedirectedSections.Add(new RedirectedSectionElement
            {
                Name = "SectionInSource2",
                SourceName = "Source2"
            });

            return configurationSourcesSection;
        }
        public static IConfigurationSource Create()
        {
            ConfigurationSourceSection configurationSourceSection
                = ConfigurationSourceSection.GetConfigurationSourceSection();

            if (configurationSourceSection != null)
            {
                string systemSourceName = configurationSourceSection.SelectedSource;
                if (!string.IsNullOrEmpty(systemSourceName))
                {
                    return(Create(systemSourceName));
                }
                else
                {
                    throw new ConfigurationErrorsException(Resources.ExceptionSystemSourceNotDefined);
                }
            }
            return(new SystemConfigurationSource());
        }
        private IConfigurationSource CreateSubordinateSource(string sourceName, bool throwWhenNotFound)
        {
            EnsureInitialized();

            ConfigurationSourceSection configurationSourcesSection = configurationSource.GetSection(ConfigurationSourceSection.SectionName) as ConfigurationSourceSection;

            if (configurationSourcesSection == null)
            {
                return(null);
            }
            else
            {
                var configurationSourceElement = configurationSourcesSection.Sources
                                                 .Where(x => x.Name == sourceName)
                                                 .FirstOrDefault();

                if (configurationSourceElement == null)
                {
                    if (throwWhenNotFound)
                    {
                        string message = string.Format(CultureInfo.CurrentCulture,
                                                       Resources.ExceptionConfigurationSourceNotFound,
                                                       sourceName,
                                                       ConfigurationSourceSection.SectionName);

                        throw new ConfigurationSourceErrorsException(message);
                    }
                    else
                    {
                        return(null);
                    }
                }
                IConfigurationSource source = configurationSourceElement.CreateSource();

                SubordinateSource sourceHolder = new SubordinateSource(this, sourceName, source);
                subordinateSourcesByName[sourceName] = sourceHolder;

                return(source);
            }
        }
        private void ChangeSourcesSection()
        {
            var sourcesSection = (ConfigurationSourceSection)RootConfiguration.GetSection(ConfigurationSourceSection.SectionName);

            var newSources = new ConfigurationSourceSection
            {
                ParentSource = sourcesSection.ParentSource,
                SelectedSource = sourcesSection.SelectedSource
            };

            CopyData(sourcesSection.Sources, s => newSources.Sources.Add(s));
            CopyData(sourcesSection.RedirectedSections, r => newSources.RedirectedSections.Add(r));

            newSources.Sources.Get("Second Source").Name = "New Source Name";
            newSources.RedirectedSections.Get(LoggingSettings.SectionName).SourceName = "New Source Name";

            ((FileConfigurationSource) RootConfiguration).Save(ConfigurationSourceSection.SectionName, newSources);
        }
        private static IDesignConfigurationSource GetSelectedConfigSource(ConfigurationSourceSection configSourceSection, IDesignConfigurationSource mainConfigurationSource)
        {
            if (configSourceSection == null) return null;

            var selectedSource =
                configSourceSection.Sources.Where(s => s.Name == configSourceSection.SelectedSource).
                    FirstOrDefault();

            return (selectedSource == null ? null : selectedSource.CreateDesignSource(mainConfigurationSource));
        }
        protected override void Arrange()
        {
            base.Arrange();

            sourceSection = new ConfigurationSourceSection() {ParentSource = "MissingParentSource"};
            var localSource = new TestConfigurationSource();
            localSource.Add(ConfigurationSourceSection.SectionName, sourceSection);
            hierarchicalConfigurationSourceHandler = new HierarchicalConfigurationSourceHandler(localSource);
            localSource.SetHierarchyHandler(hierarchicalConfigurationSourceHandler);
        }
		public ConfigurationSourceSectionNodeBuilder(IServiceProvider serviceProvider, ConfigurationSourceSection configurationSourceSection)
			: base(serviceProvider)
		{
			this.configurationSourceSection = configurationSourceSection;			
		}
        protected virtual ConfigurationSourceSection CreateConfigurationSourceSection()
        {
            ConfigurationSourceSection section = new ConfigurationSourceSection();
            section.Sources.Add(new TestConfigurationSourceElement(SubordinateSource1Name));

            return section;
        }
 protected override void Act()
 {
     section = new ConfigurationSourceSection();
     base.ConfigurationSourceBuilder.AddSection(ConfigurationSourceSection.SectionName,
                                                section);
 }
 private void AddConfigurationSourcesToHierarchy()
 {
     ConfigurationSourceSection section = new ConfigurationSourceSection();
     section.Sources.Add(new SystemConfigurationSourceElement("System"));
     section.Sources.Add(new FileConfigurationSourceElement("File", "app.config"));
     section.SelectedSource = "File";
     ConfigurationSourceSectionNodeBuilder builder = new ConfigurationSourceSectionNodeBuilder(ServiceProvider, section);
     ApplicationNode.AddNode(builder.Build());
 }
 private ConfigurationSourceSection CreateConfigurationSourceSection()
 {
     ConfigurationSourceSection section = new ConfigurationSourceSection();
     section.Sources.Add(new FileConfigurationSourceElement(fileSourceName, filePath));
     return section;
 }