Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 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);
        }
        /// <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");
            }

            if (String.IsNullOrEmpty(name))
            {
                name = "CrosshatchAutoInputProtectionFilterProvider";
            }

            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "Crosshatch Auto-Input Protection Filter Provider");
            }

            base.Initialize(name, config);

            VerificationCodeProviderHelper helper = new VerificationCodeProviderHelper(config);

            opacity     = helper.ParseSingle("opacity", false, .15F);
            randomStyle = helper.ParseBoolean("randomStyle", false, true);
            style       = helper.ParseEnum("style", false, HatchStyle.DiagonalCross);
            colors.AddRange(helper.ParseCollection <Color>("colors", false, true, false, ','));

            if (colors.Count == 0)
            {
                colors.Add(Color.Black);
            }

            // Throw an exception if unrecognized attributes remain
            if (config.Count > 0)
            {
                string attr = config.GetKey(0);

                if (!String.IsNullOrEmpty(attr))
                {
                    throw new Exception(string.Format(System.Globalization.CultureInfo.CurrentUICulture,
                                                      "Resources.Errors.UnrecognizedAttribute", attr));
                }
            }
        }
        /// <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");
            }

            if (String.IsNullOrEmpty(name))
            {
                name = "LineNoiseAutoInputProtectionImageProvider";
            }

            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "Line Noise Auto-Input Protection Image Provider");
            }

            VerificationCodeProviderHelper helper = new VerificationCodeProviderHelper(config);

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

            base.Initialize(name, config);

            // Throw an exception if unrecognized attributes remain
            if (config.Count > 0)
            {
                string attr = config.GetKey(0);

                if (!String.IsNullOrEmpty(attr))
                {
                    throw new ProviderException(string.Format(System.Globalization.CultureInfo.CurrentUICulture,
                                                              "Errors.UnrecognizedAttribute", attr));
                }
            }
        }