コード例 #1
0
        /// <summary>
        /// Parses the specified notification text.
        /// </summary>
        /// <param name="textLayout">The text layout.</param>
        /// <returns></returns>
        internal string Parse(string textLayout = null)
        {
            if (String.IsNullOrWhiteSpace(textLayout))
            {
                return(NotificationText);
            }

            if (!textLayout.Contains("{") || NotificationID == 0)
            {
                return(textLayout);
            }

            var pairs = Util.ParseYaml(NotificationText) as YamlMappingNode;

            IDictionary <string, string> parsedDict = GetParsedDictionary(textLayout, pairs);

            foreach (KeyValuePair <YamlNode, YamlNode> pair in pairs)
            {
                m_parser.Parse(m_notification, pair, parsedDict);
            }

            string parsedText = parsedDict.Aggregate(textLayout, (current, pair) =>
                                                     current.Replace("{" + pair.Key + "}", pair.Value.Trim('\'')));

            return(parsedText.Contains("{") ? NotificationText : parsedText);
        }
コード例 #2
0
        /// <summary>
        /// Parses the specified notification text.
        /// </summary>
        /// <param name="textLayout">The text layout.</param>
        /// <returns></returns>
        internal string Parse(string textLayout = null)
        {
            string text = NotificationText;

            if (!string.IsNullOrWhiteSpace(textLayout))
            {
                if (!textLayout.Contains("{") || NotificationID == 0)
                {
                    // If nothing to substitute, leave it alone
                    text = textLayout;
                }
                else
                {
                    var pairs = Util.ParseYaml(NotificationText) as YamlMappingNode;
                    if (pairs != null)
                    {
                        // Substitute the {} placeholders with YAML text
                        var parsedDict = GetParsedDictionary(textLayout, pairs);
                        foreach (var pair in pairs)
                        {
                            m_parser.Parse(m_notification, pair, parsedDict);
                        }
                        string parsedText = parsedDict.Aggregate(textLayout, (current, pair) =>
                                                                 current.Replace("{" + pair.Key + "}", pair.Value.Trim('\'')));
                        text = parsedText.Contains("{") ? NotificationText : parsedText;
                    }
                }
            }
            return(text);
        }