internal void CurrentPubnubInstance(Pubnub instance) { PubnubInstance = instance; if (!MultiChannelSubscribe.ContainsKey(instance.InstanceId)) { MultiChannelSubscribe.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, long>()); } if (!MultiChannelGroupSubscribe.ContainsKey(instance.InstanceId)) { MultiChannelGroupSubscribe.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, long>()); } if (!ChannelRequest.ContainsKey(instance.InstanceId)) { ChannelRequest.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, HttpWebRequest>()); } if (!ChannelInternetStatus.ContainsKey(instance.InstanceId)) { ChannelInternetStatus.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, bool>()); } if (!ChannelGroupInternetStatus.ContainsKey(instance.InstanceId)) { ChannelGroupInternetStatus.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, bool>()); } if (!ChannelLocalUserState.ContainsKey(instance.InstanceId)) { ChannelLocalUserState.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Dictionary <string, object> >()); } if (!ChannelGroupLocalUserState.ContainsKey(instance.InstanceId)) { ChannelGroupLocalUserState.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Dictionary <string, object> >()); } if (!ChannelUserState.ContainsKey(instance.InstanceId)) { ChannelUserState.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Dictionary <string, object> >()); } if (!ChannelGroupUserState.ContainsKey(instance.InstanceId)) { ChannelGroupUserState.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Dictionary <string, object> >()); } if (!ChannelReconnectTimer.ContainsKey(instance.InstanceId)) { ChannelReconnectTimer.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Timer>()); } if (!ChannelGroupReconnectTimer.ContainsKey(instance.InstanceId)) { ChannelGroupReconnectTimer.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Timer>()); } if (!SubscribeDisconnected.ContainsKey(instance.InstanceId)) { SubscribeDisconnected.GetOrAdd(instance.InstanceId, false); } if (!LastSubscribeTimetoken.ContainsKey(instance.InstanceId)) { LastSubscribeTimetoken.GetOrAdd(instance.InstanceId, 0); } if (!SubscribeRequestTracker.ContainsKey(instance.InstanceId)) { SubscribeRequestTracker.GetOrAdd(instance.InstanceId, DateTime.Now); } }
internal void CurrentPubnubInstance(Pubnub instance) { PubnubInstance = instance; if (!ChannelRequest.ContainsKey(instance.InstanceId)) { ChannelRequest.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, HttpWebRequest>()); } if (!ChannelInternetStatus.ContainsKey(instance.InstanceId)) { ChannelInternetStatus.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, bool>()); } if (!ChannelGroupInternetStatus.ContainsKey(instance.InstanceId)) { ChannelGroupInternetStatus.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, bool>()); } if (!ChannelUserState.ContainsKey(instance.InstanceId)) { ChannelUserState.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Dictionary <string, object> >()); } if (!ChannelGroupUserState.ContainsKey(instance.InstanceId)) { ChannelGroupUserState.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Dictionary <string, object> >()); } if (!ChannelLocalUserState.ContainsKey(instance.InstanceId)) { ChannelLocalUserState.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Dictionary <string, object> >()); } if (!ChannelGroupLocalUserState.ContainsKey(instance.InstanceId)) { ChannelGroupLocalUserState.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Dictionary <string, object> >()); } }
public SetStateOperation(PNConfiguration pubnubConfig, IJsonPluggableLibrary jsonPluggableLibrary, IPubnubUnitTest pubnubUnit, IPubnubLog log, EndPoint.TelemetryManager telemetryManager, Pubnub instance) : base(pubnubConfig, jsonPluggableLibrary, pubnubUnit, log, telemetryManager, instance) { config = pubnubConfig; jsonLibrary = jsonPluggableLibrary; unit = pubnubUnit; pubnubLog = log; pubnubTelemetryMgr = telemetryManager; PubnubInstance = instance; if (!ChannelRequest.ContainsKey(instance.InstanceId)) { ChannelRequest.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, HttpWebRequest>()); } if (!ChannelInternetStatus.ContainsKey(instance.InstanceId)) { ChannelInternetStatus.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, bool>()); } if (!ChannelGroupInternetStatus.ContainsKey(instance.InstanceId)) { ChannelGroupInternetStatus.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, bool>()); } if (!ChannelUserState.ContainsKey(instance.InstanceId)) { ChannelUserState.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Dictionary <string, object> >()); } if (!ChannelGroupUserState.ContainsKey(instance.InstanceId)) { ChannelGroupUserState.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Dictionary <string, object> >()); } if (!ChannelLocalUserState.ContainsKey(instance.InstanceId)) { ChannelLocalUserState.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Dictionary <string, object> >()); } if (!ChannelGroupLocalUserState.ContainsKey(instance.InstanceId)) { ChannelGroupLocalUserState.GetOrAdd(instance.InstanceId, new ConcurrentDictionary <string, Dictionary <string, object> >()); } }
private void SharedSetUserState(string[] channels, string[] channelGroups, string uuid, string jsonChannelUserState, string jsonChannelGroupUserState, PNCallback <PNSetStateResult> callback) { List <string> channelList = new List <string>(); List <string> channelGroupList = new List <string>(); if (channels != null && channels.Length > 0) { channelList = new List <string>(channels); channelList = channelList.Where(ch => !string.IsNullOrEmpty(ch) && ch.Trim().Length > 0).Distinct <string>().ToList(); channels = channelList.ToArray(); } if (channelGroups != null && channelGroups.Length > 0) { channelGroupList = new List <string>(channelGroups); channelGroupList = channelGroupList.Where(cg => !string.IsNullOrEmpty(cg) && cg.Trim().Length > 0).Distinct <string>().ToList(); channelGroups = channelGroupList.ToArray(); } string commaDelimitedChannels = (channels != null && channels.Length > 0) ? string.Join(",", channels.OrderBy(x => x).ToArray()) : ""; string commaDelimitedChannelGroups = (channelGroups != null && channelGroups.Length > 0) ? string.Join(",", channelGroups.OrderBy(x => x).ToArray()) : ""; if (string.IsNullOrEmpty(uuid)) { uuid = config.Uuid; } Dictionary <string, object> deserializeChannelUserState = jsonLibrary.DeserializeToDictionaryOfObject(jsonChannelUserState); Dictionary <string, object> deserializeChannelGroupUserState = jsonLibrary.DeserializeToDictionaryOfObject(jsonChannelGroupUserState); for (int channelIndex = 0; channelIndex < channelList.Count; channelIndex++) { string currentChannel = channelList[channelIndex]; ChannelUserState.AddOrUpdate(currentChannel.Trim(), deserializeChannelUserState, (oldState, newState) => deserializeChannelUserState); ChannelLocalUserState.AddOrUpdate(currentChannel.Trim(), deserializeChannelUserState, (oldState, newState) => deserializeChannelUserState); } for (int channelGroupIndex = 0; channelGroupIndex < channelGroupList.Count; channelGroupIndex++) { string currentChannelGroup = channelGroupList[channelGroupIndex]; ChannelGroupUserState.AddOrUpdate(currentChannelGroup.Trim(), deserializeChannelGroupUserState, (oldState, newState) => deserializeChannelGroupUserState); ChannelGroupLocalUserState.AddOrUpdate(currentChannelGroup.Trim(), deserializeChannelGroupUserState, (oldState, newState) => deserializeChannelGroupUserState); } string jsonUserState = "{}"; if (jsonChannelUserState == jsonChannelGroupUserState) { jsonUserState = jsonChannelUserState; } else if (jsonChannelUserState == "{}" && jsonChannelGroupUserState != "{}") { jsonUserState = jsonChannelGroupUserState; } else if (jsonChannelUserState != "{}" && jsonChannelGroupUserState == "{}") { jsonUserState = jsonChannelUserState; } else if (jsonChannelUserState != "{}" && jsonChannelGroupUserState != "{}") { jsonUserState = ""; for (int channelIndex = 0; channelIndex < channelList.Count; channelIndex++) { string currentChannel = channelList[channelIndex]; if (jsonUserState == "") { jsonUserState = string.Format("\"{0}\":{{{1}}}", currentChannel, jsonChannelUserState); } else { jsonUserState = string.Format("{0},\"{1}\":{{{2}}}", jsonUserState, currentChannel, jsonChannelUserState); } } for (int channelGroupIndex = 0; channelGroupIndex < channelGroupList.Count; channelGroupIndex++) { string currentChannelGroup = channelGroupList[channelGroupIndex]; if (jsonUserState == "") { jsonUserState = string.Format("\"{0}\":{{{1}}}", currentChannelGroup, jsonChannelGroupUserState); } else { jsonUserState = string.Format("{0},\"{1}\":{{{2}}}", jsonUserState, currentChannelGroup, jsonChannelGroupUserState); } } jsonUserState = string.Format("{{{0}}}", jsonUserState); //jsonUserState = string.Format("{{\"{0}\":{{{1}}},\"{2}\":{{{3}}}}}", channel, jsonChannelUserState, channelGroup, jsonChannelGroupUserState); } IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit); Uri request = urlBuilder.BuildSetUserStateRequest(commaDelimitedChannels, commaDelimitedChannelGroups, uuid, jsonUserState); RequestState <PNSetStateResult> requestState = new RequestState <PNSetStateResult>(); requestState.Channels = channels; requestState.ChannelGroups = channelGroups; requestState.ResponseType = PNOperationType.PNSetStateOperation; requestState.PubnubCallback = callback; requestState.Reconnect = false; requestState.EndPointOperation = this; //Set TerminateSubRequest to true to bounce the long-polling subscribe requests to update user state string json = UrlProcessRequest <PNSetStateResult>(request, requestState, true); if (!string.IsNullOrEmpty(json)) { List <object> result = ProcessJsonResponse <PNSetStateResult>(requestState, json); ProcessResponseCallbacks(result, requestState); } }