/// <summary> /// Creates an <see cref="IBuildInfoModel" /> for the specified <see cref="KeyValuePair{TKey,TValue}" />. /// </summary> /// <param name="htmlHelper"> /// The specified <see cref="HtmlHelper" />. /// </param> /// <param name="parameterContainer"> /// The specified <see cref="IParameterContainer" />. /// </param> /// <param name="captchaPair"> /// The specified <see cref="KeyValuePair{TKey,TValue}" />. /// </param> /// <param name="imgUrl">The specified image url.</param> /// <param name="refreshUrl">The specified refresh url.</param> /// <returns> /// An instance of <see cref="IBuildInfoModel" />. /// </returns> protected virtual IBuildInfoModel CreateBuildInfo(HtmlHelper htmlHelper, IParameterContainer parameterContainer, KeyValuePair <string, ICaptchaValue> captchaPair, string imgUrl, string refreshUrl) { string requiredText = null; string refreshText; string inputText; parameterContainer.TryGet(RefreshTextAttribute, out refreshText, "Refresh"); bool findInputText = parameterContainer.TryGet(InputTextAttribute, out inputText); bool isRequired = parameterContainer.IsContains(IsRequiredAttribute); if (isRequired) { parameterContainer.TryGet(RequiredMessageAttribute, out requiredText, "This is a required field."); } IBuildInfoModel buildInfo; if (parameterContainer.IsContains(MathCaptchaAttribute)) { buildInfo = new MathBuildInfoModel(parameterContainer, TokenParameterName, MathCaptchaAttribute, isRequired, requiredText, refreshText, findInputText ? inputText : "The answer is", htmlHelper, InputElementName, TokenElementName, ImageElementName, imgUrl, refreshUrl, captchaPair.Key); } else { buildInfo = new DefaultBuildInfoModel(parameterContainer, TokenParameterName, requiredText, isRequired, refreshText, findInputText ? inputText : "Input symbols", htmlHelper, InputElementName, ImageElementName, TokenElementName, refreshUrl, imgUrl, captchaPair.Key); } //If it a partial view. if (parameterContainer.IsContains(PartialViewNameAttribute)) { ViewDataDictionary viewData; parameterContainer.TryGet(PartialViewDataAttribute, out viewData); string scriptPartialView; parameterContainer.TryGet(ScriptPartialViewNameAttribute, out scriptPartialView); return(new PartialBuildInfoModel(htmlHelper, buildInfo, parameterContainer.Get <string>(PartialViewNameAttribute), scriptPartialView, viewData)); } return(buildInfo); }
private static ICaptchaManager GetCaptchaManager(IParameterContainer parameterContainer) { int numberOfCaptcha; if (parameterContainer.TryGet(MultipleParameterKey, out numberOfCaptcha)) { return(CaptchaManagers.GetOrAdd(numberOfCaptcha, CreateCaptchaManagerByNumber)); } if (parameterContainer.IsContains(CookieParameterKey)) { return(CookieCaptchaManager); } //If not found parameter return default manager. return(CaptchaUtils.CaptchaManager); }
/// <summary> /// Generates a specified <see cref="KeyValuePair{TKey,TValue}" /> for a captcha. /// </summary> /// <param name="parameterContainer"> /// The specified <see cref="IParameterContainer" />. /// </param> /// <param name="oldValue">The old value if any.</param> /// <returns> /// An instance of <see cref="KeyValuePair{TKey,TValue}" />. /// </returns> protected virtual KeyValuePair <string, ICaptchaValue> CreateCaptchaPair(IParameterContainer parameterContainer, ICaptchaValue oldValue) { if (parameterContainer.IsContains(MathCaptchaAttribute)) { return(MathCaptchaPairFactory()); } int length; if (oldValue != null) { length = oldValue.CaptchaText.Length; } else if (!parameterContainer.TryGet(LengthAttribute, out length)) { throw new ArgumentException("Parameter is not specified for the length of the captcha."); } if (length <= 0) { throw new ArgumentException("The length parameter can not be <= 0."); } return(PlainCaptchaPairFactory(length)); }
/// <summary> /// Determines whether the <see cref="IParameterContainer" /> contains a specific key. /// </summary> /// <param name="key">The specified key.</param> /// <returns> /// <c>True</c> if the value is found in the <see cref="IParameterContainer" />; otherwise, <c>false</c>. /// </returns> public bool IsContains(string key) { return(_firstContainer.IsContains(key) || _secondContainer.IsContains(key)); }