Example #1
0
 internal static void ResponseCallbackWebExceptionHandler <T> (CustomEventArgs <T> cea, RequestState <T> requestState,
                                                               WebException webEx, string channel, SafeDictionary <PubnubChannelCallbackKey, object> channelCallbacks,
                                                               PubnubErrorFilter.Level errorLevel)
 {
     if (requestState.Channels != null || requestState.RespType == ResponseType.Time)
     {
         if (requestState.RespType == ResponseType.Subscribe ||
             requestState.RespType == ResponseType.Presence)
         {
             if (webEx.Message.IndexOf("The request was aborted: The request was canceled") == -1 ||
                 webEx.Message.IndexOf("Machine suspend mode enabled. No request will be processed.") == -1)
             {
                 PubnubCallbacks.FireErrorCallbacksForAllChannels <T> (webEx, requestState,
                                                                       PubnubErrorSeverity.Warn, channelCallbacks,
                                                                       true, errorLevel);
             }
         }
         else
         {
             PubnubCallbacks.CallErrorCallback <T> (webEx, requestState, channel,
                                                    PubnubErrorSeverity.Warn, requestState.ErrorCallback, errorLevel);
         }
     }
     ProcessResponseCallbackWebExceptionHandler <T> (webEx, requestState, channel, errorLevel);
 }
Example #2
0
        internal static void ResponseCallbackErrorOrTimeoutHandler <T> (CustomEventArgs <T> cea, RequestState <T> requestState, string channel,
                                                                        PubnubErrorFilter.Level errorLevel, IJsonPluggableLibrary jsonPluggableLibrary)
        {
            WebException webEx = new WebException(cea.Message);

            if ((cea.Message.Contains("NameResolutionFailure") ||
                 cea.Message.Contains("ConnectFailure") ||
                 cea.Message.Contains("ServerProtocolViolation") ||
                 cea.Message.Contains("ProtocolError")
                 ))
            {
                webEx = new WebException("Network connnect error", WebExceptionStatus.ConnectFailure);

                PubnubCallbacks.CallErrorCallback <T> (cea.Message, null, channel,
                                                       PubnubErrorCode.NoInternetRetryConnect, PubnubErrorSeverity.Warn, requestState.ErrorCallback, errorLevel);
            }
            else if (cea.IsTimeout || Utility.CheckRequestTimeoutMessageInError(cea))
            {
            }
            else if ((cea.Message.Contains("403")) ||
                     (cea.Message.Contains("java.io.FileNotFoundException")) ||
                     ((PubnubUnity.Version.Contains("UnityWeb")) && (cea.Message.Contains("Failed downloading"))))
            {
                PubnubClientError error = new PubnubClientError(403, PubnubErrorSeverity.Critical, cea.Message, PubnubMessageSource.Server, requestState.Request, requestState.Response, cea.Message, channel);
                PubnubCallbacks.GoToCallback(error, requestState.ErrorCallback, jsonPluggableLibrary);
            }
            else if (cea.Message.Contains("500"))
            {
                PubnubClientError error = new PubnubClientError(500, PubnubErrorSeverity.Critical, cea.Message, PubnubMessageSource.Server, requestState.Request, requestState.Response, cea.Message, channel);
                PubnubCallbacks.GoToCallback(error, requestState.ErrorCallback, jsonPluggableLibrary);
            }
            else if (cea.Message.Contains("502"))
            {
                PubnubClientError error = new PubnubClientError(503, PubnubErrorSeverity.Critical, cea.Message, PubnubMessageSource.Server, requestState.Request, requestState.Response, cea.Message, channel);
                PubnubCallbacks.GoToCallback(error, requestState.ErrorCallback, jsonPluggableLibrary);
            }
            else if (cea.Message.Contains("503"))
            {
                PubnubClientError error = new PubnubClientError(503, PubnubErrorSeverity.Critical, cea.Message, PubnubMessageSource.Server, requestState.Request, requestState.Response, cea.Message, channel);
                PubnubCallbacks.GoToCallback(error, requestState.ErrorCallback, jsonPluggableLibrary);
            }
            else if (cea.Message.Contains("504"))
            {
                PubnubClientError error = new PubnubClientError(504, PubnubErrorSeverity.Critical, cea.Message, PubnubMessageSource.Server, requestState.Request, requestState.Response, cea.Message, channel);
                PubnubCallbacks.GoToCallback(error, requestState.ErrorCallback, jsonPluggableLibrary);
            }
            else if (cea.Message.Contains("414"))
            {
                PubnubClientError error = new PubnubClientError(414, PubnubErrorSeverity.Critical, cea.Message, PubnubMessageSource.Server, requestState.Request, requestState.Response, cea.Message, channel);
                PubnubCallbacks.GoToCallback(error, requestState.ErrorCallback, jsonPluggableLibrary);
            }
            else
            {
                PubnubClientError error = new PubnubClientError(400, PubnubErrorSeverity.Critical, cea.Message, PubnubMessageSource.Server, requestState.Request, requestState.Response, cea.Message, channel);
                PubnubCallbacks.GoToCallback(error, requestState.ErrorCallback, jsonPluggableLibrary);
            }
            ProcessResponseCallbackWebExceptionHandler <T> (webEx, requestState, channel, errorLevel);
        }
Example #3
0
        internal static void CreateErrorCodeAndCallErrorCallback <T> (int statusCode, CustomEventArgs <T> cea, RequestState <T> requestState,
                                                                      PubnubErrorFilter.Level errorLevel)
        {
            PubnubClientError error = new PubnubClientError(statusCode, PubnubErrorSeverity.Critical, cea.Message, PubnubMessageSource.Server,
                                                            requestState.Request, requestState.Response, cea.Message, requestState.ChannelEntities);

            PubnubCallbacks.CallErrorCallback <T> (requestState.ErrorCallback, requestState.ChannelEntities,
                                                   error, errorLevel);
        }
