Example #1
0
 public object GetStoredRequestState(CurrentRequestType aKey)
 {
     if (requestStates.ContainsKey(aKey))
     {
         if (requestStates.ContainsKey(aKey))
         {
             #if (ENABLE_PUBNUB_LOGGING)
             LoggingMethod.WriteToLog(string.Format("DateTime {0}, GetStoredRequestState {1}",
                                                    DateTime.Now.ToString(), aKey.ToString()), LoggingMethod.LevelInfo);
             #endif
             return(requestStates [aKey]);
         }
         #if (ENABLE_PUBNUB_LOGGING)
         LoggingMethod.WriteToLog(string.Format("DateTime {0}, GetStoredRequestState returning false", DateTime.Now.ToString()), LoggingMethod.LevelInfo);
         #endif
     }
     #if (ENABLE_PUBNUB_LOGGING)
     else
     {
         LoggingMethod.WriteToLog(string.Format("DateTime {0}, GetStoredRequestState doesnt contain key {1}",
                                                DateTime.Now.ToString(), aKey.ToString()), LoggingMethod.LevelInfo);
     }
     #endif
     return(null);
 }
Example #2
0
        internal static void SendCallbacksBasedOnType <T>(SafeDictionary <PubnubChannelCallbackKey, object> channelCallbacks,
                                                          IJsonPluggableLibrary jsonPluggableLibrary, string currentChannel, List <object> itemMessage)
        {
            var callbackKey = PubnubCallbacks.GetPubnubChannelCallbackKey(currentChannel,
                                                                          (Utility.IsPresenceChannel(currentChannel)) ? ResponseType.Presence : ResponseType.Subscribe);

            #if (ENABLE_PUBNUB_LOGGING)
            LoggingMethod.WriteToLog(string.Format("DateTime {0}, currentChannel: {1}", DateTime.Now.ToString(),
                                                   currentChannel.ToString()), LoggingMethod.LevelInfo);
            #endif
            if (channelCallbacks.Count > 0 && channelCallbacks.ContainsKey(callbackKey))
            {
                #if (ENABLE_PUBNUB_LOGGING)
                LoggingMethod.WriteToLog(string.Format("DateTime {0}, typeof(T): {1}", DateTime.Now.ToString(), typeof(T).ToString()), LoggingMethod.LevelInfo);
                #endif
                if ((typeof(T) == typeof(string) && channelCallbacks[callbackKey].GetType().Name.Contains("[System.String]")) ||
                    (typeof(T) == typeof(object) && channelCallbacks[callbackKey].GetType().Name.Contains("[System.Object]")))
                {
                    CallCallback <T>(callbackKey, channelCallbacks, jsonPluggableLibrary, itemMessage);
                }
                else if (channelCallbacks[callbackKey].GetType().FullName.Contains("[System.String"))
                {
                    CallCallbackKnownType <string>(callbackKey, channelCallbacks, jsonPluggableLibrary, itemMessage);
                }
                else if (channelCallbacks[callbackKey].GetType().FullName.Contains("[System.Object"))
                {
                    CallCallbackKnownType <object>(callbackKey, channelCallbacks, jsonPluggableLibrary, itemMessage);
                }
            }
        }
Example #3
0
        internal static void FireErrorCallback <T> (string activeChannel, SafeDictionary <PubnubChannelCallbackKey,
                                                                                          object> channelCallbacks, bool callbackObjectType, ResponseType responseType, PubnubErrorFilter.Level errorLevel,
                                                    PubnubClientError error)
        {
            var callbackKey = GetPubnubChannelCallbackKey(activeChannel, responseType);
            PubnubChannelCallback <T> currentPubnubCallback = null;

            if (channelCallbacks.Count > 0 && channelCallbacks.ContainsKey(callbackKey))
            {
                if (callbackObjectType)
                {
                    object callbackObject;
                    bool   channelAvailable = channelCallbacks.TryGetValue(callbackKey, out callbackObject);

                    if (channelAvailable)
                    {
                        currentPubnubCallback = callbackObject as PubnubChannelCallback <T>;
                    }
                }
                else
                {
                    currentPubnubCallback = channelCallbacks [callbackKey] as PubnubChannelCallback <T>;
                }
                if (currentPubnubCallback != null && currentPubnubCallback.ErrorCallback != null)
                {
                    GoToCallback(error, currentPubnubCallback.ErrorCallback, errorLevel);
                }
            }
        }
