protected override void RunWebRequest(QueueManager qm) { RequestState requestState = new RequestState(); requestState.OperationType = OperationType; requestState.httpMethod = HTTPMethod.Patch; var cub = new { add = ObjectsHelpers.ConvertPNMembersInputForJSON(ManageMembershipsAdd), update = ObjectsHelpers.ConvertPNMembersInputForJSON(ManageMembershipsUpdate), remove = ObjectsHelpers.ConvertPNMembersRemoveForJSON(ManageMembershipsRemove), }; string jsonUserBody = Helpers.JsonEncodePublishMsg(cub, "", this.PubNubInstance.JsonLibrary, this.PubNubInstance.PNLog); #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("jsonUserBody: {0}", jsonUserBody), PNLoggingMethod.LevelInfo); #endif requestState.POSTData = jsonUserBody; string[] includeString = (ManagerMembershipsInclude == null) ? new string[] {} : ManagerMembershipsInclude.Select(a => a.GetDescription().ToString()).ToArray(); Uri request = BuildRequests.BuildObjectsManageMembershipsRequest( ManageMembershipsUserID, ManageMembershipsLimit, ManageMembershipsStart, ManageMembershipsEnd, ManageMembershipsCount, string.Join(",", includeString), this.PubNubInstance, this.QueryParams ); base.RunWebRequest(qm, request, requestState, this.PubNubInstance.PNConfig.NonSubscribeTimeout, 0, this); }
protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { PNUUIDMetadataResult pnUUIDMetadataResult = new PNUUIDMetadataResult(); 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) { pnUUIDMetadataResult = ObjectsHelpers.ExtractUUIDMetadata(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) { pnUUIDMetadataResult = null; pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory); } Callback(pnUUIDMetadataResult, pnStatus); }
protected override void RunWebRequest(QueueManager qm) { RequestState requestState = new RequestState(); requestState.OperationType = OperationType; requestState.httpMethod = HTTPMethod.Patch; var cub = new { set = ObjectsHelpers.ConvertPNMembershipsInputForJSON(ManageMembershipsSet), delete = ObjectsHelpers.ConvertPNMembershipsRemoveForJSON(ManageMembershipsRemove), }; string jsonUserBody = Helpers.JsonEncodePublishMsg(cub, "", this.PubNubInstance.JsonLibrary, this.PubNubInstance.PNLog); #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("jsonUserBody: {0}", jsonUserBody), PNLoggingMethod.LevelInfo); #endif requestState.POSTData = jsonUserBody; string[] includeString = (ManagerMembershipsInclude == null) ? new string[] {} : ManagerMembershipsInclude.Select(a => a.GetDescription().ToString()).ToArray(); List <string> sortFields = SortBy ?? new List <string>(); Uri request = BuildRequests.BuildObjectsManageMembershipsRequest( ManageMembershipsUUID, ManageMembershipsLimit, ManageMembershipsStart, ManageMembershipsEnd, ManageMembershipsCount, string.Join(",", includeString), this.PubNubInstance, this.QueryParams, string.Join(",", sortFields) ); request = this.PubNubInstance.TokenMgr.AppendTokenToURL(request.OriginalString, ManageMembershipsUUID, PNResourceType.PNUUIDMetadata, OperationType); base.RunWebRequest(qm, request, requestState, this.PubNubInstance.PNConfig.NonSubscribeTimeout, 0, this); }
protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { PNGetSpacesResult pnSpaceResultList = new PNGetSpacesResult(); pnSpaceResultList.Data = new List <PNSpaceResult>(); 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) { PNSpaceResult pnSpaceResult = ObjectsHelpers.ExtractSpace(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); }
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); }
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) { PNUserResult pnUserResult = new PNUserResult(); PNStatus pnStatus = new PNStatus(); Debug.Log("=======>" + deSerializedResult.ToString()); try{ Debug.Log("=======> dictionary"); 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); Debug.Log("=======> pnUserResult" + pnUserResult); } else { pnUserResult = null; pnStatus = base.CreateErrorResponseFromException(new PubNubException("objDataDict null"), requestState, PNStatusCategory.PNUnknownCategory); } } else { Debug.Log("=======> objData null"); pnUserResult = null; pnStatus = base.CreateErrorResponseFromException(new PubNubException("objData null"), requestState, PNStatusCategory.PNUnknownCategory); } } else { Debug.Log("=======> dictionary null"); } } catch (Exception ex) { Debug.Log("=======>" + ex.ToString()); pnUserResult = null; pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory); } Callback(pnUserResult, pnStatus); }
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); }
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 { pnUserResultList = null; pnStatus = base.CreateErrorResponseFromException(new PubNubException("objData null"), requestState, PNStatusCategory.PNUnknownCategory); } } } catch (Exception ex) { pnUserResultList = null; pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory); } Callback(pnUserResultList, pnStatus); }
internal void CreateObjectsEventResult(SubscribeMessage subscribeMessage, out PNUserEventResult pnUserEventResult, out PNSpaceEventResult pnSpaceEventResult, out PNMembershipEventResult pnMembershipEventResult) { pnUserEventResult = null; pnSpaceEventResult = null; pnMembershipEventResult = null; object payload = subscribeMessage.Payload; Dictionary <string, object> pnObjectEventDict = payload as Dictionary <string, object>; string objectsEventType = Utility.ReadMessageFromResponseDictionary(pnObjectEventDict, "type"); string objectsEvent = Utility.ReadMessageFromResponseDictionary(pnObjectEventDict, "event"); Dictionary <string, object> data = Utility.ReadDictionaryFromResponseDictionary(pnObjectEventDict, "data"); if (data != null) { string userID = Utility.ReadMessageFromResponseDictionary(data, "userId"); string ID = Utility.ReadMessageFromResponseDictionary(data, "id"); string spaceID = Utility.ReadMessageFromResponseDictionary(data, "spaceId"); string name = Utility.ReadMessageFromResponseDictionary(data, "name"); string externalID = Utility.ReadMessageFromResponseDictionary(data, "externalId"); string profileURL = Utility.ReadMessageFromResponseDictionary(data, "profileUrl"); string email = Utility.ReadMessageFromResponseDictionary(data, "email"); string description = Utility.ReadMessageFromResponseDictionary(data, "description"); string timestamp = Utility.ReadMessageFromResponseDictionary(data, "timestamp"); string created = Utility.ReadMessageFromResponseDictionary(data, "created"); string updated = Utility.ReadMessageFromResponseDictionary(data, "updated"); string eTag = Utility.ReadMessageFromResponseDictionary(data, "eTag"); Dictionary <string, object> custom = Utility.ReadDictionaryFromResponseDictionary(pnObjectEventDict, "custom"); if (objectsEventType.Equals(PNObjectsEventType.PNObjectsUserEvent.GetDescription().ToString())) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("PNObjectsUserEvent"), PNLoggingMethod.LevelInfo); #endif pnUserEventResult = new PNUserEventResult(); pnUserEventResult.ObjectsEvent = ObjectsHelpers.GetPNObjectsEventFromString(objectsEvent); pnUserEventResult.Subscription = subscribeMessage.SubscriptionMatch.Replace(Utility.PresenceChannelSuffix, ""); pnUserEventResult.Channel = subscribeMessage.Channel.Replace(Utility.PresenceChannelSuffix, ""); pnUserEventResult.Email = email; pnUserEventResult.UserID = ID; pnUserEventResult.Timestamp = timestamp; pnUserEventResult.Created = created; pnUserEventResult.Updated = updated; pnUserEventResult.ETag = eTag; pnUserEventResult.Custom = custom; pnUserEventResult.Name = name; pnUserEventResult.ExternalID = externalID; pnUserEventResult.ProfileURL = profileURL; this.PubNubInstance.PNLog.WriteToLog("pnUserEventResult.UserID" + pnUserEventResult.UserID, PNLoggingMethod.LevelInfo); } else if (objectsEventType.Equals(PNObjectsEventType.PNObjectsSpaceEvent.GetDescription().ToString())) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("PNObjectsSpaceEvent"), PNLoggingMethod.LevelInfo); #endif pnSpaceEventResult = new PNSpaceEventResult(); pnSpaceEventResult.ObjectsEvent = ObjectsHelpers.GetPNObjectsEventFromString(objectsEvent); pnSpaceEventResult.Subscription = subscribeMessage.SubscriptionMatch.Replace(Utility.PresenceChannelSuffix, ""); pnSpaceEventResult.Channel = subscribeMessage.Channel.Replace(Utility.PresenceChannelSuffix, ""); pnSpaceEventResult.Description = description; pnSpaceEventResult.SpaceID = ID; pnSpaceEventResult.Timestamp = timestamp; pnSpaceEventResult.Created = created; pnSpaceEventResult.Updated = updated; pnSpaceEventResult.ETag = eTag; pnSpaceEventResult.Custom = custom; pnSpaceEventResult.Name = name; } else if (objectsEventType.Equals(PNObjectsEventType.PNObjectsMembershipEvent.GetDescription().ToString())) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("PNObjectsMembershipEvent"), PNLoggingMethod.LevelInfo); #endif pnMembershipEventResult = new PNMembershipEventResult(); pnMembershipEventResult.ObjectsEvent = ObjectsHelpers.GetPNObjectsEventFromString(objectsEvent); pnMembershipEventResult.Subscription = subscribeMessage.SubscriptionMatch.Replace(Utility.PresenceChannelSuffix, ""); pnMembershipEventResult.Channel = subscribeMessage.Channel.Replace(Utility.PresenceChannelSuffix, ""); pnMembershipEventResult.Description = description; pnMembershipEventResult.SpaceID = spaceID; pnMembershipEventResult.UserID = userID; pnMembershipEventResult.Timestamp = timestamp; pnMembershipEventResult.Custom = custom; } } }