Пример #1
0
        /// <summary>Initializes a new instance of the <see cref="EmailValidator"/> class.</summary>
        /// <param name="name">The name for the validator.</param>
        /// <param name="messageTemplate">The template to use when logging validation results, or null we the default message template is to be used.</param>
        /// <param name="tag">The tag to set when logging validation results, or null.</param>
        /// <param name="negated">Indicates if the validation logic represented by the validator should be negated.</param>
        public EmailValidator(string name, string messageTemplate, string tag, bool negated)
            : base(messageTemplate, tag, negated)
        {
            this.Name     = name;
            this.Category = EmailCategory.Basic;

            if (ConfiguredValues != null && ConfiguredValues.Count > 0)
            {
                ConfiguredValuesContainer container = null;
                if (ConfiguredValues.ContainsKey(this.Name))
                {
                    container = ConfiguredValues[this.Name];
                }
                else if (ConfiguredValues.ContainsKey(DefaultName))
                {
                    container = ConfiguredValues[DefaultName];
                }

                if (container != null)
                {
                    this.AllowComments         = container.AllowComments;
                    this.AllowIPAddresses      = container.AllowIPAddresses;
                    this.RequireTopLevelDomain = container.RequireTopLevelDomain;
                    this.IncludeDomains        = container.IncludeDomains;
                    this.ExcludeDomains        = container.ExcludeDomains;
                }
            }
        }
Пример #2
0
        /// <summary>Initializes the properties with the values from the configuration.</summary>
        private void LoadConfiguration()
        {
            if (ConfiguredValues != null && ConfiguredValues.Count > 0)
            {
                ConfiguredValuesContainer container = null;
                if (ConfiguredValues.ContainsKey(this.Name))
                {
                    container = ConfiguredValues[this.Name];
                }
                else if (ConfiguredValues.ContainsKey(DefaultName))
                {
                    container = ConfiguredValues[DefaultName];
                }

                if (container != null)
                {
                    this.AllowCountryCallingCode = container.AllowCountryCallingCode;
                    this.AllowCarrierPreselect   = container.AllowCarrierPreselect;
                    if (container.AreaCodesOverridden)
                    {
                        this.IncludeAreaCodes = container.AreaCodes;
                    }
                }
            }
        }
Пример #3
0
        /// <summary>Initializes a new instance of the <see cref="DutchPhoneNumberValidator"/> class.</summary>
        /// <param name="name">The name for the validator.</param>
        /// <param name="messageTemplate">The template to use when logging validation results, or null we the default message template is to be used.</param>
        /// <param name="tag">The tag to set when logging validation results, or null.</param>
        /// <param name="negated">Indicates if the validation logic represented by the validator should be negated.</param>
        public DutchPhoneNumberValidator(string name, string messageTemplate, string tag, bool negated)
            : base(messageTemplate, tag, negated)
        {
            this.Name       = name;
            this.Categories = PhoneNumberCategories.Default;
            this.AllowCountryCallingCode = true;

            if (ConfiguredValues != null && ConfiguredValues.Count > 0)
            {
                ConfiguredValuesContainer container = null;
                if (ConfiguredValues.ContainsKey(this.Name))
                {
                    container = ConfiguredValues[this.Name];
                }
                else if (ConfiguredValues.ContainsKey(DefaultName))
                {
                    container = ConfiguredValues[DefaultName];
                }

                if (container != null)
                {
                    this.AllowCountryCallingCode = container.AllowCountryCallingCode;
                    this.AllowCarrierPreselect   = container.AllowCarrierPreselect;
                    if (container.AreaCodesOverridden)
                    {
                        this.IncludeAreaCodes = container.AreaCodes;
                    }
                }
            }
        }