Example #4
0
        internal static void SendConnectCallback <T> (IJsonPluggableLibrary jsonPluggableLibrary,
                                                      List <object> connectResult, string channel, ResponseType type, SafeDictionary <PubnubChannelCallbackKey, object> channelCallbacks)
        {
            var callbackKey = GetPubnubChannelCallbackKey(channel, type);

            if (channelCallbacks.Count > 0 && channelCallbacks.ContainsKey(callbackKey))
            {
                PubnubChannelCallback <T> currentPubnubCallback = channelCallbacks [callbackKey] as PubnubChannelCallback <T>;
                if (currentPubnubCallback != null && currentPubnubCallback.ConnectCallback != null)
                {
                    PubnubCallbacks.GoToCallback <T> (connectResult, currentPubnubCallback.ConnectCallback, jsonPluggableLibrary);
                }
            }
        }
Example #5
0
 public void Add(ChannelEntity channelEntity, bool reset)
 {
     if (!channelEntitiesDictionary.ContainsKey(channelEntity.ChannelID))
     {
         channelEntity.ChannelParams.IsSubscribed = true;
         channelEntitiesDictionary.Add(channelEntity.ChannelID, channelEntity.ChannelParams);
         #if (ENABLE_PUBNUB_LOGGING)
         LoggingMethod.WriteToLog(string.Format("DateTime {0}, Add: channelEntities key add {1} {2} {3}", DateTime.Now.ToString(),
                                                channelEntity.ChannelID.ChannelOrChannelGroupName, channelEntity.ChannelID.IsChannelGroup,
                                                channelEntity.ChannelParams.IsSubscribed
                                                ), LoggingMethod.LevelInfo);
         #endif
     }
     else
     {
         channelEntitiesDictionary [channelEntity.ChannelID].Callbacks = channelEntity.ChannelParams.Callbacks;
         channelEntitiesDictionary [channelEntity.ChannelID].IsAwaitingConnectCallback = channelEntity.ChannelParams.IsAwaitingConnectCallback;
         channelEntitiesDictionary [channelEntity.ChannelID].IsSubscribed      = true;
         channelEntitiesDictionary [channelEntity.ChannelID].TypeParameterType = channelEntity.ChannelParams.TypeParameterType;
         Dictionary <string, object> userState = channelEntitiesDictionary [channelEntity.ChannelID].UserState;
         if (userState == null)
         {
             channelEntitiesDictionary [channelEntity.ChannelID].UserState = channelEntity.ChannelParams.UserState;
         }
         #if (ENABLE_PUBNUB_LOGGING)
         LoggingMethod.WriteToLog(string.Format("DateTime {0}, Add: channelEntities key update {1} {2} {3}", DateTime.Now.ToString(),
                                                channelEntity.ChannelID.ChannelOrChannelGroupName, channelEntity.ChannelID.IsChannelGroup,
                                                channelEntity.ChannelParams.IsSubscribed
                                                ), LoggingMethod.LevelInfo);
         #endif
     }
     if (reset)
     {
         ResetChannelsAndChannelGroupsAndBuildState();
     }
 }
