Exemple #1
0
        protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
        {
            PNGetAllChannelMetadataResult pnSpaceResultList = new PNGetAllChannelMetadataResult();

            pnSpaceResultList.Data = new List <PNChannelMetadataResult>();
            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)
                            {
                                PNChannelMetadataResult pnSpaceResult = ObjectsHelpers.ExtractChannelMetadata(objDataDict);
                                pnSpaceResultList.Data.Add(pnSpaceResult);
                            }
                            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);
                    pnSpaceResultList.Next       = next;
                    pnSpaceResultList.Prev       = prev;
                    pnSpaceResultList.TotalCount = totalCount;
                }
            }
            catch (Exception ex)
            {
                pnSpaceResultList = null;
                pnStatus          = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory);
            }
            Callback(pnSpaceResultList, pnStatus);
        }
Exemple #2
0
        public static PNMemberships ExtractMemberships(Dictionary <string, object> objDataDict)
        {
            PNMemberships pnMemberships = new PNMemberships();

            pnMemberships.ID      = Utility.ReadMessageFromResponseDictionary(objDataDict, "id");
            pnMemberships.Channel = ObjectsHelpers.ExtractChannelMetadata(Utility.ReadDictionaryFromResponseDictionary(objDataDict, "channel"));
            pnMemberships.Created = Utility.ReadMessageFromResponseDictionary(objDataDict, "created");
            pnMemberships.Updated = Utility.ReadMessageFromResponseDictionary(objDataDict, "updated");
            pnMemberships.ETag    = Utility.ReadMessageFromResponseDictionary(objDataDict, "eTag");
            pnMemberships.Custom  = Utility.ReadDictionaryFromResponseDictionary(objDataDict, "custom");

            return(pnMemberships);
        }
        protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState)
        {
            PNChannelMetadataResult pnChannelMetadataResult = new PNChannelMetadataResult();
            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)
                        {
                            pnChannelMetadataResult = ObjectsHelpers.ExtractChannelMetadata(objDataDict);
                        }
                        else
                        {
                            pnChannelMetadataResult = null;
                            pnStatus = base.CreateErrorResponseFromException(new PubNubException("objDataDict null"), requestState, PNStatusCategory.PNUnknownCategory);
                        }
                    }
                    else
                    {
                        pnChannelMetadataResult = null;
                        pnStatus = base.CreateErrorResponseFromException(new PubNubException("objData null"), requestState, PNStatusCategory.PNUnknownCategory);
                    }
                }
            }
            catch (Exception ex)
            {
                pnChannelMetadataResult = null;
                pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory);
            }
            Callback(pnChannelMetadataResult, pnStatus);
        }