Пример #4
0
            /// <summary>Reads the configuration and sets the configured values.</summary>
            /// <param name="sectionName">The name of the config section that must be read. Use <see langword="null"/> or <see cref="string.Empty"/> to use the default section name.</param>
            /// <returns>The values that were read from the configuration or <see langword="null"/> if there was no configuration.</returns>
            private static Dictionary <string, ConfiguredValuesContainer> ReadConfiguration(string sectionName)
            {
                if (string.IsNullOrEmpty(sectionName))
                {
                    sectionName = ValidatorsSection.DefaultSectionName;
                }

                ValidatorsSection validatorsSection = ConfigurationManager.GetSection(sectionName) as ValidatorsSection;

                if (validatorsSection == null || validatorsSection.EmailValidators.Count == 0)
                {
                    return(null);
                }

                Dictionary <string, ConfiguredValuesContainer> configuredValues = new Dictionary <string, ConfiguredValuesContainer>();

                foreach (EmailValidatorConfigElement validatorConfig in validatorsSection.EmailValidators.Values)
                {
                    ConfiguredValuesContainer valuesContainer = new ConfiguredValuesContainer {
                        AllowComments         = validatorConfig.AllowComments,
                        AllowIPAddresses      = validatorConfig.AllowIPAddresses,
                        RequireTopLevelDomain = validatorConfig.RequireTopLevelDomain
                    };

                    List <string> configuredIncludeDomains = new List <string>(validatorConfig.IncludeDomains.Count);
                    foreach (EmailDomainConfigElement domain in validatorConfig.IncludeDomains)
                    {
                        configuredIncludeDomains.Add(domain.Pattern);
                    }

                    List <string> configuredExcludeDomains = new List <string>(validatorConfig.ExcludeDomains.Count);
                    foreach (EmailDomainConfigElement domain in validatorConfig.ExcludeDomains)
                    {
                        configuredExcludeDomains.Add(domain.Pattern);
                    }

                    valuesContainer.IncludeDomains = string.Join(";", configuredIncludeDomains.ToArray());
                    valuesContainer.ExcludeDomains = string.Join(";", configuredExcludeDomains.ToArray());

                    configuredValues.Add(validatorConfig.Name, valuesContainer);
                }

                return(configuredValues);
            }
Пример #5
0
            /// <summary>Reads the configuration and sets the configured values.</summary>
            /// <param name="sectionName">The name of the config section that must be read. Use <see langword="null"/> or <see cref="string.Empty"/> to use the default section name.</param>
            /// <returns>The values that were read from the configuration or <see langword="null"/> if there was no configuration.</returns>
            private static Dictionary <string, ConfiguredValuesContainer> ReadConfiguration(string sectionName)
            {
                if (string.IsNullOrEmpty(sectionName))
                {
                    sectionName = ValidationSection.DefaultSectionName;
                }

                ValidationSection validatorsSection = ConfigurationManager.GetSection(sectionName) as ValidationSection;

                if (validatorsSection == null || validatorsSection.DutchPhoneNumberValidators.Count == 0)
                {
                    return(null);
                }

                Dictionary <string, ConfiguredValuesContainer> configuredValues = new Dictionary <string, ConfiguredValuesContainer>();

                foreach (DutchPhoneNumberValidationConfigElement validatorConfig in validatorsSection.DutchPhoneNumberValidators.Values)
                {
                    List <string> configuredAreaCodes = new List <string>(validatorConfig.AreaCodes.Count);
                    foreach (DutchPhoneNumberAreaCodeConfigElement areaCode in validatorConfig.AreaCodes)
                    {
                        configuredAreaCodes.Add(areaCode.AreaCode.TrimStart('0'));
                    }

                    string[]             defaultAreaCodes = Resources.AreaCodes_NL.Split(';');
                    IEnumerable <string> difference       = defaultAreaCodes.Except(configuredAreaCodes);
                    difference.Concat(configuredAreaCodes.Except(defaultAreaCodes));

                    ConfiguredValuesContainer valuesContainer = new ConfiguredValuesContainer {
                        AllowCountryCallingCode = validatorConfig.AllowCountryCallingCode,
                        AllowCarrierPreselect   = validatorConfig.AllowCarrierPreselect,
                        AreaCodesOverridden     = difference.Any(),
                        AreaCodes = string.Join(";", configuredAreaCodes.ToArray())
                    };
                    configuredValues.Add(validatorConfig.Name, valuesContainer);
                }

                return(configuredValues);
            }
Пример #6
0
        /// <summary>Initializes the properties with the values from the configuration.</summary>
        private void LoadConfiguration()
        {
            if (ConfiguredValues != null && ConfiguredValues.Count > 0)
            {
                ConfiguredValuesContainer container = null;
                if (ConfiguredValues.ContainsKey(this.Name))
                {
                    container = ConfiguredValues[this.Name];
                }
                else if (ConfiguredValues.ContainsKey(DefaultName))
                {
                    container = ConfiguredValues[DefaultName];
                }

                if (container != null)
                {
                    this.AllowComments         = container.AllowComments;
                    this.AllowIPAddresses      = container.AllowIPAddresses;
                    this.RequireTopLevelDomain = container.RequireTopLevelDomain;
                    this.IncludeDomains        = container.IncludeDomains;
                    this.ExcludeDomains        = container.ExcludeDomains;
                }
            }
        }