/// <summary>
        /// 初始化
        /// </summary>
        /// <param name="name"></param>
        /// <param name="config"></param>
        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            base.Initialize(name, config);

            VerificationCodeProviderHelper helper = new VerificationCodeProviderHelper(config);

            colors.AddRange(helper.ParseCollection <Color>("colors", false, true, true, ',') ?? new List <Color>(0));

            if (colors.Count == 0)
            {
                throw VerificationCodeProviderHelper.CreateException(null, "Errors.ProviderHelper_Required", "colors");
            }

            IList <string> fontNames = helper.ParseList <string>("fonts", false, true, true, ',');

            if (fontNames == null || fontNames.Count == 0)
            {
                throw VerificationCodeProviderHelper.CreateException(null, "Errors.ProviderHelper_Required", "fonts");
            }

            fonts.Clear();
            fonts.Capacity = fontNames.Count;

            foreach (string fontName in fontNames)
            {
                if (!Array.Exists(FontFamily.Families, delegate(FontFamily family)
                {
                    return(fontName.Equals(family.Name, StringComparison.OrdinalIgnoreCase));
                }))
                {
                    throw VerificationCodeProviderHelper.CreateException(null, "Errors.AIPImageProvider_InvalidFontName", fontName, "fonts");
                }

                fonts.Add(new Font(fontName, 1));
            }

            minFontSize       = helper.ParseInt32("minimumFontSize", false, 20);
            maxFontSize       = helper.ParseInt32("maximumFontSize", false, 30);
            minimumCharacters = helper.ParseInt32("minimumCharacters", false, 4);
            maximumCharacters = helper.ParseInt32("maximumCharacters", false, 6);

            if (maximumCharacters < 1 || maximumCharacters < minimumCharacters)
            {
                throw VerificationCodeProviderHelper.CreateException(null, "Errors.AIPTextProvider_MaxCharactersOutOfRangeConfig");
            }

            if (minimumCharacters < 1)
            {
                throw VerificationCodeProviderHelper.CreateException(null, "Errors.AIPTextProvider_MinCharactersOutOfRangeConfig");
            }

            caseSensitive = helper.ParseBoolean("caseSensitive", false, false);
        }
Beispiel #2
0
        /// <summary>
        /// Loads the provider's settings from the specified <paramref name="config"/>.
        /// </summary>
        /// <exception cref="System.Configuration.Provider.ProviderException">An attribute value cannot be converted into the required type.</exception>
        /// <param name="name">Name of the provider.</param>
        /// <param name="config">A collection of name and value pairs that will be used to initialize the provider.</param>
        public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            base.Initialize(name, config);

            VerificationCodeProviderHelper helper = new VerificationCodeProviderHelper(config);

            margin      = helper.ParseInt32("margin", false, -1);
            minRotation = helper.ParseInt32("minimumCharacterRotation", false, -1);
            maxRotation = helper.ParseInt32("maximumCharacterRotation", false, -1);
        }