Example #4
0
        internal static void PushNotificationExceptionHandler <T>(string[] channels, bool requestTimeout,
                                                                  Action <PubnubClientError> errorCallback, PubnubErrorFilter.Level errorLevel)
        {
            string channel = "";

            if (channels != null)
            {
                channel = string.Join(",", channels);
            }
            if (requestTimeout)
            {
                string message = (requestTimeout) ? "Operation Timeout" : "Network connnect error";
                #if (ENABLE_PUBNUB_LOGGING)
                LoggingMethod.WriteToLog(string.Format("DateTime {0}, PushExceptionHandler response={1}", DateTime.Now.ToString(), message), LoggingMethod.LevelInfo);
                #endif
                PubnubCallbacks.CallErrorCallback <T>(message, null, channel,
                                                      PubnubErrorCode.PushNotificationTimeout, PubnubErrorSeverity.Critical, errorCallback, errorLevel);
            }
        }
Example #5
0
        internal static object DecodeMessage(PubnubCrypto aes, object element, string[] channels,
                                             Action <PubnubClientError> errorCallback, IJsonPluggableLibrary jsonPluggableLibrary,
                                             PubnubErrorFilter.Level errorLevel)
        {
            string decryptMessage = "";

            try {
                decryptMessage = aes.Decrypt(element.ToString());
            }
            catch (Exception ex) {
                decryptMessage = "**DECRYPT ERROR**";
                string multiChannel = string.Join(",", channels);
                PubnubCallbacks.CallErrorCallback <object> (ex, null, multiChannel, PubnubErrorCode.None,
                                                            PubnubErrorSeverity.Critical, errorCallback, errorLevel);
            }
            object decodeMessage = (decryptMessage == "**DECRYPT ERROR**") ? decryptMessage : jsonPluggableLibrary.DeserializeToObject(decryptMessage);

            return(decodeMessage);
        }
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 void ProcessWrapResultBasedOnResponseTypeException <T> (ResponseType type, string[] channels,
                                                                         Action <PubnubClientError> errorCallback, SafeDictionary <PubnubChannelCallbackKey, object> channelCallbacks,
                                                                         PubnubErrorFilter.Level errorLevel, Exception ex)
 {
     if (channels != null)
     {
         if (type == ResponseType.Subscribe || type == ResponseType.Presence)
         {
             PubnubCallbacks.FireErrorCallbacksForAllChannels <T> (ex, channels, PubnubErrorSeverity.Critical,
                                                                   channelCallbacks, false, PubnubErrorCode.None, type, errorLevel);
         }
         else
         {
             if (errorCallback != null)
             {
                 PubnubCallbacks.CallErrorCallback <T> (ex, null, string.Join(",", channels), PubnubErrorCode.None,
                                                        PubnubErrorSeverity.Critical, errorCallback, errorLevel);
             }
         }
     }
 }
Example #8
0
        internal static void CommonExceptionHandler <T> (string message, string channelName, bool requestTimeout,
                                                         Action <PubnubClientError> errorCallback, PubnubErrorFilter.Level errorLevel, ResponseType responseType)
        {
            if (requestTimeout)
            {
                message = "Operation Timeout";
                #if (ENABLE_PUBNUB_LOGGING)
                LoggingMethod.WriteToLog(string.Format("DateTime {0}, {1} response={2}", DateTime.Now.ToString(), responseType.ToString(), message), LoggingMethod.LevelInfo);
                #endif

                PubnubCallbacks.CallErrorCallback <T> (message, null, channelName,
                                                       Helpers.GetTimeOutErrorCode(responseType), PubnubErrorSeverity.Critical, errorCallback, errorLevel);
            }
            else
            {
                #if (ENABLE_PUBNUB_LOGGING)
                LoggingMethod.WriteToLog(string.Format("DateTime {0}, {1} response={2}", DateTime.Now.ToString(), responseType.ToString(), message), LoggingMethod.LevelInfo);
                #endif

                PubnubCallbacks.CallErrorCallback <T> (message, null, channelName,
                                                       PubnubErrorCode.None, PubnubErrorSeverity.Critical, errorCallback, errorLevel);
            }
        }
Example #9
0
 internal static void ResponseCallbackExceptionHandler <T> (CustomEventArgs <T> cea, RequestState <T> requestState,
                                                            Exception ex, string channel, SafeDictionary <PubnubChannelCallbackKey, object> channelCallbacks,
                                                            PubnubErrorFilter.Level errorLevel)
 {
     #if (ENABLE_PUBNUB_LOGGING)
     LoggingMethod.WriteToLog(string.Format("DateTime {0}, Process Response Exception: = {1}", DateTime.Now.ToString(), ex.ToString()), LoggingMethod.LevelError);
     #endif
     if (requestState.Channels != null)
     {
         if (requestState.RespType == ResponseType.Subscribe ||
             requestState.RespType == ResponseType.Presence)
         {
             PubnubCallbacks.FireErrorCallbacksForAllChannels(ex, requestState,
                                                              PubnubErrorSeverity.Warn, channelCallbacks,
                                                              false, PubnubErrorCode.None, errorLevel);
         }
         else
         {
             PubnubCallbacks.CallErrorCallback <T> (ex, requestState, channel,
                                                    PubnubErrorCode.None, PubnubErrorSeverity.Critical, requestState.ErrorCallback, errorLevel);
         }
     }
     ProcessResponseCallbackExceptionHandler <T> (ex, requestState, errorLevel);
 }
Example #10
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);
 }