/// <summary> /// 加载TextProvider /// </summary> /// <param name="configHasSection"></param> /// <param name="section"></param> private static void InitializeTextProviders(bool configHasSection, VerificationCodeSection section) { //加载TextProvider 如果webconfig中没有配置 则加载默认的BasicEnglishAutoInputProtectionTextProvider if (configHasSection) { if (!initializedTextProviders) { ProvidersHelper.InstantiateProviders(section.TextProviders, textProviders, typeof(VerificationCodeTextProvider)); initializedTextProviders = true; } if (section.DefaultTextProvider.Equals(section.ElementInformation.Properties["defaultTextProvider"].DefaultValue)) { if (textProviders.Count > 0) { textProvider = textProviders[0]; } else { textProvider = new BasicEnglishVerificationCodeTextProvider( new[] { Color.Black, Color.Red, Color.Brown }, new[] { new Font("Times New Roman", 1), new Font("Arial", 1), new Font("Microsoft Sans Serif", 1) }); } } else { textProvider = textProviders[section.DefaultTextProvider]; } if (textProvider == null) { throw new InvalidOperationException("Errors.Config_Missing_TextProvider"); } } else if (textProvider == null) { section.TextProviders.Add(CreateProviderSettings(section.DefaultTextProvider, typeof(BasicEnglishVerificationCodeTextProvider), new KeyValuePair <string, string>("colors", "Red,Green,Blue,Brown"), new KeyValuePair <string, string>("fonts", "Times New Roman, Arial, Microsoft Sans Serif"))); ProvidersHelper.InstantiateProviders(section.TextProviders, textProviders, typeof(VerificationCodeTextProvider)); textProvider = textProviders[section.DefaultTextProvider]; } }
/// <summary> /// 加载ImageProvider /// </summary> /// <param name="configHasSection"></param> /// <param name="section"></param> private static void InitializeImageProviders(bool configHasSection, VerificationCodeSection section) { //加载ImageProvider 如果webconfig中没有配置 则加载默认的LineNoiseAutoInputProtectionImageProvider if (configHasSection) { if (!initializedImageProviders) { ProvidersHelper.InstantiateProviders(section.ImageProviders, imageProviders, typeof(VerificationCodeImageProvider)); initializedImageProviders = true; } if (section.DefaultImageProvider.Equals(section.ElementInformation.Properties["defaultImageProvider"].DefaultValue)) { if (imageProviders.Count > 0) { imageProvider = imageProviders[0]; } else { imageProvider = new LineNoiseVerificationCodeImageProvider(); } } else { imageProvider = imageProviders[section.DefaultImageProvider]; } if (imageProvider == null) { throw new InvalidOperationException("Errors.Config_Missing_ImageProvider"); } } else if (imageProvider == null) { section.ImageProviders.Add(CreateProviderSettings(section.DefaultImageProvider, typeof(LineNoiseVerificationCodeImageProvider))); ProvidersHelper.InstantiateProviders(section.ImageProviders, imageProviders, typeof(VerificationCodeImageProvider)); imageProvider = imageProviders[section.DefaultImageProvider]; } }
private static void EnsureProviders() { if (!initialized) { VerificationCodeSection section = (VerificationCodeSection)WebConfigurationManager.GetSection("spbVerificationCode/autoInputProtection"); bool hasSection = section != null; if (!hasSection) { section = new VerificationCodeSection(); } //userMode = section.UserMode; PersistenceMode = section.PersistenceMode; InitializeTextProviders(hasSection, section); InitializeImageProviders(hasSection, section); ProviderSettingsCollection pc = new ProviderSettingsCollection(); pc.Add(new ProviderSettings("filters", "Spacebuilder.Common.CrosshatchVerificationCodeFilterProvider,Spacebuilder.Common")); ProvidersHelper.InstantiateProviders(pc, filterProviders, typeof(VerificationCodeFilterProvider)); initialized = true; } }
/// <summary> /// 加载TextProvider /// </summary> /// <param name="configHasSection"></param> /// <param name="section"></param> private static void InitializeTextProviders(bool configHasSection, VerificationCodeSection section) { //加载TextProvider 如果webconfig中没有配置 则加载默认的BasicEnglishAutoInputProtectionTextProvider if (configHasSection) { if (!initializedTextProviders) { ProvidersHelper.InstantiateProviders(section.TextProviders, textProviders, typeof(VerificationCodeTextProvider)); initializedTextProviders = true; } if (section.DefaultTextProvider.Equals(section.ElementInformation.Properties["defaultTextProvider"].DefaultValue)) { if (textProviders.Count > 0) textProvider = textProviders[0]; else textProvider = new BasicEnglishVerificationCodeTextProvider( new[] { Color.Black, Color.Red, Color.Brown }, new[] { new Font("Times New Roman", 1), new Font("Arial", 1), new Font("Microsoft Sans Serif", 1) }); } else textProvider = textProviders[section.DefaultTextProvider]; if (textProvider == null) throw new InvalidOperationException("Errors.Config_Missing_TextProvider"); } else if (textProvider == null) { section.TextProviders.Add(CreateProviderSettings(section.DefaultTextProvider, typeof(BasicEnglishVerificationCodeTextProvider), new KeyValuePair<string, string>("colors", "Red,Green,Blue,Brown"), new KeyValuePair<string, string>("fonts", "Times New Roman, Arial, Microsoft Sans Serif"))); ProvidersHelper.InstantiateProviders(section.TextProviders, textProviders, typeof(VerificationCodeTextProvider)); textProvider = textProviders[section.DefaultTextProvider]; } }
/// <summary> /// 加载ImageProvider /// </summary> /// <param name="configHasSection"></param> /// <param name="section"></param> private static void InitializeImageProviders(bool configHasSection, VerificationCodeSection section) { //加载ImageProvider 如果webconfig中没有配置 则加载默认的LineNoiseAutoInputProtectionImageProvider if (configHasSection) { if (!initializedImageProviders) { ProvidersHelper.InstantiateProviders(section.ImageProviders, imageProviders, typeof(VerificationCodeImageProvider)); initializedImageProviders = true; } if (section.DefaultImageProvider.Equals(section.ElementInformation.Properties["defaultImageProvider"].DefaultValue)) { if (imageProviders.Count > 0) imageProvider = imageProviders[0]; else imageProvider = new LineNoiseVerificationCodeImageProvider(); } else imageProvider = imageProviders[section.DefaultImageProvider]; if (imageProvider == null) throw new InvalidOperationException("Errors.Config_Missing_ImageProvider"); } else if (imageProvider == null) { section.ImageProviders.Add(CreateProviderSettings(section.DefaultImageProvider, typeof(LineNoiseVerificationCodeImageProvider))); ProvidersHelper.InstantiateProviders(section.ImageProviders, imageProviders, typeof(VerificationCodeImageProvider)); imageProvider = imageProviders[section.DefaultImageProvider]; } }
private static void EnsureProviders() { if (!initialized) { VerificationCodeSection section = (VerificationCodeSection)WebConfigurationManager.GetSection("spbVerificationCode/autoInputProtection"); bool hasSection = section != null; if (!hasSection) section = new VerificationCodeSection(); //userMode = section.UserMode; PersistenceMode = section.PersistenceMode; InitializeTextProviders(hasSection, section); InitializeImageProviders(hasSection, section); ProviderSettingsCollection pc = new ProviderSettingsCollection(); pc.Add(new ProviderSettings("filters", "Spacebuilder.Common.CrosshatchVerificationCodeFilterProvider,Spacebuilder.Common")); ProvidersHelper.InstantiateProviders(pc, filterProviders, typeof(VerificationCodeFilterProvider)); initialized = true; } }