コード例 #1
0
        /// <summary>
        /// Render messages tag.
        /// </summary>
        /// <returns></returns>
        public StringBuilder RenderMessages()
        {
            StringBuilder output = new StringBuilder();

            var messageStore = FeedbackMessageStore.Current;

            foreach (var messages in messageStore.Messages)
            {
                if (messages.Value.Count == 0)
                {
                    continue;
                }

                FeedbackMessageAttributeCollection outerAttrs;
                if (PerLevelOuterTagAttributes.ContainsKey(messages.Key))
                {
                    outerAttrs = OuterTagAttributes.Merge(PerLevelOuterTagAttributes[messages.Key]);
                }
                else
                {
                    outerAttrs = new FeedbackMessageAttributeCollection(OuterTagAttributes);
                }

                outerAttrs.AppendAttribute("class", $"feedback-{ messages.Key.ToString().ToLower() }");


                FeedbackMessageAttributeCollection innerAttrs;
                if (PerLevelInnerTagAttributes.ContainsKey(messages.Key))
                {
                    innerAttrs = InnerTagAttributes.Merge(PerLevelInnerTagAttributes[messages.Key]);
                }
                else
                {
                    innerAttrs = new FeedbackMessageAttributeCollection(InnerTagAttributes);
                }


                output.Append($"<{OuterTagName} {outerAttrs.Build().ToString()}>");

                foreach (var msg in messages.Value)
                {
                    output.Append($"<{InnerTagName} {innerAttrs.Build().ToString()}>");

                    string message = StringConverter.Convert(msg);
                    output.Append(EscapeMessage ? System.Web.HttpUtility.HtmlEncode(message) : message);
                    output.Append($"</{InnerTagName}>");
                    msg.MarkRendered();
                }

                output.Append($"</{OuterTagName}>");
            }

            return(output);
        }
コード例 #2
0
        /// <summary>
        /// Appends attribute value to inner tag.
        /// </summary>
        /// <param name="level"></param>
        /// <param name="key"></param>
        /// <param name="attrValue"></param>
        /// <returns></returns>
        public FeedbackMessageRenderer AppendInnerAttributeValue(FeedbackMessageLevel level, string key, string attrValue)
        {
            FeedbackMessageAttributeCollection attrCollection;

            if (PerLevelInnerTagAttributes.ContainsKey(level))
            {
                attrCollection = PerLevelInnerTagAttributes[level];
            }
            else
            {
                attrCollection = new FeedbackMessageAttributeCollection();
                PerLevelInnerTagAttributes[level] = attrCollection;
            }

            attrCollection.AppendAttribute(key, attrValue);
            return(this);
        }