コード例 #1
0
        /// <summary>
        /// When implemented in a class, provides metadata to the model metadata creation process.
        /// </summary>
        /// <param name="metadata">The model metadata.</param>
        public void OnMetadataCreated(ModelMetadata metadata)
        {
            const string ATTR = "lenrange";
            var          additionalMetadataValue = new ValidationAttributeMetadata(
                new Dictionary <string, string>
            {
                { "minlen", MinimumLength.ToString(CultureInfo.InvariantCulture) },
                { "maxlen", MaximumLength.ToString(CultureInfo.InvariantCulture) },
            }, ErrorMessageString);

            metadata.AdditionalValues.Add(ATTR, additionalMetadataValue);
        }
コード例 #2
0
 /// <summary>
 ///		Adds the HTML attributes and styles that need to be rendered for the control to the specified <see cref='System.Web.UI.HtmlTextWriter'/> object.
 /// </summary>
 /// <param name="writer">An <see cref='System.Web.UI.HtmlTextWriter'/> that represents the output stream to render HTML content on the client.</param>
 protected override void AddAttributesToRender(HtmlTextWriter writer)
 {
     base.AddAttributesToRender(writer);
     if (RenderUplevel)
     {
         string         id = ClientID;
         HtmlTextWriter expandoAttributeWriter = (EnableLegacyRendering) ? writer : null;
         AddExpandoAttribute(expandoAttributeWriter, id, "evaluationfunction", "LengthValidatorEvaluateIsValid", false);
         AddExpandoAttribute(expandoAttributeWriter, id, "minimumlength", MinimumLength.ToString());
         AddExpandoAttribute(expandoAttributeWriter, id, "minimumerrormessage", MinimumLengthErrorMessage);
         AddExpandoAttribute(expandoAttributeWriter, id, "maximumlength", MaximumLength.ToString());
         AddExpandoAttribute(expandoAttributeWriter, id, "maximumerrormessage", MaximumLengthErrorMessage);
     }
 }
コード例 #3
0
        private void AnalyzeMetaDescriptionAttribute(HtmlAttribute metaDescriptionAttribute)
        {
            var descriptionValue = metaDescriptionAttribute.Value;

            var resultRule = new ResultRule();

            if (string.IsNullOrWhiteSpace(descriptionValue))
            {
                resultRule.Alias = "no_description_value";
                resultRule.Type  = ResultType.Error;
            }
            else
            {
                descriptionValue = descriptionValue.Trim();

                if (descriptionValue.Length > MaximumLength)
                {
                    resultRule.Alias = "description_too_long";
                    resultRule.Type  = ResultType.Warning;
                }

                if (descriptionValue.Length < MinimumLength)
                {
                    resultRule.Alias = "description_too_short";
                    resultRule.Type  = ResultType.Warning;
                }
                else if (descriptionValue.Length < AcceptableLength)
                {
                    resultRule.Alias = "description_shorter_then_acceptable";
                    resultRule.Type  = ResultType.Hint;
                }

                if (descriptionValue.Length <= MaximumLength && descriptionValue.Length >= AcceptableLength)
                {
                    resultRule.Alias = "description_perfect";
                    resultRule.Type  = ResultType.Success;
                }
            }

            resultRule.Tokens.Add(MaximumLength.ToString());        // 0
            resultRule.Tokens.Add(MinimumLength.ToString());        // 1
            resultRule.Tokens.Add(AcceptableLength.ToString());     // 2

            AddResultRule(resultRule);
        }
コード例 #4
0
        private void AnalyzeTitleTag(HtmlNode titleTag)
        {
            var titleValue = titleTag.InnerText;

            var resultRule = new ResultRule();

            if (string.IsNullOrWhiteSpace(titleValue))
            {
                resultRule.Alias = "no_title_value";
                resultRule.Type  = ResultType.Error;
            }
            else
            {
                titleValue = titleValue.Trim();

                if (titleValue.Length > MaximumLength)
                {
                    resultRule.Alias = "title_too_long";
                    resultRule.Type  = ResultType.Warning;
                }

                if (titleValue.Length < MinimumLength)
                {
                    resultRule.Alias = "title_too_short";
                    resultRule.Type  = ResultType.Hint;
                }

                if (titleValue.Length <= MaximumLength && titleValue.Length >= MinimumLength)
                {
                    resultRule.Alias = "title_success";
                    resultRule.Type  = ResultType.Success;
                }
            }

            resultRule.Tokens.Add(MaximumLength.ToString());        // 0
            resultRule.Tokens.Add(MinimumLength.ToString());        // 1

            AddResultRule(resultRule);
        }
コード例 #5
0
 /// <summary>
 /// Applies formatting to a specified error message.
 /// </summary>
 /// <param name="name">The error message to format.</param>
 /// <returns>The formatted error message.</returns>
 public override string FormatErrorMessage(string name)
 {
     return(ErrorMessage.Replace("{0}", MaximumLength.ToString()));
 }