Ejemplo n.º 1
0
        /// <summary>
        /// Parse a JSON formatted string into a message object
        /// </summary>
        /// <param name="msgJson"></param>
        /// <returns></returns>
        public static Message Parse(string msgJson)
        {
            Message message = null;
            try
            {
                List<string> participantIDs = new List<string>();
                List<string> participantNames = new List<string>();
                List<Dictionary<string, string>> attachments = new List<Dictionary<string, string>>();

                JObject jObj = JObject.Parse(msgJson);
                string senderName = jObj.GetValue(JSON_KEY_SENDER_NAME).ToString(),
                 senderID = jObj.GetValue(JSON_KEY_SENDER_ID).ToString(),
                 body = jObj.GetValue(JSON_KEY_BODY).ToString(),
                 threadID = jObj.GetValue(JSON_KEY_THREAD_ID).ToString(),
                 threadName = jObj.GetValue(JSON_KEY_THREAD_NAME).ToString(),
                 location = jObj.GetValue(JSON_KEY_LOCATION).ToString(),
                 messageID = jObj.GetValue(JSON_KEY_MESSAGE_ID).ToString(),
                 timestamp = jObj.GetValue(JSON_KEY_TIMESTAMP).ToString();

                JArray jArrayParticipantID = (JArray)jObj.GetValue(JSON_KEY_PARTICIPANT_IDS);
                foreach(string id in jArrayParticipantID)
                {
                    participantIDs.Add(id);
                }

                JArray jArrayParticipantName = (JArray)jObj.GetValue(JSON_KEY_PARTICIPANT_NAMES);
                foreach (string name in jArrayParticipantID)
                {
                    participantNames.Add(name);
                }

                JArray jArrayAttachments = (JArray)jObj.GetValue(JSON_KEY_ATTACHMENT);
                attachments = Attachment.Parse(jArrayAttachments.ToString());

                message = new Message(senderName, senderID,participantNames,participantIDs,body,
                    threadID,threadName, location, messageID, attachments, long.Parse(timestamp));
            }
            catch (Exception ex)
            {
                throw new FacebookChatApiException(ex.Message);
            }

            return message;
        }
Ejemplo n.º 2
0
 internal MessageReceivedEventArgs(Message message)
 {
     Message = message;
 }