protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { PNPushRemoveChannelResult pnPushRemoveChannelResult = new PNPushRemoveChannelResult(); Dictionary <string, object> dictionary = deSerializedResult as Dictionary <string, object>; PNStatus pnStatus = new PNStatus(); if (dictionary != null) { string message = Utility.ReadMessageFromResponseDictionary(dictionary, "message"); if (Utility.CheckDictionaryForError(dictionary, "error")) { pnPushRemoveChannelResult = null; pnStatus = base.CreateErrorResponseFromMessage(message, requestState, PNStatusCategory.PNUnknownCategory); } } else { object[] c = deSerializedResult as object[]; if (c != null) { string status = ""; string statusCode = "0"; if (c.Length > 0) { statusCode = c[0].ToString(); } if (c.Length > 1) { status = c[1].ToString(); } if (statusCode.Equals("0") || (!status.ToLowerInvariant().Equals("modified channels"))) { pnPushRemoveChannelResult = null; pnStatus = base.CreateErrorResponseFromMessage(status, requestState, PNStatusCategory.PNUnknownCategory); } else { pnPushRemoveChannelResult.Message = status; } } else { pnPushRemoveChannelResult = null; pnStatus = base.CreateErrorResponseFromMessage("deSerializedResult object is null", requestState, PNStatusCategory.PNMalformedResponseCategory); } } Callback(pnPushRemoveChannelResult, pnStatus); }
protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { PNMembershipsResult pnManageMembershipsResult = new PNMembershipsResult(); pnManageMembershipsResult.Data = new List <PNMemberships>(); 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) { PNMemberships pnMemberships = ObjectsHelpers.ExtractMemberships(objDataDict); pnManageMembershipsResult.Data.Add(pnMemberships); } 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); pnManageMembershipsResult.Next = next; pnManageMembershipsResult.Prev = prev; pnManageMembershipsResult.TotalCount = totalCount; } } catch (Exception ex) { pnManageMembershipsResult = null; pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory); } Callback(pnManageMembershipsResult, pnStatus); }
private PNStatus CreatePNStatus(UnityWebRequest www) { PNStatus pnStatus = new PNStatus(); pnStatus.StatusCode = www.responseCode; if (www.isNetworkError || www.isHttpError) { pnStatus.Error = true; pnStatus.ErrorData = new PNErrorData() { Info = www.downloadHandler.text }; } return(pnStatus); }
protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { PNGrantTokenResult pnGrantTokenResult = new PNGrantTokenResult(); 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> dataDictionary = objData as Dictionary <string, object>; if (dataDictionary != null) { dataDictionary.TryGetValue("token", out objData); pnGrantTokenResult.Token = objData.ToString(); this.PubNubInstance.TokenMgr.StoreToken(pnGrantTokenResult.Token); } else { pnGrantTokenResult = null; pnStatus = base.CreateErrorResponseFromException(new PubNubException("dataDictionary null"), requestState, PNStatusCategory.PNUnknownCategory); } } else { pnGrantTokenResult = 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) { pnGrantTokenResult = 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(pnGrantTokenResult, pnStatus); }
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) { //[[{"text":"hey"},{"text":"hey"},{"text":"hey"},{"text":"hey"}],15011678612673119,15011678623670911] PNHistoryResult pnHistoryResult = new PNHistoryResult(); pnHistoryResult.Messages = new List <PNHistoryItemResult>(); PNStatus pnStatus = new PNStatus(); try{ List <object> result = ((IEnumerable)deSerializedResult).Cast <object> ().ToList(); if (result != null) { var historyResponseArray = (from item in result select item as object).ToArray(); #if (ENABLE_PUBNUB_LOGGING) foreach (var h in historyResponseArray) { this.PubNubInstance.PNLog.WriteToLog(string.Format("HistoryRequestBuilder: {0}", h.ToString()), PNLoggingMethod.LevelInfo); } #endif if (historyResponseArray.Length >= 1) { //TODO add checks if (!ExtractMessages(historyResponseArray, ref pnHistoryResult)) { pnHistoryResult = null; pnStatus = base.CreateErrorResponseFromMessage("ExtractMessages failed", requestState, PNStatusCategory.PNMalformedResponseCategory); } } if (historyResponseArray.Length > 1) { pnHistoryResult.StartTimetoken = Utility.ValidateTimetoken(historyResponseArray[1].ToString(), true); } if (historyResponseArray.Length > 2) { pnHistoryResult.EndTimetoken = Utility.ValidateTimetoken(historyResponseArray[2].ToString(), true); } } } catch (Exception ex) { pnHistoryResult = null; pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory); } Callback(pnHistoryResult, pnStatus); }
protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { //Returned JSON: `{"status": 200, "error": false, "error_message": "", "channels": {"channel2":[{"message":{"text":"hey"},"timetoken":"15011678669001834"}],"channel1":[{"message":{"text":"hey"},"timetoken":"15011678623670911"}]}}` PNFetchMessagesResult pnFetchMessagesResult = new PNFetchMessagesResult(); PNStatus pnStatus = new PNStatus(); try{ Dictionary <string, object> dictionary = deSerializedResult as Dictionary <string, object>; if (dictionary != null) { string message = Utility.ReadMessageFromResponseDictionary(dictionary, "error_message"); if (Utility.CheckDictionaryForError(dictionary, "error")) { pnFetchMessagesResult = null; pnStatus = base.CreateErrorResponseFromMessage(message, requestState, PNStatusCategory.PNUnknownCategory); } else { object objChannelsDict; dictionary.TryGetValue("channels", out objChannelsDict); if (objChannelsDict != null) { Dictionary <string, List <PNMessageResult> > channelsResult; if (!CreateFetchMessagesResult(objChannelsDict, out channelsResult)) { pnFetchMessagesResult = null; pnStatus = base.CreateErrorResponseFromMessage("channelsResult dictionary is null", requestState, PNStatusCategory.PNUnknownCategory); } else { pnFetchMessagesResult.Channels = channelsResult; } } } } else { pnFetchMessagesResult = null; pnStatus = base.CreateErrorResponseFromMessage("Response dictionary is null", requestState, PNStatusCategory.PNUnknownCategory); } } catch (Exception ex) { pnFetchMessagesResult = null; pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory); } Callback(pnFetchMessagesResult, pnStatus); }
protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { object[] c = deSerializedResult as object[]; PNSignalResult pnSignalResult = new PNSignalResult(); PNStatus pnStatus = new PNStatus(); if (c != null) { string status = ""; string statusCode = "0"; if (c.Length > 0) { statusCode = c[0].ToString(); } if (c.Length > 1) { status = c[1].ToString(); } if (statusCode.Equals("0") || (!status.ToLowerInvariant().Equals("sent"))) { pnSignalResult = null; string message = ""; if (c.Length > 2) { message = c[2].ToString(); } pnStatus = base.CreateErrorResponseFromMessage(string.Format("Signal Failure: {0}", message), requestState, PNStatusCategory.PNBadRequestCategory); } else { if (c.Length > 2) { pnSignalResult.Timetoken = Utility.ValidateTimetoken(c[2].ToString(), false); } else { pnSignalResult.Timetoken = 0; } } } else { pnSignalResult = null; pnStatus = base.CreateErrorResponseFromMessage("Response is null", requestState, PNStatusCategory.PNMalformedResponseCategory); } Callback(pnSignalResult, pnStatus); }
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 { pnSpaceResultList = null; pnStatus = base.CreateErrorResponseFromException(new PubNubException("objData null"), requestState, PNStatusCategory.PNUnknownCategory); } } } catch (Exception ex) { pnSpaceResultList = null; pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory); } Callback(pnSpaceResultList, pnStatus); }
protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { PNDeleteUserResult pnUserResult = new PNDeleteUserResult(); PNStatus pnStatus = new PNStatus(); try{ Dictionary <string, object> dictionary = deSerializedResult as Dictionary <string, object>; if (dictionary == null) { pnUserResult = null; 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); }
protected void CreateErrorResponse(PNStatusCategory pnStatusCategory, Exception exception, bool showInCallback, RequestState pnRequestState) { PNStatus pnStatus = Helpers.CreatePNStatus( pnStatusCategory, exception.Message, exception, true, OperationType, ChannelsToUse, ChannelGroupsToUse, pnRequestState, PubNubInstance ); if (showInCallback) { Callback(null, pnStatus); } }
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); }
public void Async(Action <PNChannelGroupsRemoveChannelResult, PNStatus> callback) { this.Callback = callback; if ((ChannelsToUse == null) || ((ChannelsToUse != null) && (ChannelsToUse.Count <= 0))) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("ChannelsToRemove null or empty", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } if (string.IsNullOrEmpty(ChannelGroupToDelete)) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("ChannelGroup to delete from is empty", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } base.Async(this); }
protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { Int64[] c = deSerializedResult as Int64[]; PNTimeResult pnTimeResult = new PNTimeResult(); PNStatus pnStatus = new PNStatus(); if ((c != null) && (c.Length > 0)) { pnTimeResult.TimeToken = c [0]; } else { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreatePubNubResponse (c == null) || (c.Length < 0) {0}", deSerializedResult.ToString()), PNLoggingMethod.LevelInfo); #endif pnStatus.Error = true; pnStatus = base.CreateErrorResponseFromMessage("Response is null", requestState, PNStatusCategory.PNMalformedResponseCategory); } Callback(pnTimeResult, pnStatus); }
public void Async(Action <PNPushRemoveAllChannelsResult, PNStatus> callback) { this.Callback = callback; if (string.IsNullOrEmpty(DeviceIDForPush)) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("DeviceId is empty", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } if (PushType.Equals(PNPushType.None)) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog("PNPushType not selected, using GCM", PNLoggingMethod.LevelInfo); #endif PushType = PNPushType.GCM; } base.Async(this); }
public void Async(Action <PNFetchMessagesResult, PNStatus> callback) { this.Callback = callback; if ((this.ChannelsToUse == null) || ((this.ChannelsToUse != null) && (this.ChannelsToUse.Count <= 0))) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("HistoryChannel is null or empty", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } if ((this.IncludeMessageActionsInHistory) && (this.ChannelsToUse.Count > 1)) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("Only one channel is supported when WithMessageActions is true", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } base.Async(this); }
public void Async(Action <PNGetFileURLResult, PNStatus> callback) { this.Callback = callback; RequestState requestState = new RequestState(); requestState.OperationType = OperationType; requestState.httpMethod = HTTPMethod.Get; Uri request = BuildRequests.BuildDownloadFileRequest( GetFileURLChannel, GetFileURLID.ToString(), GetFileURLName.ToString(), this.PubNubInstance, this.QueryParams ); PNGetFileURLResult pnGetFileURLResult = new PNGetFileURLResult(); PNStatus pnStatus = new PNStatus(); pnGetFileURLResult.URL = request.ToString(); Callback(pnGetFileURLResult, pnStatus); }
public void Async(Action <PNDeleteMessagesResult, PNStatus> callback) { base.Callback = callback; if (string.IsNullOrEmpty(this.HistoryChannel)) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("DeleteHistory Channel is empty", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } if (string.IsNullOrEmpty(this.PubNubInstance.PNConfig.SecretKey)) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("SecretKey is required", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } base.Async(this); }
public void Async(Action <PNPushRemoveChannelResult, PNStatus> callback) { this.Callback = callback; if ((ChannelsToUse == null) || ((ChannelsToUse != null) && (ChannelsToUse.Count <= 0))) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("ChannelsToAdd null or empty", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } if (string.IsNullOrEmpty(DeviceIDForPush)) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("DeviceId is empty", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } base.Async(this); }
protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { PNSpaceResult pnSpaceResult = new PNSpaceResult(); 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) { pnSpaceResult = ObjectsHelpers.ExtractSpace(objDataDict); } else { pnSpaceResult = null; pnStatus = base.CreateErrorResponseFromException(new PubNubException("objDataDict not present"), requestState, PNStatusCategory.PNUnknownCategory); } } else { pnSpaceResult = null; pnStatus = base.CreateErrorResponseFromException(new PubNubException("Data not present"), requestState, PNStatusCategory.PNUnknownCategory); } } } catch (Exception ex) { pnSpaceResult = null; pnStatus = base.CreateErrorResponseFromException(ex, requestState, PNStatusCategory.PNUnknownCategory); } Callback(pnSpaceResult, pnStatus); }
internal void FindChannelEntityAndCallback(SubscribeMessage subscribeMessage, ChannelIdentity ci) { bool isPresenceChannel = Utility.IsPresenceChannel(subscribeMessage.Channel); PNStatus pns = new PNStatus(); pns.Error = false; SubscribeEventEventArgs mea = new SubscribeEventEventArgs(); mea.Status = pns; if (((subscribeMessage.SubscriptionMatch.Contains(".*")) && isPresenceChannel) || (isPresenceChannel)) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog("Raising presence message event ", PNLoggingMethod.LevelInfo); #endif PNPresenceEventResult subMessageResult; CreatePNPresenceEventResult(subscribeMessage, out subMessageResult); mea.PresenceEventResult = subMessageResult; PubNubInstance.RaiseEvent(mea); } else { PNMessageResult subMessageResult; CreatePNMessageResult(subscribeMessage, out subMessageResult); #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog("Raising message event ", PNLoggingMethod.LevelInfo); #endif if (!string.IsNullOrEmpty(this.PubNubInstance.PNConfig.CipherKey) && (this.PubNubInstance.PNConfig.CipherKey.Length > 0)) { subMessageResult.Payload = Helpers.DecodeMessage(PubNubInstance.PNConfig.CipherKey, subMessageResult.Payload, PNOperationType.PNSubscribeOperation, this.PubNubInstance); } mea.MessageResult = subMessageResult; PubNubInstance.RaiseEvent(mea); } }
public void Async(Action <PNPushAddChannelResult, PNStatus> callback) { this.Callback = callback; if ((ChannelsToUse == null) || ((ChannelsToUse != null) && (ChannelsToUse.Count <= 0))) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("ChannelsToAdd null or empty", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } if (string.IsNullOrEmpty(DeviceIDForPush)) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("DeviceId is empty", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } if (PushType.Equals(PNPushType.None)) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog("PNPushType not selected, using GCM", PNLoggingMethod.LevelInfo); #endif PushType = PNPushType.GCM; } if (PushType.Equals(PNPushType.APNS2) && (string.IsNullOrEmpty(TopicForPush))) { PNStatus pnStatus = base.CreateErrorResponseFromMessage(CommonText.APNS2TopicEmpty, null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } base.Async(this); }
protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { //Returned JSON `["channel1", "channel2"] ` PNPushListProvisionsResult pnPushListProvisionsResult = new PNPushListProvisionsResult(); Dictionary <string, object> dictionary = deSerializedResult as Dictionary <string, object>; PNStatus pnStatus = new PNStatus(); if (dictionary != null) { string message = Utility.ReadMessageFromResponseDictionary(dictionary, "message"); if (Utility.CheckDictionaryForError(dictionary, "error")) { pnPushListProvisionsResult = null; pnStatus = base.CreateErrorResponseFromMessage(message, requestState, PNStatusCategory.PNUnknownCategory); } } else { object[] c = deSerializedResult as object[]; if (c != null) { pnPushListProvisionsResult.Channels = new List <string>(); foreach (string ch in c) { pnPushListProvisionsResult.Channels.Add(ch); } } else { pnPushListProvisionsResult = null; pnStatus = base.CreateErrorResponseFromMessage("Response dictionary is null", requestState, PNStatusCategory.PNMalformedResponseCategory); } } Callback(pnPushListProvisionsResult, pnStatus); }
public void Async(Action <PNSignalResult, PNStatus> callback) { this.Callback = callback; if (string.IsNullOrEmpty(this.PubNubInstance.PNConfig.PublishKey)) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("Publish Key is empty", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } if (string.IsNullOrEmpty(this.SignalChannel)) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("Channel is empty", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } if (this.SignalMessage == null) { PNStatus pnStatus = base.CreateErrorResponseFromMessage("Message is empty", null, PNStatusCategory.PNBadRequestCategory); Callback(null, pnStatus); return; } base.Async(this); }
internal void RaiseError(PNStatus pnStatus) { Callback(null, pnStatus); }
public void Execute() { if (((this.ChannelsToUse == null) || (this.ChannelsToUse.Count <= 0)) && ((this.ChannelGroupsToUse == null) || (this.ChannelGroupsToUse.Count <= 0))) { PNStatus pnStatus = Helpers.CreatePNStatus( PNStatusCategory.PNUnknownCategory, "Both Channels and ChannelGroups cannot be empty", null, true, PNOperationType.PNSubscribeOperation, this.ChannelsToUse, this.ChannelGroupsToUse, null, PubNubInstance ); PubNubInstance.SubWorker.CreateEventArgsAndRaiseEvent(pnStatus); } List <ChannelEntity> subscribedChannels = this.PubNubInstance.SubscriptionInstance.AllSubscribedChannelsAndChannelGroups; List <ChannelEntity> newChannelEntities; List <string> rawChannels = this.ChannelsToUse; List <string> rawChannelGroups = this.ChannelGroupsToUse; CheckPresenceAndAddSuffix(ref rawChannels, IncludePresenceChannel, SubscribeToPresenceChannelOnly); CheckPresenceAndAddSuffix(ref rawChannelGroups, IncludePresenceChannel, SubscribeToPresenceChannelOnly); PNOperationType pnOpType = PNOperationType.PNSubscribeOperation; long timetokenToUse = this.Timetoken; bool channelsOrChannelGroupsAdded = this.PubNubInstance.SubscriptionInstance.TryRemoveDuplicatesCheckAlreadySubscribedAndGetChannels(pnOpType, rawChannels, rawChannelGroups, false, out newChannelEntities); if (channelsOrChannelGroupsAdded) { this.PubNubInstance.SubscriptionInstance.Add(newChannelEntities); this.PubNubInstance.SubWorker.Add(timetokenToUse, subscribedChannels); this.PubNubInstance.SubWorker.QueryParams = QueryParams; } else { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("MultiChannelSubscribeInit: channelsOrChannelGroupsAdded {0}", channelsOrChannelGroupsAdded.ToString()), PNLoggingMethod.LevelInfo); #endif PNStatus pnStatus = Helpers.CreatePNStatus( PNStatusCategory.PNUnknownCategory, CommonText.DuplicateChannelsOrChannelGroups, new PubNubException(CommonText.DuplicateChannelsOrChannelGroups), true, PNOperationType.PNSubscribeOperation, rawChannels, rawChannelGroups, null, PubNubInstance ); PubNubInstance.SubWorker.CreateEventArgsAndRaiseEvent(pnStatus); } #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("channelsOrChannelGroupsAdded: {0}\nnewChannelEntities:{1}", channelsOrChannelGroupsAdded, newChannelEntities.Count), PNLoggingMethod.LevelInfo); #endif }
protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { //Returned JSON: `{"status": 200, "message": "OK", "payload": {"channels": {"channel1": {"k": "v"}, "channel2": {}}}, "uuid": "pn-c5a12d424054a3688066572fb955b7a0", "service": "Presence"}` //TODO read all values. PNSetStateResult pnSetStateResult = new PNSetStateResult(); Dictionary <string, object> dictionary = deSerializedResult as Dictionary <string, object>; PNStatus pnStatus = new PNStatus(); if (dictionary != null) { string message = Utility.ReadMessageFromResponseDictionary(dictionary, "message"); if (Utility.CheckDictionaryForError(dictionary, "error")) { pnSetStateResult = null; pnStatus = base.CreateErrorResponseFromMessage(message, requestState, PNStatusCategory.PNUnknownCategory); } else { object objPayload; dictionary.TryGetValue("payload", out objPayload); if (objPayload != null) { Dictionary <string, object> payload = objPayload as Dictionary <string, object>; object objChannelsDict; payload.TryGetValue("channels", out objChannelsDict); if (objChannelsDict != null) { Dictionary <string, object> channelsDict = objPayload as Dictionary <string, object>; #if (ENABLE_PUBNUB_LOGGING) foreach (KeyValuePair <string, object> kvp in channelsDict) { this.PubNubInstance.PNLog.WriteToLog(string.Format("KVP: {0} -- {1}", kvp.Key, kvp.Value), PNLoggingMethod.LevelInfo); } #endif pnSetStateResult.StateByChannels = channelsDict; } else { pnSetStateResult.StateByChannels = payload; } } else { pnSetStateResult = null; pnStatus = base.CreateErrorResponseFromMessage("Payload dictionary is null", requestState, PNStatusCategory.PNMalformedResponseCategory); } } } else { pnSetStateResult = null; pnStatus = base.CreateErrorResponseFromMessage("Response dictionary is null", requestState, PNStatusCategory.PNMalformedResponseCategory); } Callback(pnSetStateResult, pnStatus); }
internal void ResponseToUserCallbackForSubscribe(List <SubscribeMessage> subscribeMessages) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("In ResponseToUserCallbackForSubscribeV2"), PNLoggingMethod.LevelInfo); #endif if (subscribeMessages.Count >= this.PubNubInstance.PNConfig.MessageQueueOverflowCount) { PNStatus pnStatus = Helpers.CreatePNStatus( PNStatusCategory.PNRequestMessageCountExceededCategory, "", null, true, PNOperationType.PNSubscribeOperation, PubNubInstance.SubscriptionInstance.AllChannels, PubNubInstance.SubscriptionInstance.AllChannelGroups, null, this.PubNubInstance ); CreateEventArgsAndRaiseEvent(pnStatus); } foreach (SubscribeMessage subscribeMessage in subscribeMessages) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("ResponseToUserCallbackForSubscribeV2:\n SubscribeMessage:\n" + "shard : {0},\n" + "subscriptionMatch: {1},\n" + "channel: {2},\n" + "payload: {3},\n" + "flags: {4},\n" + "issuingClientId: {5},\n" + "subscribeKey: {6},\n" + "sequenceNumber: {7},\n" + "originatingTimetoken tt: {8},\n" + "originatingTimetoken region: {9},\n" + "publishMetadata tt: {10},\n" + "publishMetadata region: {11},\n" + "userMetadata {12} \n", subscribeMessage.Shard, subscribeMessage.SubscriptionMatch, subscribeMessage.Channel, subscribeMessage.Payload.ToString(), subscribeMessage.Flags, subscribeMessage.IssuingClientId, subscribeMessage.SubscribeKey, subscribeMessage.SequenceNumber, (subscribeMessage.OriginatingTimetoken != null) ? subscribeMessage.OriginatingTimetoken.Timetoken.ToString() : "", (subscribeMessage.OriginatingTimetoken != null) ? subscribeMessage.OriginatingTimetoken.Region : "", (subscribeMessage.PublishTimetokenMetadata != null) ? subscribeMessage.PublishTimetokenMetadata.Timetoken.ToString() : "", (subscribeMessage.PublishTimetokenMetadata != null) ? subscribeMessage.PublishTimetokenMetadata.Region : "", (subscribeMessage.UserMetadata != null) ? subscribeMessage.UserMetadata.ToString() : "null"), PNLoggingMethod.LevelInfo); #endif bool isPresenceChannel = Utility.IsPresenceChannel(subscribeMessage.Channel); if (string.IsNullOrEmpty(subscribeMessage.SubscriptionMatch) || subscribeMessage.Channel.Equals(subscribeMessage.SubscriptionMatch)) { //channel ChannelIdentity ci = new ChannelIdentity(subscribeMessage.Channel, false, isPresenceChannel); FindChannelEntityAndCallback(subscribeMessage, ci); } else if (subscribeMessage.SubscriptionMatch.Contains(".*") && isPresenceChannel) { //wildcard presence channel ChannelIdentity ci = new ChannelIdentity(subscribeMessage.SubscriptionMatch, false, false); FindChannelEntityAndCallback(subscribeMessage, ci); } else if (subscribeMessage.SubscriptionMatch.Contains(".*")) { //wildcard channel ChannelIdentity ci = new ChannelIdentity(subscribeMessage.SubscriptionMatch, false, isPresenceChannel); FindChannelEntityAndCallback(subscribeMessage, ci); } else { ChannelIdentity ci = new ChannelIdentity(subscribeMessage.SubscriptionMatch, true, isPresenceChannel); FindChannelEntityAndCallback(subscribeMessage, ci); //ce will be the cg and subscriptionMatch will have the cg name } } }
//TODO refactor protected override void CreatePubNubResponse(object deSerializedResult, RequestState requestState) { //Retruned JSON: `{"status": 200, "message": "OK", "payload": {"channels": {"channel1": {"occupancy": 1, "uuids": ["a"]}, "channel2": {"occupancy": 1, "uuids": ["a"]}}, "total_channels": 2, "total_occupancy": 2}, "service": "Presence"}` //Retruned JSON: `{"status": 200, "message": "OK", "occupancy": 1, "uuids": [{"uuid": "UnityTestHereNowUUID"}], "service": "Presence"}` PNHereNowResult pnHereNowResult = new PNHereNowResult(); Dictionary <string, object> dictionary = deSerializedResult as Dictionary <string, object>; PNStatus pnStatus = new PNStatus(); if (dictionary != null) { string message = Utility.ReadMessageFromResponseDictionary(dictionary, "message"); if (Utility.CheckDictionaryForError(dictionary, "error")) { pnHereNowResult = null; pnStatus = base.CreateErrorResponseFromMessage(message, requestState, PNStatusCategory.PNUnknownCategory); } else { int totalChannels, total_occupancy; string log = ""; object objPayload; dictionary.TryGetValue("payload", out objPayload); if (objPayload != null) { Dictionary <string, object> payload = objPayload as Dictionary <string, object>; object objChannelsDict; payload.TryGetValue("channels", out objChannelsDict); if (objChannelsDict != null) { Dictionary <string, PNHereNowChannelData> channelsResult; pnStatus.Error = CreateHereNowResult(objChannelsDict, out channelsResult); pnHereNowResult.Channels = channelsResult; } } else if (Utility.TryCheckKeyAndParseInt(dictionary, "total_channels", "total_channels", out log, out totalChannels)) { pnHereNowResult.TotalChannels = totalChannels; #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("log: {0}", log), PNLoggingMethod.LevelInfo); #endif } else if (Utility.TryCheckKeyAndParseInt(dictionary, "total_occupancy", "total_occupancy", out log, out total_occupancy)) { pnHereNowResult.TotalOccupancy = total_occupancy; #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("log2: {0}", log), PNLoggingMethod.LevelInfo); #endif } else if ((ChannelsToUse.Count.Equals(1) && (ChannelGroupsToUse == null)) && dictionary.TryGetValue("uuids", out objPayload)) { Dictionary <string, object> objChannelsDict = new Dictionary <string, object>(); Dictionary <string, PNHereNowChannelData> channelsResult; object[] uuidsArray = objPayload as object[]; Dictionary <string, object> channelsResultDict = new Dictionary <string, object>(); channelsResultDict.Add("uuids", uuidsArray); objChannelsDict.Add(ChannelsToUse[0], channelsResultDict); pnStatus.Error = CreateHereNowResult(objChannelsDict, out channelsResult); pnHereNowResult.Channels = channelsResult; #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("pnStatus.Error: {0} channelsResult.Count().ToString(): {1} ChannelsToUse[0]: {2}", pnStatus.Error, channelsResult.Count().ToString(), ChannelsToUse[0]), PNLoggingMethod.LevelInfo); foreach (KeyValuePair <string, PNHereNowChannelData> kvp in channelsResult) { this.PubNubInstance.PNLog.WriteToLog(string.Format("kvp.Key: {0} ", kvp.Key), PNLoggingMethod.LevelInfo); PNHereNowChannelData pnHereNowChannelData = kvp.Value; List <PNHereNowOccupantData> pnHereNowOccupantDataList = pnHereNowChannelData.Occupants; foreach (PNHereNowOccupantData pnHereNowOccupantData in pnHereNowOccupantDataList) { this.PubNubInstance.PNLog.WriteToLog(string.Format("pnHereNowOccupantData.UUID: {0} ", pnHereNowOccupantData.UUID), PNLoggingMethod.LevelInfo); } } #endif } else { if (objPayload != null) { pnHereNowResult = null; string msg = string.Format("Payload dictionary is not null of type: {0}", objPayload.GetType()); pnStatus = base.CreateErrorResponseFromMessage(msg, requestState, PNStatusCategory.PNMalformedResponseCategory); } else { pnHereNowResult = null; pnStatus = base.CreateErrorResponseFromMessage("Payload dictionary is null", requestState, PNStatusCategory.PNMalformedResponseCategory); } } } } else { pnHereNowResult = null; pnStatus = base.CreateErrorResponseFromMessage("Response dictionary is null", requestState, PNStatusCategory.PNMalformedResponseCategory); } Callback(pnHereNowResult, 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); }