Exemplo n.º 1
0
        public void AddGetAndRemoveASection()
        {
            IConfigurationSource source = ConfigurationSourceFactory.Create("sqlSource");

            Assert.AreEqual(typeof(SqlConfigurationSource), source.GetType());

            DummySection dummySection1 = new DummySection();

            dummySection1.Value = 10;

            source.Add(CreateParameter(), localSection, dummySection1);

            ConfigurationSection newSection = source.GetSection(localSection);

            Assert.AreEqual(typeof(DummySection), newSection.GetType());

            DummySection dummySection2 = newSection as DummySection;

            Assert.AreEqual(dummySection1, dummySection2);

            source.Remove(CreateParameter(), localSection);

            newSection = source.GetSection(localSection);
            Assert.AreEqual(null, newSection);
        }
Exemplo n.º 2
0
        public void TestAddStorage_UsesConfigurationSection()
        {
            MockConfigurationInitializer_MultipleRuntimeStorages initializer = new MockConfigurationInitializer_MultipleRuntimeStorages(source);

            var section = source.GetSection(initializer.Section1);

            Assert.IsInstanceOfType(section, typeof(StorageSettings));
        }
Exemplo n.º 3
0
        public void BuildConfigurationSourceFromHiearchy()
        {
            AddConfigurationSourcesToHierarchy();
            AddInstrumentationToHierarchy();
            IConfigurationSource source = Hierarchy.BuildConfigurationSource();

            Assert.IsNotNull(source.GetSection(InstrumentationConfigurationSection.SectionName));
            Assert.IsNotNull(source.GetSection(ConfigurationSourceSection.SectionName));
        }
        protected override void Arrange()
        {
            base.Arrange();

            Source = new DictionaryConfigurationSource();

            ConfigurationSourceBuilder sourceBuilder = new ConfigurationSourceBuilder();
            sourceBuilder.ConfigureExceptionHandling()
                .GivenPolicyWithName("SomePolicy")
                    .ForExceptionType<Exception>()
                        .ReplaceWith<ApplicationException>()
                        .WrapWith<ArgumentException>()
                        .ThenThrowNewException()
                    .ForExceptionType<ArithmeticException>()
                        .LogToCategory("ArithmicExceptions")
                        .ThenDoNothing()
                .GivenPolicyWithName("Global Policy")
                    .ForExceptionType<Exception>()
                        .ReplaceWith<ApplicationException>()
                        .UsingMessage("replacement message")
                        .WrapWith<Exception>()
                        .ThenNotifyRethrow()
                    .ForExceptionType<InvalidCastException>()
                        .WrapWith<ApplicationException>()
                        .WrapWith<Exception>()
                        .UsingMessage("yes, thats a known bug")
                        .ThenThrowNewException();

            sourceBuilder.UpdateConfigurationWithReplace(Source);

            Section = (ExceptionHandlingSettings)Source.GetSection(ExceptionHandlingSettings.SectionName);
        }
        public static CallHandlerData SerializeAndDeserializeHandler(CallHandlerData handlerData)
        {
            PolicyData policy = new PolicyData("policy");

            policy.Handlers.Add(handlerData);

            PolicyInjectionSettings settings = new PolicyInjectionSettings();

            settings.Policies.Add(policy);

            Dictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections.Add(PolicyInjectionSettings.SectionName, settings);

            IConfigurationSource configurationSource =
                ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            PolicyInjectionSettings deserializedSection =
                configurationSource.GetSection(PolicyInjectionSettings.SectionName) as PolicyInjectionSettings;

            Assert.IsNotNull(deserializedSection);

            PolicyData deserializedPolicy = deserializedSection.Policies.Get(0);

            Assert.IsNotNull(deserializedPolicy);
            return(deserializedPolicy.Handlers.Get(0));
        }
Exemplo n.º 6
0
        public void CanDeserializeSerializedInstanceWithNameAndTargetRuleset()
        {
            MockValidationSettings rwSettings      = new MockValidationSettings();
            ObjectValidatorData    rwValidatorData = new ObjectValidatorData("validator1");

            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.TargetRuleset = "ruleset";

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                MockValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as MockValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(ObjectValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual("ruleset", ((ObjectValidatorData)roSettings.Validators.Get(0)).TargetRuleset);
            }
        }
Exemplo n.º 7
0
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings          rwSettings      = new MockValidationSettings();
            PropertyComparisonValidatorData rwValidatorData = new PropertyComparisonValidatorData("validator1");

            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.ComparisonOperator = ComparisonOperator.GreaterThanEqual;
            rwValidatorData.PropertyToCompare  = "property";
            rwValidatorData.Negated            = true;

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                MockValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as MockValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(PropertyComparisonValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual(ComparisonOperator.GreaterThanEqual, ((PropertyComparisonValidatorData)roSettings.Validators.Get(0)).ComparisonOperator);
                Assert.AreEqual("property", ((PropertyComparisonValidatorData)roSettings.Validators.Get(0)).PropertyToCompare);
                Assert.AreEqual(true, ((PropertyComparisonValidatorData)roSettings.Validators.Get(0)).Negated);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Create the <see cref="PolicySet"/> based on the configuration settings.
        /// </summary>
        /// <param name="context">Builder context.</param>
        /// <param name="name">Name of object to create.</param>
        /// <param name="configurationSource">Configuration source.</param>
        /// <param name="reflectionCache">reflection cache, unused in this method.</param>
        /// <returns>The constructed <see cref="PolicySet"/> object.</returns>
        public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            PolicyInjectionSettings injectionSettings = configurationSource.GetSection(PolicyInjectionSettings.SectionName) as PolicyInjectionSettings;

            if (injectionSettings == null)
            {
                return(new PolicySet());
            }

            PolicySet policySet = new PolicySet();

            foreach (PolicyData policyData in injectionSettings.Policies)
            {
                RuleDrivenPolicy policy = new RuleDrivenPolicy(policyData.Name);

                foreach (CallHandlerData handlerData in policyData.Handlers)
                {
                    ICallHandler callHandler = CallHandlerCustomFactory.Instance.Create(context, handlerData, configurationSource, reflectionCache);
                    policy.Handlers.Add(callHandler);
                }

                foreach (MatchingRuleData matchingRuleData in policyData.MatchingRules)
                {
                    IMatchingRule matchingRule = MatchingRuleCustomFactory.Instance.Create(context, matchingRuleData, configurationSource, reflectionCache);
                    policy.RuleSet.Add(matchingRule);
                }
                policySet.Add(policy);
            }
            return(policySet);
        }
        public void CanDeserializeSerializedConfiguration()
        {
            DatabaseSettings settings = new DatabaseSettings();

            DbProviderMapping mappingData1 = new DbProviderMapping(providerName1, typeof(OracleDatabase));
            DbProviderMapping mappingData2 = new DbProviderMapping(providerName2, typeof(SqlDatabase));

            settings.DefaultDatabase = databaseName1;
            settings.ProviderMappings.Add(mappingData1);
            settings.ProviderMappings.Add(mappingData2);

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[DatabaseSettings.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            DatabaseSettings roSettigs = (DatabaseSettings)configurationSource.GetSection(DatabaseSettings.SectionName);

            Assert.IsNotNull(roSettigs);
            Assert.AreEqual(2, roSettigs.ProviderMappings.Count);
            Assert.AreEqual(databaseName1, roSettigs.DefaultDatabase);

            Assert.IsNotNull(roSettigs.ProviderMappings.Get(providerName1));
            Assert.AreSame(typeof(OracleDatabase), roSettigs.ProviderMappings.Get(providerName1).DatabaseType);
            Assert.AreEqual(providerName1, roSettigs.ProviderMappings.Get(providerName1).DbProviderName);
        }
Exemplo n.º 10
0
        public void CanDeserializeSerializedInstanceWithChildValidators()
        {
            MockValidationSettings    rwSettings      = new MockValidationSettings();
            AndCompositeValidatorData rwValidatorData = new AndCompositeValidatorData("validator1");

            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.Validators.Add(new MockValidatorData("child validator 1", false));
            rwValidatorData.Validators.Add(new MockValidatorData("child validator 2", false));

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                MockValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as MockValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(AndCompositeValidatorData), roSettings.Validators.Get(0).GetType());
                Assert.AreEqual(2, ((AndCompositeValidatorData)roSettings.Validators.Get(0)).Validators.Count);
                Assert.AreEqual("child validator 1", ((AndCompositeValidatorData)roSettings.Validators.Get(0)).Validators.Get(0).Name);
                Assert.AreEqual("child validator 2", ((AndCompositeValidatorData)roSettings.Validators.Get(0)).Validators.Get(1).Name);
            }
        }
