private void ExtractMessageWithTimetokens(object element, string cipherKey, out PNHistoryItemResult pnHistoryItemResult) { //[[{"message":{"text":"hey"},"timetoken":14985452911089049}],14985452911089049,14985452911089049] //[[{"message":{"text":"hey"},"timetoken":14986549102032676},{"message":"E8VOcbfrYqLyHMtoVGv9UQ==","timetoken":14986619049105442},{"message":"E8VOcbfrYqLyHMtoVGv9UQ==","timetoken":14986619291068634}],14986549102032676,14986619291068634] pnHistoryItemResult = new PNHistoryItemResult(); Dictionary <string, object> historyMessage = element as Dictionary <string, object>; #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("ExtractMessageWithTimetokens: historyMessage {0}", historyMessage), PNLoggingMethod.LevelInfo); #endif object v; historyMessage.TryGetValue("message", out v); if (!string.IsNullOrEmpty(cipherKey) && (cipherKey.Length > 0)) { //TODO: handle exception pnHistoryItemResult.Entry = Helpers.DecodeMessage(cipherKey, v, OperationType, this.PubNubInstance); } else { pnHistoryItemResult.Entry = v; } #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("ExtractMessageWithTimetokens: v {0}", pnHistoryItemResult.Entry), PNLoggingMethod.LevelInfo); #endif object t; historyMessage.TryGetValue("timetoken", out t); pnHistoryItemResult.Timetoken = Utility.ValidateTimetoken(t.ToString(), false); #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("ExtractMessageWithTimetokens: t {0}", t), PNLoggingMethod.LevelInfo); #endif }
private void ExtractMessage(object element, string cipherKey, out PNHistoryItemResult pnHistoryItemResult) { //[[{"text":"hey"}],14985452911089049,14985452911089049] //[[{"text":"hey"},"E8VOcbfrYqLyHMtoVGv9UQ==","E8VOcbfrYqLyHMtoVGv9UQ=="],14986549102032676,14986619291068634] pnHistoryItemResult = new PNHistoryItemResult(); if (!string.IsNullOrEmpty(cipherKey) && (cipherKey.Length > 0)) { //TODO: handle exception pnHistoryItemResult.Entry = Helpers.DecodeMessage(cipherKey, element, OperationType, this.PubNubInstance); } else { pnHistoryItemResult.Entry = element; } #if (ENABLE_PUBNUB_LOGGING) this.PubNubInstance.PNLog.WriteToLog(string.Format("ExtractMessage: v {0}", pnHistoryItemResult.Entry), PNLoggingMethod.LevelInfo); #endif }
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); } }
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); }