コード例 #1
0
        internal static PNHistoryResult GetObject(List <object> listObject)
        {
            PNHistoryResult ack = new PNHistoryResult();

            if (listObject == null || listObject.Count == 0)
            {
                return(ack);
            }

            long historyStartTime;
            long historyEndTime;

            if (listObject.Count >= 2 && Int64.TryParse(listObject[1].ToString(), out historyStartTime))
            {
                ack.StartTimeToken = historyStartTime;
            }
            if (listObject.Count >= 2 && Int64.TryParse(listObject[2].ToString(), out historyEndTime))
            {
                ack.EndTimeToken = historyEndTime;
            }
            List <object> messagesContainer = listObject[0] as List <object>;

            if (messagesContainer == null)
            {
                object[] messagesCollection = listObject[0] as object[];
                if (messagesCollection != null && messagesCollection.Length > 0)
                {
                    messagesContainer = messagesCollection.ToList();
                }
            }
            if (messagesContainer != null)
            {
                ack.Messages = new List <PNHistoryItemResult>();
                foreach (var message in messagesContainer)
                {
                    PNHistoryItemResult         result = new PNHistoryItemResult();
                    Dictionary <string, object> dicMessageTimetoken = JsonDataParseInternalUtil.ConvertToDictionaryObject(message);
                    if (dicMessageTimetoken != null)
                    {
                        if (dicMessageTimetoken.ContainsKey("message") &&
                            (dicMessageTimetoken.ContainsKey("timetoken") || dicMessageTimetoken.ContainsKey("meta")))
                        {
                            result.Entry = dicMessageTimetoken["message"];

                            long messageTimetoken;
                            if (dicMessageTimetoken.ContainsKey("timetoken") && Int64.TryParse(dicMessageTimetoken["timetoken"].ToString(), out messageTimetoken))
                            {
                                result.Timetoken = messageTimetoken;
                            }

                            if (dicMessageTimetoken.ContainsKey("meta"))
                            {
                                result.Meta = dicMessageTimetoken["meta"];
                            }
                        }
                        else
                        {
                            result.Entry = dicMessageTimetoken;
                        }
                    }
                    else
                    {
                        result.Entry = message;
                    }

                    ack.Messages.Add(result);
                }
            }

            return(ack);
        }
コード例 #2
0
        internal static PNFetchHistoryResult GetObject(List <object> listObject)
        {
            PNFetchHistoryResult ack = new PNFetchHistoryResult();

            Dictionary <string, List <object> > channelMessagesContainer = null;

            for (int index = 0; index < listObject.Count; index++)
            {
                if (listObject[index].GetType() == typeof(List <object>))
                {
                    List <object> channelMessagesList = listObject[index] as List <object>;
                    if (channelMessagesList.Count >= 1)
                    {
                        channelMessagesContainer = channelMessagesList[0] as Dictionary <string, List <object> >;
                    }
                    if (channelMessagesContainer != null)
                    {
                        ack.Messages = new Dictionary <string, List <PNHistoryItemResult> >();
                        foreach (var channelKVP in channelMessagesContainer)
                        {
                            string channel = channelKVP.Key;
                            List <PNHistoryItemResult> resultList = new List <PNHistoryItemResult>();
                            object[] channelValArray = channelKVP.Value != null?JsonDataParseInternalUtil.ConvertToObjectArray(channelKVP.Value) : new object[0];

                            foreach (object msgContainerObj in channelValArray)
                            {
                                Dictionary <string, object> messagesContainer = JsonDataParseInternalUtil.ConvertToDictionaryObject(msgContainerObj);
                                if (messagesContainer != null)
                                {
                                    PNHistoryItemResult result = new PNHistoryItemResult();
                                    if (messagesContainer.ContainsKey("message") &&
                                        (messagesContainer.ContainsKey("timetoken") || messagesContainer.ContainsKey("meta") || messagesContainer.ContainsKey("actions")))
                                    {
                                        result.Entry = messagesContainer["message"];

                                        long messageTimetoken;
                                        if (messagesContainer.ContainsKey("timetoken") && Int64.TryParse(messagesContainer["timetoken"].ToString(), out messageTimetoken))
                                        {
                                            result.Timetoken = messageTimetoken;
                                        }

                                        if (messagesContainer.ContainsKey("meta"))
                                        {
                                            result.Meta = messagesContainer["meta"];
                                        }

                                        if (messagesContainer.ContainsKey("actions"))
                                        {
                                            result.Actions = messagesContainer["actions"];
                                        }
                                    }
                                    resultList.Add(result);
                                }
                            }
                            ack.Messages.Add(channel, resultList);
                        }
                    }
                }
                else if (listObject[index].GetType() == typeof(Dictionary <string, object>))
                {
                    Dictionary <string, object> moreContainer = listObject[index] as Dictionary <string, object>;
                    if (moreContainer != null && moreContainer.ContainsKey("more"))
                    {
                        Dictionary <string, object> moreDic = moreContainer["more"] as Dictionary <string, object>;
                        if (moreDic != null)
                        {
                            ack.More = new PNFetchHistoryResult.MoreInfo();
                            if (moreDic.ContainsKey("start"))
                            {
                                long moreStart;
                                if (moreDic.ContainsKey("start") && Int64.TryParse(moreDic["start"].ToString(), out moreStart))
                                {
                                    ack.More.Start = moreStart;
                                }

                                long moreEnd;
                                if (moreDic.ContainsKey("end") && Int64.TryParse(moreDic["end"].ToString(), out moreEnd))
                                {
                                    ack.More.End = moreEnd;
                                }

                                int moreMax;
                                if (moreDic.ContainsKey("max") && Int32.TryParse(moreDic["max"].ToString(), out moreMax))
                                {
                                    ack.More.Max = moreMax;
                                }
                            }
                        }
                    }
                }
            }

            return(ack);
        }