Exemplo n.º 11
0
        public void CanDeserializeSerializedConfiguration()
        {
            string name      = "name";
            string filename  = "filename";
            string header    = "header";
            string footer    = "footer";
            string formatter = "formatter";

            TraceListenerData data = new FlatFileTraceListenerData(name, filename, header, footer,
                                                                   formatter, TraceOptions.Callstack);

            LoggingSettings settings = new LoggingSettings();

            settings.TraceListeners.Add(data);

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[LoggingSettings.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            LoggingSettings roSettigs = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName);

            Assert.AreEqual(1, roSettigs.TraceListeners.Count);
            Assert.IsNotNull(roSettigs.TraceListeners.Get(name));
            Assert.AreEqual(TraceOptions.Callstack, roSettigs.TraceListeners.Get(name).TraceOutputOptions);
            Assert.AreSame(typeof(FlatFileTraceListenerData), roSettigs.TraceListeners.Get(name).GetType());
            Assert.AreSame(typeof(FlatFileTraceListenerData), roSettigs.TraceListeners.Get(name).ListenerDataType);
            Assert.AreSame(typeof(FlatFileTraceListener), roSettigs.TraceListeners.Get(name).Type);
            Assert.AreEqual(filename, ((FlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).FileName);
            Assert.AreEqual(footer, ((FlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).Footer);
            Assert.AreEqual(formatter, ((FlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).Formatter);
            Assert.AreEqual(header, ((FlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).Header);
        }
Exemplo n.º 12
0
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            DateTime lowerBound = new DateTime(2006, 1, 1);
            DateTime upperBound = new DateTime(2006, 1, 10);

            MockValidationSettings     rwSettings      = new MockValidationSettings();
            DateTimeRangeValidatorData rwValidatorData = new DateTimeRangeValidatorData("validator1");

            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.LowerBound     = lowerBound;
            rwValidatorData.LowerBoundType = RangeBoundaryType.Exclusive;
            rwValidatorData.UpperBound     = upperBound;
            rwValidatorData.UpperBoundType = RangeBoundaryType.Inclusive;

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                MockValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as MockValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(DateTimeRangeValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual(lowerBound, ((DateTimeRangeValidatorData)roSettings.Validators.Get(0)).LowerBound);
                Assert.AreEqual(RangeBoundaryType.Exclusive, ((DateTimeRangeValidatorData)roSettings.Validators.Get(0)).LowerBoundType);
                Assert.AreEqual(upperBound, ((DateTimeRangeValidatorData)roSettings.Validators.Get(0)).UpperBound);
                Assert.AreEqual(RangeBoundaryType.Inclusive, ((DateTimeRangeValidatorData)roSettings.Validators.Get(0)).UpperBoundType);
            }
        }
        public void CanDeserializeSerializedInstanceWithNameOnly()
        {
            MockValidationSettings rwSettings      = new MockValidationSettings();
            RegexValidatorData     rwValidatorData = new RegexValidatorData("validator1");

            rwSettings.Validators.Add(rwValidatorData);

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                MockValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as MockValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(RegexValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual("", ((RegexValidatorData)roSettings.Validators.Get(0)).Pattern);
                Assert.AreEqual("", ((RegexValidatorData)roSettings.Validators.Get(0)).PatternResourceName);
                Assert.AreEqual(null, ((RegexValidatorData)roSettings.Validators.Get(0)).PatternResourceType);
                Assert.AreEqual(RegexOptions.None, ((RegexValidatorData)roSettings.Validators.Get(0)).Options);
                Assert.AreEqual(false, ((RegexValidatorData)roSettings.Validators.Get(0)).Negated);
            }
        }
        public void CanDeserializeSerializedConfiguration()
        {
            string name           = "name";
            string initData       = "init data";
            string attributeName  = "attribute";
            string attributeValue = "value";

            CustomTraceListenerData data = new CustomTraceListenerData(name, typeof(MockCustomTraceListener), initData, TraceOptions.Callstack);

            data.SetAttributeValue(attributeName, attributeValue);

            LoggingSettings settings = new LoggingSettings();

            settings.TraceListeners.Add(data);

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[LoggingSettings.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            LoggingSettings roSettigs = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName);

            Assert.AreEqual(1, roSettigs.TraceListeners.Count);
            Assert.IsNotNull(roSettigs.TraceListeners.Get(name));
            Assert.AreEqual(TraceOptions.Callstack, ((CustomTraceListenerData)roSettigs.TraceListeners.Get(name)).TraceOutputOptions);
            Assert.AreSame(typeof(CustomTraceListenerData), roSettigs.TraceListeners.Get(name).GetType());
            Assert.AreSame(typeof(CustomTraceListenerData), roSettigs.TraceListeners.Get(name).ListenerDataType);
            Assert.AreSame(typeof(MockCustomTraceListener), roSettigs.TraceListeners.Get(name).Type);
            Assert.AreEqual(attributeValue, ((CustomTraceListenerData)roSettigs.TraceListeners.Get(name)).Attributes[attributeName]);
        }
        public void CanDeserializeSerializedInstanceWithNoChildValidators()
        {
            MockValidationSettings   rwSettings      = new MockValidationSettings();
            OrCompositeValidatorData rwValidatorData = new OrCompositeValidatorData("validator1");

            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.MessageTemplate = "Template";
            rwValidatorData.Tag             = "tag";

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                MockValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as MockValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(OrCompositeValidatorData), roSettings.Validators.Get(0).GetType());
                Assert.AreEqual(0, ((OrCompositeValidatorData)roSettings.Validators.Get(0)).Validators.Count);
                Assert.AreEqual("Template", ((OrCompositeValidatorData)roSettings.Validators.Get(0)).MessageTemplate);
                Assert.AreEqual("tag", ((OrCompositeValidatorData)roSettings.Validators.Get(0)).Tag);
            }
        }
        public void CanDeserializeSerializedConfiguration()
        {
            LoggingSettings rwLoggingSettings = new LoggingSettings();

            rwLoggingSettings.Formatters.Add(new JsonLogFormatterData("jsonFormatter1")
            {
                Formatting = JsonFormatting.Indented
            });
            rwLoggingSettings.Formatters.Add(new JsonLogFormatterData("jsonFormatter2"));

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[LoggingSettings.SectionName] = rwLoggingSettings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            LoggingSettings roLoggingSettings = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName);

            Assert.AreEqual(2, roLoggingSettings.Formatters.Count);
            Assert.IsNotNull(roLoggingSettings.Formatters.Get("jsonFormatter1"));
            Assert.AreEqual(JsonFormatting.Indented, ((JsonLogFormatterData)roLoggingSettings.Formatters.Get("jsonFormatter1")).Formatting);
            Assert.AreSame(typeof(JsonLogFormatterData), roLoggingSettings.Formatters.Get("jsonFormatter1").GetType());
            Assert.AreSame(typeof(JsonLogFormatter), roLoggingSettings.Formatters.Get("jsonFormatter1").Type);
            Assert.IsNotNull(roLoggingSettings.Formatters.Get("jsonFormatter2"));
            Assert.AreEqual(JsonFormatting.None, ((JsonLogFormatterData)roLoggingSettings.Formatters.Get("jsonFormatter2")).Formatting);
            Assert.AreSame(typeof(JsonLogFormatterData), roLoggingSettings.Formatters.Get("jsonFormatter2").GetType());
            Assert.AreSame(typeof(JsonLogFormatter), roLoggingSettings.Formatters.Get("jsonFormatter2").Type);
        }
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings rwSettings      = new MockValidationSettings();
            RegexValidatorData     rwValidatorData = new RegexValidatorData("validator1");

            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.Pattern             = "pattern";
            rwValidatorData.PatternResourceName = RegexResourceName1;
            rwValidatorData.PatternResourceType = typeof(Resources);
            rwValidatorData.Negated             = true;
            rwValidatorData.Options             = RegexOptions.Multiline | RegexOptions.IgnoreCase;

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                MockValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as MockValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(RegexValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual("pattern", ((RegexValidatorData)roSettings.Validators.Get(0)).Pattern);
                Assert.AreEqual(RegexResourceName1, ((RegexValidatorData)roSettings.Validators.Get(0)).PatternResourceName);
                Assert.AreEqual(typeof(Resources), ((RegexValidatorData)roSettings.Validators.Get(0)).PatternResourceType);
                Assert.AreEqual(RegexOptions.Multiline | RegexOptions.IgnoreCase, ((RegexValidatorData)roSettings.Validators.Get(0)).Options);
                Assert.AreEqual(true, ((RegexValidatorData)roSettings.Validators.Get(0)).Negated);
            }
        }
