Esempio n. 1
0
        private static ReceiveXmlMessage ConvertReceiveXmlToReceiveXmlMessage(string receiveXml)
        {
            Dictionary <string, string> dictionary = XmlHelper.Read(receiveXml);
            string            text = dictionary["MsgType"];
            ReceiveXmlMessage receiveXmlMessage = null;

            if (text.Equals("text"))
            {
                receiveXmlMessage = new ReceiveXmlTextMessage();
            }
            else if (text.Equals("image"))
            {
                receiveXmlMessage = new ReceiveXmlImageMessage();
            }
            else if (text.Equals("voice"))
            {
                receiveXmlMessage = new ReceiveXmlVoiceMessage();
            }
            else if (text.Equals("video"))
            {
                receiveXmlMessage = new ReceiveXmlVideoMessage();
            }
            else if (text.Equals("location"))
            {
                receiveXmlMessage = new ReceiveXmlLocationMessage();
            }
            else if (text.Equals("link"))
            {
                receiveXmlMessage = new ReceiveXmlLinkMessage();
            }
            else if (text.Equals("event"))
            {
                receiveXmlMessage = new ReceiveXmlEventMessage();
            }
            if (receiveXmlMessage != null)
            {
                Type           type       = receiveXmlMessage.GetType();
                PropertyInfo[] properties = type.GetProperties();
                PropertyInfo[] array      = properties;
                for (int i = 0; i < array.Length; i++)
                {
                    PropertyInfo propertyInfo     = array[i];
                    object[]     customAttributes = propertyInfo.GetCustomAttributes(typeof(MessagePropertyNameAttribute), true);
                    if (customAttributes != null && customAttributes.Length > 0)
                    {
                        MessagePropertyNameAttribute messagePropertyNameAttribute = (MessagePropertyNameAttribute)customAttributes[0];
                        if (dictionary.ContainsKey(messagePropertyNameAttribute.PropertyName))
                        {
                            string value = dictionary[messagePropertyNameAttribute.PropertyName];
                            propertyInfo.SetValue(receiveXmlMessage, value, null);
                        }
                    }
                }
                receiveXmlMessage.Xml = receiveXml;
            }
            return(receiveXmlMessage);
        }
Esempio n. 2
0
 private static ReceiveXmlMessage ConvertReceiveXmlToReceiveXmlMessage(string receiveXml)
 {
     Dictionary<string, string> dictionary = XmlHelper.Read(receiveXml);
     string text = dictionary["MsgType"];
     ReceiveXmlMessage receiveXmlMessage = null;
     if (text.Equals("text"))
     {
         receiveXmlMessage = new ReceiveXmlTextMessage();
     }
     else if (text.Equals("image"))
     {
         receiveXmlMessage = new ReceiveXmlImageMessage();
     }
     else if (text.Equals("voice"))
     {
         receiveXmlMessage = new ReceiveXmlVoiceMessage();
     }
     else if (text.Equals("video"))
     {
         receiveXmlMessage = new ReceiveXmlVideoMessage();
     }
     else if (text.Equals("location"))
     {
         receiveXmlMessage = new ReceiveXmlLocationMessage();
     }
     else if (text.Equals("link"))
     {
         receiveXmlMessage = new ReceiveXmlLinkMessage();
     }
     else if (text.Equals("event"))
     {
         receiveXmlMessage = new ReceiveXmlEventMessage();
     }
     if (receiveXmlMessage != null)
     {
         Type type = receiveXmlMessage.GetType();
         PropertyInfo[] properties = type.GetProperties();
         PropertyInfo[] array = properties;
         for (int i = 0; i < array.Length; i++)
         {
             PropertyInfo propertyInfo = array[i];
             object[] customAttributes = propertyInfo.GetCustomAttributes(typeof(MessagePropertyNameAttribute), true);
             if (customAttributes != null && customAttributes.Length > 0)
             {
                 MessagePropertyNameAttribute messagePropertyNameAttribute = (MessagePropertyNameAttribute)customAttributes[0];
                 if (dictionary.ContainsKey(messagePropertyNameAttribute.PropertyName))
                 {
                     string value = dictionary[messagePropertyNameAttribute.PropertyName];
                     propertyInfo.SetValue(receiveXmlMessage, value, null);
                 }
             }
         }
         receiveXmlMessage.Xml = receiveXml;
     }
     return receiveXmlMessage;
 }