Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="content"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public virtual string Fromat(Content content, Message message)
        {
            Dictionary <string, TemplateFormatter> templateValues = content.CreateVariableMaping(message);
            var mapping = new Dictionary <string, string>();

            foreach (string s in NamedFormatters)
            {
                //if couldn't find the Valibel in mapping, it will try to
                //get value by reflact.
                if (!templateValues.ContainsKey(s))
                {
                    PropertyInfo propertyInfo = content.Value.GetType().GetProperty(s);
                    if (propertyInfo != null)
                    {
                        templateValues[s] = new TemplateFormatter {
                            Value = propertyInfo.GetValue(content.Value, null)
                        };
                    }
                }

                mapping.Add(s, templateValues[s].ToString());
            }

            return(NamedFormatterHelper.Replace(TemplateContent, mapping));
        }
Example #2
0
        public void ReplaceTest()
        {
            string formatString = "Hello,[Person], you are a good [job]";
            IDictionary <string, string> replacePattern = new Dictionary <string, string>
            {
                { "Person", "John" },
                { "job", "student" }
            };
            string expected = "Hello,John, you are a good student";
            string actual;

            actual = NamedFormatterHelper.Replace(formatString, replacePattern);
            Assert.AreEqual(expected, actual);
        }
Example #3
0
        public void CollectVariableTest()
        {
            string content  = @"string [a] ok
[b.a]kdjfkdjfkdj [a][b]
[c]isAGood[a]";
            var    expected = new[] { "a", "b.a", "c", "b" };

            string[] actual;
            actual = NamedFormatterHelper.CollectVariable(content);
            Assert.AreEqual(expected.Length, actual.Length);

            for (int idx = 0; idx < actual.Length; idx++)
            {
                int aryIndex = Array.IndexOf(expected, actual[idx]);
                Assert.AreNotEqual(-1, aryIndex, expected[idx] + " isn't in expected array");
            }
        }
Example #4
0
        public virtual void Publish(IMemberShipFactory daoFactory, IDictionary <string, string> variable,
                                    User performers)
        {
            if (daoFactory == null)
            {
                throw new ArgumentNullException("daoFactory");
            }
            if (variable == null)
            {
                throw new ArgumentNullException("variable");
            }
            if (performers == null)
            {
                throw new ArgumentNullException("performers");
            }
            var     helper  = new NamedFormatterHelper();
            Content content = GetContent(performers);

            foreach (string key in NotifySenderManager.Instance.Variables.Keys)
            {
                if (!variable.ContainsKey(key))
                {
                    variable.Add(key, NotifySenderManager.Instance.Variables[key]);
                }
            }

            var simpleMessage = new SimpleMessage(performers)
            {
                Content = new Content
                {
                    Language = content.Language,
                    Subject  = helper.Replace(content.Subject, variable),
                    Value    = helper.Replace(content.Value, variable)
                }
            };

            Type.Send(simpleMessage);
        }