Exemplo n.º 18
0
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings          rwSettings      = new MockValidationSettings();
            ContainsCharactersValidatorData rwValidatorData = new ContainsCharactersValidatorData("validator1");

            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.CharacterSet       = "abc";
            rwValidatorData.ContainsCharacters = ContainsCharacters.All;


            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                MockValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as MockValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(ContainsCharactersValidator), roSettings.Validators.Get(0).Type);
                Assert.AreEqual("abc", ((ContainsCharactersValidatorData)roSettings.Validators.Get(0)).CharacterSet);
                Assert.AreEqual(ContainsCharacters.All, ((ContainsCharactersValidatorData)roSettings.Validators.Get(0)).ContainsCharacters);
            }
        }
Exemplo n.º 19
0
        public void CanDeserializeSerializedConfigurationWithDefaults()
        {
            LoggingSettings rwLoggingSettings = new LoggingSettings();

            rwLoggingSettings.TraceListeners.Add(new MsmqTraceListenerData("listener", CommonUtil.MessageQueuePath, formatterName));

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[LoggingSettings.SectionName] = rwLoggingSettings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            LoggingSettings roLoggingSettings = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName);

            Assert.AreEqual(1, roLoggingSettings.TraceListeners.Count);
            Assert.IsNotNull(roLoggingSettings.TraceListeners.Get("listener"));
            Assert.AreEqual(roLoggingSettings.TraceListeners.Get("listener").GetType(), typeof(MsmqTraceListenerData));

            MsmqTraceListenerData listenerData = roLoggingSettings.TraceListeners.Get("listener") as MsmqTraceListenerData;

            Assert.AreEqual("listener", listenerData.Name);
            Assert.AreEqual(formatterName, listenerData.Formatter);
            Assert.AreEqual(CommonUtil.MessageQueuePath, listenerData.QueuePath);
            Assert.AreEqual(MsmqTraceListenerData.DefaultRecoverable, listenerData.Recoverable);
            Assert.AreEqual(MsmqTraceListenerData.DefaultUseAuthentication, listenerData.UseAuthentication);
            Assert.AreEqual(MsmqTraceListenerData.DefaultUseDeadLetter, listenerData.UseDeadLetterQueue);
            Assert.AreEqual(MsmqTraceListenerData.DefaultUseEncryption, listenerData.UseEncryption);
            Assert.AreEqual(MsmqTraceListenerData.DefaultPriority, listenerData.MessagePriority);
            Assert.AreEqual(MsmqTraceListenerData.DefaultTimeToBeReceived, listenerData.TimeToBeReceived);
            Assert.AreEqual(MsmqTraceListenerData.DefaultTimeToBeReceived, listenerData.TimeToBeReceived);
            Assert.AreEqual(TraceOptions.None, listenerData.TraceOutputOptions);
        }
        /// <summary>
        /// public for unittesting purposes.
        /// </summary>
        /// <param name="configurationSource"></param>
        /// <param name="reconfiguringEventSource"></param>
        /// <returns></returns>
        public static IEnumerable <ITypeRegistrationsProvider> CreateTypeRegistrationsProviderLocators(IConfigurationSource configurationSource, IContainerReconfiguringEventSource reconfiguringEventSource)
        {
            TypeRegistrationProvidersConfigurationSection section = configurationSource.GetSection(TypeRegistrationProvidersConfigurationSection.SectionName) as TypeRegistrationProvidersConfigurationSection;

            if (section == null)
            {
                section = new TypeRegistrationProvidersConfigurationSection();
            }

            foreach (TypeRegistrationProviderElement typeRegistrationProviderElement in section.TypeRegistrationProviders)
            {
                if (!string.IsNullOrEmpty(typeRegistrationProviderElement.SectionName) &&
                    !string.IsNullOrEmpty(typeRegistrationProviderElement.ProviderTypeName))
                {
                    throw new ConfigurationErrorsException(
                              string.Format("Type Registration Provider Settings '{0}' cannot declare both sectionName and providerType attributes",
                                            typeRegistrationProviderElement.Name));
                }
                if (!string.IsNullOrEmpty(typeRegistrationProviderElement.SectionName))
                {
                    yield return(new ConfigSectionLocator(typeRegistrationProviderElement.SectionName, reconfiguringEventSource));
                }
                else if (!string.IsNullOrEmpty(typeRegistrationProviderElement.ProviderTypeName))
                {
                    yield return(new TypeLoadingLocator(typeRegistrationProviderElement.ProviderTypeName, reconfiguringEventSource));
                }
            }
        }
        public void CanDeserializeSerializedConfiguration()
        {
            OracleConnectionSettings rwSettings = new OracleConnectionSettings();

            OracleConnectionData rwOracleConnectionData = new OracleConnectionData();

            rwOracleConnectionData.Name = "name0";
            rwOracleConnectionData.Packages.Add(new OraclePackageData("package1", "pref1"));
            rwOracleConnectionData.Packages.Add(new OraclePackageData("package2", "pref2"));
            rwSettings.OracleConnectionsData.Add(rwOracleConnectionData);
            rwOracleConnectionData      = new OracleConnectionData();
            rwOracleConnectionData.Name = "name1";
            rwOracleConnectionData.Packages.Add(new OraclePackageData("package3", "pref3"));
            rwOracleConnectionData.Packages.Add(new OraclePackageData("package4", "pref4"));
            rwSettings.OracleConnectionsData.Add(rwOracleConnectionData);

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[OracleConnectionSettings.SectionName] = rwSettings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            OracleConnectionSettings roSettings = (OracleConnectionSettings)configurationSource.GetSection(OracleConnectionSettings.SectionName);

            Assert.AreEqual(2, roSettings.OracleConnectionsData.Count);
            Assert.AreEqual("name0", roSettings.OracleConnectionsData.Get(0).Name);
            Assert.AreEqual(2, roSettings.OracleConnectionsData.Get(0).Packages.Count);
        }
