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); }
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); }
protected bool CreateFetchMessagesResult(object objChannelsDict, out Dictionary <string, List <PNMessageResult> > channelsResult) { Dictionary <string, object> channelsDict = objChannelsDict as Dictionary <string, object>; channelsResult = new Dictionary <string, List <PNMessageResult> >(); if (channelsDict != null) { foreach (KeyValuePair <string, object> kvpair in channelsDict) { string channelName = kvpair.Key; #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateFetchMessagesResult: \nChannel {0}", channelName), PNLoggingMethod.LevelInfo); #endif if (channelsResult.ContainsKey(channelName)) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateFetchMessagesResult: Channel name {0} exists in dict, continuing.", channelName), PNLoggingMethod.LevelInfo); #endif continue; } object[] channelDetails = kvpair.Value as object[]; #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateFetchMessagesResult: channelDetails {0}", channelDetails.Length), PNLoggingMethod.LevelInfo); #endif List <PNMessageResult> lstMessageResult = new List <PNMessageResult>(); foreach (object messageData in channelDetails) { Dictionary <string, object> messageDataDict = messageData as Dictionary <string, object>; if (messageDataDict != null) { object objPayload; messageDataDict.TryGetValue("message", out objPayload); object meta; if (messageDataDict.TryGetValue("meta", out meta)) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateFetchMessagesResult: meta {0}.", meta.ToString()), PNLoggingMethod.LevelInfo); #endif } object objTimetoken; long timetoken = 0; if (messageDataDict.TryGetValue("timetoken", out objTimetoken)) { if (long.TryParse(objTimetoken.ToString(), out timetoken)) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateFetchMessagesResult: timetoken {0}.", timetoken.ToString()), PNLoggingMethod.LevelInfo); #endif } } if (!string.IsNullOrEmpty(this.PubNubInstance.PNConfig.CipherKey) && (this.PubNubInstance.PNConfig.CipherKey.Length > 0)) { //TODO: handle exception objPayload = Helpers.DecodeMessage(this.PubNubInstance.PNConfig.CipherKey, objPayload, OperationType, this.PubNubInstance); } PNMessageResult pnMessageResult = new PNMessageResult( channelName, channelName, objPayload, timetoken, timetoken, meta, "" ); object objMessageType; if (messageDataDict.TryGetValue("message_type", out objMessageType)) { int messageType; if (int.TryParse(objMessageType.ToString(), out messageType)) { #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("CreateFetchMessagesResult: messageType {0}.", messageType.ToString()), PNLoggingMethod.LevelInfo); #endif } pnMessageResult.MessageType = messageType; } object objUUID; if (messageDataDict.TryGetValue("uuid", out objUUID)) { pnMessageResult.IssuingClientId = objUUID.ToString(); } pnMessageResult.MessageActions = MessageActionsHelpers.ExtractMessageActions(messageDataDict); lstMessageResult.Add(pnMessageResult); } } channelsResult.Add(channelName, lstMessageResult); } return(true); } return(false); }