Exemple #1
0
        protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
        {
            PNUserResult pnUserResult = new PNUserResult();
            PNStatus     pnStatus     = new PNStatus();

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

                if (dictionary != null)
                {
                    object objData;
                    if (dictionary.TryGetValue("data", out objData))
                    {
                        Dictionary <string, object> objDataDict = objData as Dictionary <string, object>;
                        if (objDataDict != null)
                        {
                            pnUserResult = ObjectsHelpers.ExtractUser(objDataDict);
                        }
                        else
                        {
                            pnStatus = base.CreateErrorResponseFromException(new PubNubException("objDataDict not present"), requestState, PNStatusCategory.PNUnknownCategory);
                        }
                    }
                    else
                    {
                        pnStatus = base.CreateErrorResponseFromException(new PubNubException("Data not present"), requestState, PNStatusCategory.PNUnknownCategory);
                    }
                }
            } catch (Exception ex) {
                pnUserResult = null;
                pnStatus     = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory);
            }
            Callback(pnUserResult, pnStatus);
        }
        public static PNMembers ExtractMembers(Dictionary <string, object> objDataDict)
        {
            PNMembers pnMembers = new PNMembers();

            pnMembers.ID      = Utility.ReadMessageFromResponseDictionary(objDataDict, "id");
            pnMembers.User    = ObjectsHelpers.ExtractUser(Utility.ReadDictionaryFromResponseDictionary(objDataDict, "user"));
            pnMembers.Created = Utility.ReadMessageFromResponseDictionary(objDataDict, "created");
            pnMembers.Updated = Utility.ReadMessageFromResponseDictionary(objDataDict, "updated");
            pnMembers.ETag    = Utility.ReadMessageFromResponseDictionary(objDataDict, "eTag");
            pnMembers.Custom  = Utility.ReadDictionaryFromResponseDictionary(objDataDict, "custom");

            return(pnMembers);
        }
        protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
        {
            PNGetUsersResult pnUserResultList = new PNGetUsersResult();

            pnUserResultList.Data = new List <PNUserResult>();
            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)
                            {
                                PNUserResult pnUserResult = ObjectsHelpers.ExtractUser(objDataDict);
                                pnUserResultList.Data.Add(pnUserResult);
                            }
                            else
                            {
                                pnStatus = base.CreateErrorResponseFromException(new PubNubException("objDataDict null"), requestState, PNStatusCategory.PNUnknownCategory);
                            }
                        }
                    }
                    else
                    {
                        pnStatus = base.CreateErrorResponseFromException(new PubNubException("objData null"), requestState, PNStatusCategory.PNUnknownCategory);
                    }
                    int    totalCount;
                    string next;
                    string prev;
                    ObjectsHelpers.ExtractPagingParamsAndTotalCount(dictionary, "totalCount", "next", "prev", out totalCount, out next, out prev);
                    pnUserResultList.Next       = next;
                    pnUserResultList.Prev       = prev;
                    pnUserResultList.TotalCount = totalCount;
                }
            } catch (Exception ex) {
                pnUserResultList = null;
                pnStatus         = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory);
            }
            Callback(pnUserResultList, pnStatus);
        }
Exemple #4
0
        protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
        {
            PNUserResult pnUserResult = new PNUserResult();
            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)
                        {
                            pnUserResult = ObjectsHelpers.ExtractUser(objDataDict);
                        }
                        else
                        {
                            pnUserResult = null;
                            pnStatus     = base.CreateErrorResponseFromException(new PubNubException("objDataDict null"), requestState, PNStatusCategory.PNUnknownCategory);
                        }
                    }
                    else
                    {
                        pnUserResult = 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) {
                pnUserResult = null;
                pnStatus     = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory);
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog(string.Format("ex: {0}", ex.ToString()), PNLoggingMethod.LevelError);
                #endif
            }
            Callback(pnUserResult, pnStatus);
        }