Exemplo n.º 22
0
        protected static MatchingRuleData SerializeAndDeserializeMatchingRule(MatchingRuleData typeMatchingRule)
        {
            PolicyData policy = new PolicyData("policy");

            policy.MatchingRules.Add(typeMatchingRule);

            PolicyInjectionSettings settings = new PolicyInjectionSettings();

            settings.Policies.Add(policy);

            Dictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections.Add(PolicyInjectionSettings.SectionName, settings);

            IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            PolicyInjectionSettings deserializedSection = configurationSource.GetSection(PolicyInjectionSettings.SectionName) as PolicyInjectionSettings;

            Assert.IsNotNull(deserializedSection);

            PolicyData deserializedPolicy = deserializedSection.Policies.Get(0);

            Assert.IsNotNull(deserializedPolicy);

            return(deserializedPolicy.MatchingRules.Get(0));
        }
        protected override void AddElementAdministrativeTemplateParts(AdmContentBuilder contentBuilder,
                                                                      FormattedDatabaseTraceListenerData configurationObject,
                                                                      IConfigurationSource configurationSource,
                                                                      String elementPolicyKeyName)
        {
            List <AdmDropDownListItem> connectionStrings = new List <AdmDropDownListItem>();
            ConnectionStringsSection   connectionStringsSection
                = (ConnectionStringsSection)configurationSource.GetSection("connectionStrings");

            if (connectionStringsSection != null)
            {
                foreach (ConnectionStringSettings connectionString in connectionStringsSection.ConnectionStrings)
                {
                    connectionStrings.Add(new AdmDropDownListItem(connectionString.Name, connectionString.Name));
                }
            }
            contentBuilder.AddDropDownListPart(Resources.DatabaseTraceListenerDatabasePartName,
                                               DatabaseInstanceNamePropertyName,
                                               connectionStrings,
                                               configurationObject.DatabaseInstanceName);
            contentBuilder.AddEditTextPart(Resources.DatabaseTraceListenerWriteStoreProcPartName,
                                           WriteLogStoredProcNamePropertyName,
                                           configurationObject.WriteLogStoredProcName,
                                           512,
                                           true);
            contentBuilder.AddEditTextPart(Resources.DatabaseTraceListenerAddCategoryStoreProcPartName,
                                           AddCategoryStoredProcNamePropertyName,
                                           configurationObject.AddCategoryStoredProcName,
                                           512,
                                           false);
            AddTraceOptionsPart(contentBuilder, configurationObject.TraceOutputOptions);
            AddFilterPart(contentBuilder, configurationObject.Filter);
            AddFormattersPart(contentBuilder, configurationObject.Formatter, configurationSource);
        }
