Ejemplo n.º 1
0
        protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
        {
            PNMessageActionsResult pnMessageActionsResult = new PNMessageActionsResult();
            PNStatus pnStatus = new PNStatus();

            try{
                Dictionary <string, object> dictionary = deSerializedResult as Dictionary <string, object>;

                if (dictionary != null)
                {
                    object objData;
                    dictionary.TryGetValue("data", out objData);
                    if (objData != null)
                    {
                        Dictionary <string, object> objDataDict = objData as Dictionary <string, object>;
                        if (objDataDict != null)
                        {
                            pnMessageActionsResult = MessageActionsHelpers.ExtractMessageAction(objDataDict);
                        }
                        else
                        {
                            pnMessageActionsResult = null;
                            pnStatus = base.CreateErrorResponseFromException(new PubNubException("objDataDict null"), requestState, PNStatusCategory.PNUnknownCategory);
                        }
                    }
                    else
                    {
                        pnMessageActionsResult = null;
                        pnStatus = base.CreateErrorResponseFromException(new PubNubException("objData null"), requestState, PNStatusCategory.PNUnknownCategory);
                    }
                }
                #if (ENABLE_PUBNUB_LOGGING)
                else
                {
                    this.PubNubInstance.PNLog.WriteToLog("dictionary null", PNLoggingMethod.LevelInfo);
                }
                #endif
            } catch (Exception ex) {
                pnMessageActionsResult = null;
                pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory);
            }
            Callback(pnMessageActionsResult, pnStatus);
        }
        protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
        {
            PNGetMessageActionsResult pnGetMessageActionsResult = new PNGetMessageActionsResult();

            pnGetMessageActionsResult.Data = new List <PNMessageActionsResult>();
            pnGetMessageActionsResult.More = new PNGetMessageActionsMore();
            PNStatus pnStatus = new PNStatus();

            try{
                Dictionary <string, object> dictionary = deSerializedResult as Dictionary <string, object>;

                if (dictionary != null)
                {
                    object objData;
                    dictionary.TryGetValue("data", out objData);
                    if (objData != null)
                    {
                        object[] objArr = objData as object[];
                        foreach (object data in objArr)
                        {
                            Dictionary <string, object> objDataDict = data as Dictionary <string, object>;
                            if (objDataDict != null)
                            {
                                PNMessageActionsResult pnMessageActionsResult = MessageActionsHelpers.ExtractMessageAction(objDataDict);
                                pnGetMessageActionsResult.Data.Add(pnMessageActionsResult);
                            }
                            else
                            {
                                pnStatus = base.CreateErrorResponseFromException(new PubNubException("objDataDict null"), requestState, PNStatusCategory.PNUnknownCategory);
                            }
                        }
                    }
                    else
                    {
                        pnStatus = base.CreateErrorResponseFromException(new PubNubException("objData null"), requestState, PNStatusCategory.PNUnknownCategory);
                    }
                    object objMore;
                    dictionary.TryGetValue("more", out objMore);
                    if (objMore != null)
                    {
                        Dictionary <string, object> objMoreDict = objMore as Dictionary <string, object>;
                        string log;
                        long   start;
                        Utility.TryCheckKeyAndParseLong(objMoreDict, "start", "start", out log, out start);
                        pnGetMessageActionsResult.More.Start = start;

                        int limit;
                        Utility.TryCheckKeyAndParseInt(objMoreDict, "limit", "limit", out log, out limit);
                        pnGetMessageActionsResult.More.Limit = limit;

                        long end;
                        Utility.TryCheckKeyAndParseLong(objMoreDict, "end", "end", out log, out end);
                        pnGetMessageActionsResult.More.End = start;

                        pnGetMessageActionsResult.More.URL = Utility.ReadMessageFromResponseDictionary(objMoreDict, "url");
                    }
                }
            } catch (Exception ex) {
                pnGetMessageActionsResult = null;
                pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory);
            }
            Callback(pnGetMessageActionsResult, pnStatus);
        }