コード例 #1
0
        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);
        }
コード例 #2
0
        public static PNUserResult ExtractUser(Dictionary <string, object> objDataDict)
        {
            PNUserResult pnUserResult = new PNUserResult();

            pnUserResult.ID         = Utility.ReadMessageFromResponseDictionary(objDataDict, "id");
            pnUserResult.Name       = Utility.ReadMessageFromResponseDictionary(objDataDict, "name");
            pnUserResult.ExternalID = Utility.ReadMessageFromResponseDictionary(objDataDict, "externalId");
            pnUserResult.ProfileURL = Utility.ReadMessageFromResponseDictionary(objDataDict, "profileUrl");
            pnUserResult.Email      = Utility.ReadMessageFromResponseDictionary(objDataDict, "email");
            pnUserResult.Created    = Utility.ReadMessageFromResponseDictionary(objDataDict, "created");
            pnUserResult.Updated    = Utility.ReadMessageFromResponseDictionary(objDataDict, "updated");
            pnUserResult.ETag       = Utility.ReadMessageFromResponseDictionary(objDataDict, "eTag");
            pnUserResult.Custom     = Utility.ReadDictionaryFromResponseDictionary(objDataDict, "custom");

            return(pnUserResult);
        }