Exemplo n.º 24
0
        public void CanDeserializeSerializedConfigurationWithDefaults()
        {
            LoggingSettings rwLoggingSettings = new LoggingSettings();

            rwLoggingSettings.TraceListeners.Add(
                new RollingFlatFileTraceListenerData(
                    "listener1", "log1.txt", "header", "footer", 10, "yyyy-MM-dd", RollFileExistsBehavior.Increment,
                    RollInterval.Minute, TraceOptions.DateTime, "SimpleTextFormat1"));
            rwLoggingSettings.TraceListeners.Add(
                new RollingFlatFileTraceListenerData(
                    "listener2", "log2.txt", "header", "footer", 10, "yyyy-MM-dd", RollFileExistsBehavior.Increment,
                    RollInterval.Minute, TraceOptions.DateTime, "SimpleTextFormat1"));

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[LoggingSettings.SectionName] = rwLoggingSettings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            LoggingSettings roLoggingSettings = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName);

            Assert.AreEqual(2, roLoggingSettings.TraceListeners.Count);
            Assert.IsNotNull(roLoggingSettings.TraceListeners.Get("listener1"));
            Assert.IsNotNull(roLoggingSettings.TraceListeners.Get("listener2"));
        }
            public static void DoInitializeResources(Resources resources)
            {
                if (HasConfiguration())
                {
                    resources.HookRegistratorPluginNames = new List <string>();

                    IConfigurationSource configurationSource = GetConfiguration();

                    var settings = configurationSource.GetSection(HookRegistratorSettings.SectionName) as HookRegistratorSettings;

                    if (settings == null)
                    {
                        throw new ConfigurationErrorsException(string.Format("Failed to load the configuration section '{0}' from the configuration", HookRegistratorSettings.SectionName));
                    }

                    foreach (HookRegistratorData data in settings.HookRegistratorPlugins)
                    {
                        resources.HookRegistratorPluginNames.Add(data.Name);
                    }
                }
                else
                {
                    resources.HookRegistratorPluginNames = new List <string>();
                }
            }
        public void CanDeserializeSerializedConfiguration()
        {
            LoggingSettings rwLoggingSettings = new LoggingSettings();

            rwLoggingSettings.Formatters.Add(new TextFormatterData("formatter1", "template1"));
            rwLoggingSettings.Formatters.Add(new TextFormatterData("formatter2", "template2"));

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[LoggingSettings.SectionName] = rwLoggingSettings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            LoggingSettings roLoggingSettings = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName);

            Assert.AreEqual(2, roLoggingSettings.Formatters.Count);
            Assert.IsNotNull(roLoggingSettings.Formatters.Get("formatter1"));
            Assert.AreSame(typeof(TextFormatterData), roLoggingSettings.Formatters.Get("formatter1").GetType());
            Assert.AreSame(typeof(TextFormatter), roLoggingSettings.Formatters.Get("formatter1").Type);
            Assert.AreEqual("template1", ((TextFormatterData)roLoggingSettings.Formatters.Get("formatter1")).Template);
            Assert.IsNotNull(roLoggingSettings.Formatters.Get("formatter2"));
            Assert.AreSame(typeof(TextFormatterData), roLoggingSettings.Formatters.Get("formatter2").GetType());
            Assert.AreSame(typeof(TextFormatter), roLoggingSettings.Formatters.Get("formatter2").Type);
            Assert.AreEqual("template2", ((TextFormatterData)roLoggingSettings.Formatters.Get("formatter2")).Template);
        }
        /// <summary>
        /// Checks whether the result of a call to <see cref="IConfigurationSource.GetSection(string)"/> should be merged.<br/>
        /// If the call should be merged, performs the merge behavior and returns the resulting <see cref="ConfigurationSection"/> intance.<br/>
        /// If the call should not be merged returns <paramref name="configurationSection"/>.
        /// </summary>
        /// <param name="sectionName">The name of the section that was retrieved from configuration.</param>
        /// <param name="configurationSection">The section that was retrieved from configuration.</param>
        /// <returns>The resulting <see cref="ConfigurationSection"/> instance.</returns>
        /// <seealso cref="IConfigurationSource.GetSection(string)"/>
        protected override ConfigurationSection DoCheckGetSection(string sectionName, ConfigurationSection configurationSection)
        {
            if (string.IsNullOrEmpty(parentSourceName))
            {
                return(configurationSection);
            }

            IConfigurationSource parentSource = GetSubordinateSource(parentSourceName);

            if (parentSource == null)
            {
                return(configurationSection);
            }

            ConfigurationSection parentSection = parentSource.GetSection(sectionName);

            if (configurationSection == null)
            {
                return(parentSection);
            }

            if (parentSection == null)
            {
                return(configurationSection);
            }

            ConfigurationSection      localSection       = CloneSection(configurationSection);
            ConfigurationSectionMerge configurationMerge = new ConfigurationSectionMerge(parentSection, localSection);

            ConfigurationSection mergedSection = configurationMerge.GetMergedSection();

            EnsurePropagatingSectionChangeEvents(parentSourceName, sectionName);

            return(mergedSection);
        }
Exemplo n.º 28
0
        public void CanDeserializeSerializedInstanceWithValuesSet()
        {
            MockValidationSettings rwSettings      = new MockValidationSettings();
            DomainValidatorData    rwValidatorData = new DomainValidatorData("validator1");

            rwSettings.Validators.Add(rwValidatorData);
            rwValidatorData.Negated = true;
            rwValidatorData.Domain.Add(new DomainConfigurationElement("1"));
            rwValidatorData.Domain.Add(new DomainConfigurationElement("2"));
            rwValidatorData.Domain.Add(new DomainConfigurationElement("3"));

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>();

            sections[ValidationSettings.SectionName] = rwSettings;

            using (ConfigurationFileHelper configurationFileHelper = new ConfigurationFileHelper(sections))
            {
                IConfigurationSource configurationSource = configurationFileHelper.ConfigurationSource;

                MockValidationSettings roSettings = configurationSource.GetSection(ValidationSettings.SectionName) as MockValidationSettings;

                Assert.IsNotNull(roSettings);
                Assert.AreEqual(1, roSettings.Validators.Count);
                Assert.AreEqual("validator1", roSettings.Validators.Get(0).Name);
                Assert.AreSame(typeof(DomainValidator <object>), roSettings.Validators.Get(0).Type);
                Assert.AreEqual(true, ((DomainValidatorData)roSettings.Validators.Get(0)).Negated);
                Assert.AreEqual(3, ((DomainValidatorData)roSettings.Validators.Get(0)).Domain.Count);
            }
        }
        /// <summary>
        /// Checks whether the result of a call to <see cref="IConfigurationSource.GetSection(string)"/> should be deferred to a subordinate source.<br/>
        /// If the call should be deferred, returns the <see cref="ConfigurationSection"/> intance from the approriate source.<br/>
        /// If the call should not be deferred returns <paramref name="configurationSection"/>.
        /// </summary>
        /// <param name="sectionName">The name of the section that was retrieved from configuration.</param>
        /// <param name="configurationSection">The section that was retrieved from configuration.</param>
        /// <returns>The resulting <see cref="ConfigurationSection"/> instance.</returns>
        /// <seealso cref="IConfigurationSource.GetSection(string)"/>
        /// <exception cref="ConfigurationSourceErrorsException">Thrown if a section does not exist in a registered source.</exception>
        protected override ConfigurationSection DoCheckGetSection(string sectionName, ConfigurationSection configurationSection)
        {
            string sourceNameForSection;

            if (!sectionRedirectTable.TryGetValue(sectionName, out sourceNameForSection))
            {
                return(configurationSection);
            }

            //if no source is specified we can return.
            if (string.IsNullOrEmpty(sourceNameForSection))
            {
                return(configurationSection);
            }

            IConfigurationSource subordinateSource = GetSubordinateSource(sourceNameForSection);

            EnsurePropagatingSectionChangeEvents(sourceNameForSection, sectionName);

            var section = subordinateSource.GetSection(sectionName);

            if (section == null)
            {
                throw new ConfigurationSourceErrorsException(
                          string.Format(CultureInfo.CurrentCulture,
                                        Resources.ExceptionRedirectedConfigurationSectionNotFound,
                                        sectionName,
                                        sourceNameForSection));
            }

            return(section);
        }
        /// <summary>
        /// Adds the ADM parts that represent the properties of
        /// a specific instance of the configuration element type managed by the receiver.
        /// </summary>
        /// <param name="contentBuilder">The <see cref="AdmContentBuilder"/> to which the Adm instructions are to be appended.</param>
        /// <param name="configurationObject">The configuration object instance.</param>
        /// <param name="configurationSource">The configuration source from where to get additional configuration
        /// information, if necessary.</param>
        /// <param name="elementPolicyKeyName">The key for the element's policies.</param>
        /// <remarks>
        /// Subclasses managing objects that must not create a policy will likely need to include the elements' keys when creating the parts.
        /// </remarks>
        protected override void AddElementAdministrativeTemplateParts(AdmContentBuilder contentBuilder,
                                                                      DataCacheStorageData configurationObject,
                                                                      IConfigurationSource configurationSource,
                                                                      String elementPolicyKeyName)
        {
            List <AdmDropDownListItem> connectionStrings = new List <AdmDropDownListItem>();
            ConnectionStringsSection   connectionStringsSection
                = (ConnectionStringsSection)configurationSource.GetSection("connectionStrings");

            if (connectionStringsSection != null)
            {
                foreach (ConnectionStringSettings connectionString in connectionStringsSection.ConnectionStrings)
                {
                    connectionStrings.Add(new AdmDropDownListItem(connectionString.Name, connectionString.Name));
                }
            }
            contentBuilder.AddDropDownListPart(Resources.DataCacheStorageDatabaseInstanceNamePartName,
                                               elementPolicyKeyName,
                                               DatabaseInstanceNamePropertyName,
                                               connectionStrings,
                                               configurationObject.DatabaseInstanceName);

            contentBuilder.AddEditTextPart(Resources.DataCacheStoragePartitionNamePartName,
                                           elementPolicyKeyName,
                                           PartitionNamePropertyName,
                                           configurationObject.PartitionName,
                                           255,
                                           true);
        }
