示例#1
0
        public ResponseMessage HandlerRequestMessage(XElement xml)
        {
            var request = new RequestTextMessage(xml);
            var response = new ResponseNewsMessage(request)
            {
                CreateTime = DateTime.Now.Ticks
            };
            var articles = new List<Article>
            {
                new Article{
                    Title = "article 1",
                    Description = "this is book",
                    PicUrl = "http://www.sh-bu.somc",
                    Url = "http://www.sh-bus.com"
                },
                new Article{
                    Title = "article 2",
                    Description = "this is book",
                    PicUrl = "http://www.sh-bu.somc",
                    Url = "http://www.sh-bus.com"
                },
            };

            response.ArticleCount = articles.Count;
            response.Articles = articles;
            return response;
        }
 public ResponseMessage HandlerRequestMessage(XElement xml)
 {
     var request = new RequestTextMessage(xml);
     return new ResponseTextMessage(request)
     {
         CreateTime = DateTime.Now.Ticks,
         Content = s_cnblogsMsg
     };
 }
示例#3
0
        public IMessageHandler MessageRole(XElement xml)
        {
            var request = new RequestTextMessage(xml);
            if (request.Content.IndexOf("博客园") > -1)
            {
                return new CnblogsTextMessageHandler();
            }

            return new DefaultMessageHandler();
        }
示例#4
0
 public ResponseMessage HandlerRequestMessage(XElement xml)
 {
     var request = new RequestTextMessage(xml);
     if (request.Content.IndexOf("info") > -1)
     {
         return new ResponseTextMessage(request)
         {
             Content = "this message has keyword:info"
         };
     }
     else
     {
         return new ResponseTextMessage(request)
         {
             Content = "this message has not keyword"
         };
     }
 }
示例#5
0
文件: Program.cs 项目: jshiying/JCWX
        static void Main(string[] args)
        {
            #region test

            //input info
            var request = new RequestTextMessage
            {
                ToUserName = "******",
                FromUserName = "******",
                MsgId = 123123123L,
                CreateTime = 1231231322L,
                Content = "my request message"
            };

            StringWriter sw = new StringWriter();
            var xmlSerializer = new XmlSerializer(typeof(RequestTextMessage));
            var ns = new XmlSerializerNamespaces();
            ns.Add("", "");
            xmlSerializer.Serialize(sw, request, ns);
            Console.WriteLine(sw.ToString());
            Stream stream = new MemoryStream(sw.Encoding.GetBytes(sw.ToString()));

            //get request message

            #endregion
            var reader = XmlReader.Create(stream);
            var doc = XDocument.Load(reader);
            var xml = doc.Element("xml");
            IMessageRole role = new MyMessageRole();
            IMessageHandler handler = role.MessageRole(xml);
            ResponseMessage response = handler.HandlerRequestMessage(xml);
            if (response != null)
            {
                Console.WriteLine(response.Serializable());
            }
            else
            {
                Console.WriteLine("not handler");
            }
            Console.Read();
        }