Example #6
0
        internal static List <string> GetValidChannels <T>(ResponseType type, Action <PubnubClientError> errorCallback,
                                                           string[] rawChannels, SafeDictionary <string, long> multiChannelSubscribe, PubnubErrorFilter.Level errorLevel)
        {
            List <string> validChannels = new List <string>();

            if (rawChannels.Length > 0)
            {
                for (int index = 0; index < rawChannels.Length; index++)
                {
                    if (rawChannels[index].Trim().Length > 0)
                    {
                        string channelName = rawChannels[index].Trim();
                        if (type == ResponseType.PresenceUnsubscribe)
                        {
                            channelName = string.Format("{0}{1}", channelName, Utility.PresenceChannelSuffix);
                        }
                        if (!multiChannelSubscribe.ContainsKey(channelName))
                        {
                            string          message   = string.Format("{0}Channel Not Subscribed", (Utility.IsPresenceChannel(channelName)) ? "Presence " : "");
                            PubnubErrorCode errorType = (Utility.IsPresenceChannel(channelName)) ? PubnubErrorCode.NotPresenceSubscribed : PubnubErrorCode.NotSubscribed;
                            #if (ENABLE_PUBNUB_LOGGING)
                            LoggingMethod.WriteToLog(string.Format("DateTime {0}, channel={1} unsubscribe response={2}", DateTime.Now.ToString(), channelName, message), LoggingMethod.LevelInfo);
                            #endif
                            PubnubCallbacks.CallErrorCallback <T>(message, null, channelName, errorType, PubnubErrorSeverity.Info, errorCallback, errorLevel);
                        }
                        else
                        {
                            validChannels.Add(channelName);
                        }
                    }
                    else
                    {
                        string message = "Invalid Channel Name For Unsubscribe";
                        #if (ENABLE_PUBNUB_LOGGING)
                        LoggingMethod.WriteToLog(string.Format("DateTime {0}, channel={1} unsubscribe response={2}", DateTime.Now.ToString(), rawChannels[index], message), LoggingMethod.LevelInfo);
                        #endif
                        PubnubCallbacks.CallErrorCallback <T>(message, null, rawChannels[index].ToString(), PubnubErrorCode.InvalidChannel, PubnubErrorSeverity.Info, errorCallback, errorLevel);
                    }
                }
            }
            return(validChannels);
        }
Example #7
0
 internal static bool CheckChannelsInMultiChannelSubscribeRequest(string multiChannel,
                                                                  SafeDictionary <string, long> multiChannelSubscribe, SafeDictionary <string, PubnubWebRequest> channelRequest)
 {
     if (!channelRequest.ContainsKey(multiChannel))
     {
         #if (ENABLE_PUBNUB_LOGGING)
         LoggingMethod.WriteToLog(string.Format("DateTime {0}, MultiChannelSubscribeRequest _channelRequest doesnt contain {1}", DateTime.Now.ToString(), multiChannel), LoggingMethod.LevelInfo);
         #endif
         string[] currentChannels = multiChannelSubscribe.Keys.ToArray <string>();
         if (currentChannels != null && currentChannels.Length > 0)
         {
             #if (ENABLE_PUBNUB_LOGGING)
             string currentSubChannels = string.Join(",", currentChannels);
             LoggingMethod.WriteToLog(string.Format("DateTime {0}, using existing channels: {1}", DateTime.Now.ToString(), currentSubChannels), LoggingMethod.LevelInfo);
             #endif
         }
         else
         {
             return(true);
         }
     }
     return(false);
 }
Example #8
0
 internal static List <string> RemoveDuplicateChannelsAndCheckForAlreadySubscribedChannels <T>(ResponseType type,
                                                                                               string channel, Action <PubnubClientError> errorCallback, string[] rawChannels, List <string> validChannels,
                                                                                               bool networkConnection, SafeDictionary <string, long> multiChannelSubscribe, PubnubErrorFilter.Level errorLevel)
 {
     if (rawChannels.Length > 0 && networkConnection)
     {
         if (rawChannels.Length != rawChannels.Distinct().Count())
         {
             rawChannels = rawChannels.Distinct().ToArray();
             string message = "Detected and removed duplicate channels";
             PubnubCallbacks.CallErrorCallback <T>(message, null, channel, PubnubErrorCode.DuplicateChannel, PubnubErrorSeverity.Info, errorCallback, errorLevel);
         }
         for (int index = 0; index < rawChannels.Length; index++)
         {
             if (rawChannels[index].Trim().Length > 0)
             {
                 string channelName = rawChannels[index].Trim();
                 if (type == ResponseType.Presence)
                 {
                     channelName = string.Format("{0}{1}", channelName, Utility.PresenceChannelSuffix);
                 }
                 if (multiChannelSubscribe.ContainsKey(channelName))
                 {
                     string          message   = string.Format("{0}Already subscribed", (Utility.IsPresenceChannel(channelName)) ? "Presence " : "");
                     PubnubErrorCode errorType = (Utility.IsPresenceChannel(channelName)) ? PubnubErrorCode.AlreadyPresenceSubscribed : PubnubErrorCode.AlreadySubscribed;
                     PubnubCallbacks.CallErrorCallback <T>(message, null, channelName.Replace(Utility.PresenceChannelSuffix, ""), errorType, PubnubErrorSeverity.Info, errorCallback, errorLevel);
                 }
                 else
                 {
                     validChannels.Add(channelName);
                 }
             }
         }
     }
     return(validChannels);
 }