Exemplo n.º 31
0
        public void CanDeserializeSerializedConfiguration()
        {
            CustomCacheStorageData customData
                = new CustomCacheStorageData("custom", typeof(MockCustomStorageBackingStore));

            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            CacheManagerSettings settings = new CacheManagerSettings();

            settings.BackingStores.Add(customData);
            settings.CacheManagers.Add(new CacheManagerData("ignore", 0, 0, 0, "custom"));

            IDictionary <string, ConfigurationSection> sections = new Dictionary <string, ConfigurationSection>(1);

            sections[CacheManagerSettings.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            CacheManagerSettings roSettigs = (CacheManagerSettings)configurationSource.GetSection(CacheManagerSettings.SectionName);

            Assert.IsNotNull(roSettigs);
            Assert.AreEqual(1, roSettigs.BackingStores.Count);

            Assert.IsNotNull(roSettigs.BackingStores.Get("custom"));
            Assert.AreSame(typeof(CustomCacheStorageData), roSettigs.BackingStores.Get("custom").GetType());
            Assert.AreEqual("custom", ((CustomCacheStorageData)roSettigs.BackingStores.Get("custom")).Name);
            Assert.AreEqual(typeof(MockCustomStorageBackingStore), ((CustomCacheStorageData)roSettigs.BackingStores.Get("custom")).Type);
            Assert.AreEqual("value1", ((CustomCacheStorageData)roSettigs.BackingStores.Get("custom")).Attributes[MockCustomProviderBase.AttributeKey]);
        }
        /// <summary>
        /// public for unittesting purposes.
        /// </summary>
        /// <param name="configurationSource"></param>
        /// <param name="reconfiguringEventSource"></param>
        /// <returns></returns>
        public static IEnumerable<ITypeRegistrationsProvider> CreateTypeRegistrationsProviderLocators(IConfigurationSource configurationSource, IContainerReconfiguringEventSource reconfiguringEventSource)
        {
            TypeRegistrationProvidersConfigurationSection section = configurationSource.GetSection(TypeRegistrationProvidersConfigurationSection.SectionName) as TypeRegistrationProvidersConfigurationSection;
            if (section == null)
            {
                section = new TypeRegistrationProvidersConfigurationSection();
            }

            foreach (TypeRegistrationProviderElement typeRegistrationProviderElement in section.TypeRegistrationProviders)
            {
                if (!string.IsNullOrEmpty(typeRegistrationProviderElement.SectionName) &&
                    !string.IsNullOrEmpty(typeRegistrationProviderElement.ProviderTypeName))
                {
                    throw new ConfigurationErrorsException(
                        string.Format("Type Registration Provider Settings '{0}' cannot declare both sectionName and providerType attributes",
                        typeRegistrationProviderElement.Name));
                }
                if (!string.IsNullOrEmpty(typeRegistrationProviderElement.SectionName))
                {
                    yield return new ConfigSectionLocator(typeRegistrationProviderElement.SectionName, reconfiguringEventSource);
                }
                else if (!string.IsNullOrEmpty(typeRegistrationProviderElement.ProviderTypeName))
                {
                    yield return new TypeLoadingLocator(typeRegistrationProviderElement.ProviderTypeName, reconfiguringEventSource);
                }
            }
        }
		private InstrumentationConfigurationSection GetConfiguration(IConfigurationSource configurationSource)
		{
			InstrumentationConfigurationSection configurationSection
				= (InstrumentationConfigurationSection)configurationSource.GetSection(InstrumentationConfigurationSection.SectionName);
			if (configurationSection == null) configurationSection
				= new InstrumentationConfigurationSection(false, false, false);

			return configurationSection;
		}
 private InstrumentationConfigurationSection GetConfigurationSection(IConfigurationSource configurationSource)
 {
     InstrumentationConfigurationSection section = (InstrumentationConfigurationSection) configurationSource.GetSection("instrumentationConfiguration");
     if (section == null)
     {
         section = new InstrumentationConfigurationSection(false, false, false);
     }
     return section;
 }
        /// <summary>
        /// Adds to the <paramref name="container"/> the policy definitions available in the corresponding configuration section
        /// in <paramref name="configurationSource"/>, if such a section is available.
        /// </summary>
        /// <param name="container">The container on which the injection policies must be configured.</param>
        /// <param name="configurationSource">The configuration source from where the policy injection settings must be retrieved.</param>
        public static void ConfigureContainer(IUnityContainer container, IConfigurationSource configurationSource)
        {
            Guard.ArgumentNotNull(configurationSource, "configurationSource");

            var section = configurationSource.GetSection(SectionName) as PolicyInjectionSettings;
            if (section != null)
            {
                section.ConfigureContainer(container);
            }
        }
        ///<summary>
        /// Initializes a new instance of the <see cref="OracleDatabaseData"/> class with a connection string and a configuration
        /// source.
        ///</summary>
        ///<param name="connectionStringSettings">The <see cref="ConnectionStringSettings"/> for the represented database.</param>
        ///<param name="configurationSource">The <see cref="IConfigurationSource"/> from which Oracle-specific information 
        /// should be retrieved.</param>
        public OracleDatabaseData(ConnectionStringSettings connectionStringSettings, IConfigurationSource configurationSource)
            : base(connectionStringSettings, configurationSource)
        {
            var settings = (OracleConnectionSettings)
                           configurationSource.GetSection(OracleConnectionSettings.SectionName);

            if (settings != null)
            {
                ConnectionData = settings.OracleConnectionsData.Get(connectionStringSettings.Name);
            }
        }
        public string MapName(string name, IConfigurationSource configSource)
        {
            if (string.IsNullOrEmpty(name))
            {
                TerminologyServiceSettings settings =
                    configSource.GetSection(TerminologyServiceSettings.SectionName) as TerminologyServiceSettings;

                if (settings == null)
                    throw new ApplicationException(TerminologyServiceSettings.SectionName + " configuration section not found");
                name = settings.DefaultProvider;
            }

            Check.Ensure(!string.IsNullOrEmpty(name));
            return name;
        }
 public static AdmContent GenerateAdministrativeTemplateContent(IConfigurationSource configurationSource, string applicationName, IDictionary<string, ConfigurationSectionManageabilityProvider> manageabilityProviders)
 {
     AdmContentBuilder contentBuilder = new AdmContentBuilder();
     contentBuilder.StartCategory(applicationName);
     foreach (KeyValuePair<string, ConfigurationSectionManageabilityProvider> pair in manageabilityProviders)
     {
         ConfigurationSection configurationObject = configurationSource.GetSection(pair.Key);
         if (configurationObject != null)
         {
             pair.Value.AddAdministrativeTemplateDirectives(contentBuilder, configurationObject, configurationSource, applicationName);
         }
     }
     contentBuilder.EndCategory();
     return contentBuilder.GetContent();
 }
        private IEnumerable<TypeRegistration> GetRegistrationsInternal(IConfigurationSource configurationSource,
            Func<ITypeRegistrationsProvider, IConfigurationSource, IEnumerable<TypeRegistration>> registrationsAccessor)
        {
            ITypeRegistrationsProvider provider = null;
            ConfigurationSection section = configurationSource.GetSection(Name);
            if (section != null)
            {
                provider = section as ITypeRegistrationsProvider;
            }

            if (provider != null)
            {
                return registrationsAccessor(provider, configurationSource);
            }
            return Enumerable.Empty<TypeRegistration>();
        }
        ///<summary>
        /// Tries to retrieve the <see cref="ValidationSettings"/> and notifies the provided <see cref="IValidationInstrumentationProvider"/>
        /// if there is a <see cref="ConfigurationErrorsException"/>.  The exception is rethrown.
        ///</summary>
        ///<param name="configurationSource"></param>
        ///<param name="instrumentationProvider"></param>
        ///<returns></returns>
        public static ValidationSettings TryGet(
            IConfigurationSource configurationSource,
            IValidationInstrumentationProvider instrumentationProvider
            )
        {
            if (configurationSource == null) throw new ArgumentNullException("configurationSource");
            if (instrumentationProvider == null) throw new ArgumentNullException("instrumentationProvider");

            try
            {
                return configurationSource.GetSection(ValidationSettings.SectionName) as ValidationSettings;
            }
            catch(ConfigurationErrorsException e)
            {
                instrumentationProvider.NotifyConfigurationFailure(e);
                throw;
            }
        }
        public string MapName(string name, IConfigurationSource configSource)
        {
            if (null == configSource) throw new ArgumentNullException("configSource");

            if (null != name)
            {
                return name;
            }
            
            var settings = configSource.GetSection(LoginProviderSettings.SectionName) as LoginProviderSettings;
                
            if (null == settings)
            {
                throw new ConfigurationErrorsException(string.Format("Could not load configuration section {0}", LoginProviderSettings.SectionName));
            }
                
            return settings.DefaultLoginProviderPlugin;
        }
        public object CreateObject(Microsoft.Practices.ObjectBuilder.IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            TerminologyServiceSettings settings =
                configurationSource.GetSection(TerminologyServiceSettings.SectionName) as TerminologyServiceSettings;

            Check.Assert(settings != null, "settings must not be null.");
            TerminologyServiceData data = settings.TerminologyServiceProviders.Get(name) as TerminologyServiceData;
            if (data == null)
                throw new ConfigurationErrorsException("Unable to find Terminology service provider. " + name);

            Dictionary<string, ICodeSetAccess> codeSetAccessDictionary = new Dictionary<string, ICodeSetAccess>();

            foreach (CodeSetAccessProviderData codeSetAccessProviderData in data.codeSetAccessProviders)
            {
                codeSetAccessDictionary.Add(codeSetAccessProviderData.Name,
                    (ICodeSetAccess)CodeSetAccessProviderCustomFactory.Instance.Create
                    (context, codeSetAccessProviderData, configurationSource, reflectionCache));
            }

            Dictionary<string, ITerminologyAccess> terminologyAccessDictionary = new Dictionary<string, ITerminologyAccess>();

            foreach (TerminologyAccessProviderData terminologyAccessProviderData in data.TerminologyAccessProviders)
            {
                terminologyAccessDictionary.Add(terminologyAccessProviderData.Name,
                    (ITerminologyAccess)TerminologyAccessProviderCustomFactory.Instance.Create
                    (context, terminologyAccessProviderData, configurationSource, reflectionCache));
            }

            ITerminologyService terminologyService = new TerminologyService(terminologyAccessDictionary, codeSetAccessDictionary);

            if (context.Locator != null)
            {
                ILifetimeContainer lifetime = context.Locator.Get<ILifetimeContainer>(typeof(ILifetimeContainer), SearchMode.Local);
                if (lifetime != null)
                {
                    context.Locator.Add(new DependencyResolutionLocatorKey(typeof(ITerminologyServiceProvider), name), terminologyService);
                    lifetime.Add(terminologyService);
                }
            }

            return terminologyService;
        }
        public string MapName(string name, IConfigurationSource configSource)
        {
            if (null == configSource) throw new ArgumentNullException("configSource");

            if (null != name)
            {
                return name;
            }
            else
            {
                UserPermissionDefinitionProviderSettings settings = configSource.GetSection(UserPermissionDefinitionProviderSettings.SectionName) as UserPermissionDefinitionProviderSettings;

                if (null == settings)
                {
                    throw new ConfigurationErrorsException(string.Format("Could not load configuration section {0}", UserPermissionDefinitionProviderSettings.SectionName));
                }

                return settings.DefaultUserPermissionDefinitionProvider;
            }
        }
        public string MapName(string name, IConfigurationSource configSource)
        {
            if (null == configSource) throw new ArgumentNullException("configSource");

            if (null != name)
            {
                return name;
            }
            else
            {
                ApplicationOnlineHandlerSettings settings = configSource.GetSection(ApplicationOnlineHandlerSettings.SectionName) as ApplicationOnlineHandlerSettings;

                if (null == settings)
                {
                    throw new ConfigurationErrorsException(string.Format("Could not load configuration section {0}", ApplicationOnlineHandlerSettings.SectionName));
                }

                return settings.DefaultApplicationOnlineHandler;
            }
        }
        /// <summary>
        /// Create the installer class, reading the categories from a policy set
        /// configured in the given <paramref name="configurationSource"/>.
        /// </summary>
        /// <param name="configurationSource">Configuration source containing the policy set.</param>
        public PerformanceCountersInstaller(IConfigurationSource configurationSource )
        {
            categoryNames = new List<string>();

            PolicyInjectionSettings settings =
                configurationSource.GetSection(PolicyInjectionSettings.SectionName) as PolicyInjectionSettings;

            if( settings != null )
            {
                foreach(PolicyData policyData in settings.Policies)
                {
                    foreach(CallHandlerData handlerData in policyData.Handlers)
                    {
                        PerformanceCounterCallHandlerData perfHandlerData =
                            handlerData as PerformanceCounterCallHandlerData;
                        if(perfHandlerData != null)
                        {
                            categoryNames.Add(perfHandlerData.CategoryName);
                        }
                    }
                }
            }
        }
 public static OracleConnectionSettings GetSettings(IConfigurationSource configurationSource)
 {
     return (configurationSource.GetSection("oracleConnectionSettings") as OracleConnectionSettings);
 }
Exemplo n.º 47
0
 /// <summary>
 /// Gets the <see cref="ExceptionHandlingSettings"/> section in the configuration source.
 /// </summary>
 /// <param name="configurationSource">The <see cref="IConfigurationSource"/> to get the section from.</param>
 /// <returns>The exception handling section.</returns>
 public static ExceptionHandlingSettings GetExceptionHandlingSettings(IConfigurationSource configurationSource)
 {
     return (ExceptionHandlingSettings)configurationSource.GetSection(SectionName);
 }
Exemplo n.º 48
0
 public static DatabaseSettings GetDatabaseSettings(IConfigurationSource configurationSource)
 {
     return (DatabaseSettings) configurationSource.GetSection("dataConfiguration");
 }
Exemplo n.º 49
0
 /// <summary>
 /// Retrieves the <see cref="RetryPolicyConfigurationSettings"/> section from the configuration source.
 /// </summary>
 /// <param name="configurationSource">The configuration source to get the section from.</param>
 /// <returns>The retry policy section.</returns>
 public static RetryPolicyConfigurationSettings GetRetryPolicySettings(IConfigurationSource configurationSource)
 {
     if (configurationSource == null) throw new ArgumentNullException("configurationSource");
     return (RetryPolicyConfigurationSettings)configurationSource.GetSection(SectionName);
 }
 private SectionViewModel GetSection(string sectionName, IConfigurationSource source)
 {
     var configurationSourceModel = Container.Resolve<ConfigurationSourceModel>();
     return configurationSourceModel.AddSection(sectionName, source.GetSection(sectionName));
 }
 protected override TypeRegistrationProvidersConfigurationSection Given(IConfigurationSource source)
 {
     return (TypeRegistrationProvidersConfigurationSection)source.GetSection("addedSectionName");
 }
        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;
        }
