private static void InitialImageProviders(bool hasSection, VerificationCodeSection section) { if (hasSection) { //根据给定的Provider类型和提供的节点配置初始化对应的ProviderCollection ProvidersHelper.InstantiateProviders(section.ImageProviders,ImageProviderCollection,typeof(VerificationCodeImageProvider)); if ( section.DefaultImageProvider.Equals( section.ElementInformation.Properties["defaultImageProvider"].DefaultValue)) { if (ImageProviderCollection.Count > 0) imageProvider = ImageProviderCollection[0]; else imageProvider = new LineNoiseVerificationCodeImageProvider(); } else { imageProvider = ImageProviderCollection[section.DefaultImageProvider]; } if(imageProvider == null) throw new InvalidOperationException("验证码图片配置有误"); } else if (imageProvider == null) { section.ImageProviders.Add(CreateProviderSettings(section.DefaultImageProvider,typeof(LineNoiseVerificationCodeImageProvider))); ProvidersHelper.InstantiateProviders(section.ImageProviders,ImageProviderCollection,typeof(VerificationCodeImageProvider)); imageProvider = ImageProviderCollection[section.DefaultImageProvider]; } }
/// <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]; } }