Exemplo n.º 53
0
 public static OracleConnectionSettings GetSettings(IConfigurationSource configurationSource) {
     return configurationSource.GetSection(SectionName) as OracleConnectionSettings;
 }
 /// <summary>
 /// Gets the <see cref="ExceptionHandlingSettings"/> section in the configuration source.
 /// </summary>
 /// <param name="configurationSource">The <see cref="IConfigurationSource"/> to get the section from.</param>
 /// <returns>The exception handling section.</returns>
 public static ExceptionHandlingSettings GetExceptionHandlingSettings(IConfigurationSource configurationSource)
 {
     if (configurationSource == null) throw new ArgumentNullException("configurationSource");
     return (ExceptionHandlingSettings)configurationSource.GetSection(SectionName);
 }
Exemplo n.º 55
0
 /// <summary>
 /// Retrieves the <see cref="LoggingSettings"/> section from the configuration source.
 /// </summary>
 /// <param name="configurationSource">The <see cref="IConfigurationSource"/> to get the section from.</param>
 /// <returns>The logging section.</returns>
 public static LoggingSettings GetLoggingSettings(IConfigurationSource configurationSource)
 {
     return (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName);
 }
        ///<summary>
        /// Tries to retrieve the <see cref="ValidationSettings"/>.
        ///</summary>
        ///<param name="configurationSource"></param>
        ///<returns></returns>
        public static ValidationSettings TryGet(IConfigurationSource configurationSource)
        {
            if (configurationSource == null) throw new ArgumentNullException("configurationSource");

            return configurationSource.GetSection(ValidationSettings.SectionName) as ValidationSettings;
        }
        /// <summary>
        /// Retrieve the <see cref="InstrumentationConfigurationSection"/> from the given configuratio source.
        /// If the source is null, or does not contain an instrumentation section, then return a default
        /// section with instrumentation turned off.
        /// </summary>
        /// <param name="configurationSource">Configuration source containing section (or not).</param>
        /// <returns>The configuration section.</returns>
        public static InstrumentationConfigurationSection GetSection(IConfigurationSource configurationSource)
        {
            if (configurationSource != null)
            {
                var section =
                    configurationSource.GetSection(SectionName) as InstrumentationConfigurationSection;
                if (section != null)
                {
                    return section;
                }
            }

            return new InstrumentationConfigurationSection();
        }
		/// <summary>
		/// Retrieves the <see cref="OracleConnectionSettings"/> from the configuration source.
		/// </summary>
		/// <param name="configurationSource">The configuration source to retrieve the configuration from.</param>
		/// <returns>The configuration section, or <see langword="null"/> (<b>Nothing</b> in Visual Basic) 
		/// if not present in the configuration source.</returns>
		public static OracleConnectionSettings GetSettings(IConfigurationSource configurationSource)
		{
		    if (configurationSource == null) throw new ArgumentNullException("configurationSource");

			return configurationSource.GetSection(SectionName) as OracleConnectionSettings;
		}
 protected override TypeRegistrationProvidersConfigurationSection Given(IConfigurationSource source)
 {
     return (TypeRegistrationProvidersConfigurationSection)source.GetSection("clearedAndRedeclared");
 }
Exemplo n.º 60
0
 public static TerminologyServiceSettings GetTerminologyServiceSettings(IConfigurationSource configurationSource)
 {
     return (TerminologyServiceSettings)configurationSource.GetSection(TerminologyServiceSettings.SectionName);
 }