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); }
public static PubnubErrorCode GetErrorType(int statusCode, string httpErrorCodeMessage) { PubnubErrorCode ret = PubnubErrorCode.None; switch (statusCode) { case 400: if (httpErrorCodeMessage.ToUpper().Contains("MESSAGE TOO LARGE")) { ret = PubnubErrorCode.MessageTooLarge; } else if (httpErrorCodeMessage.ToUpper() == "INVALID KEY") { ret = PubnubErrorCode.InvalidKey; } else if (httpErrorCodeMessage.ToUpper() == "BADREQUEST") { ret = PubnubErrorCode.BadRequest; } else if (httpErrorCodeMessage.ToUpper() == "NO UUID SPECIFIED") { ret = PubnubErrorCode.NoUuidSpecified; } else if (httpErrorCodeMessage.ToUpper() == "INVALID TIMESTAMP") { ret = PubnubErrorCode.InvalidTimestamp; } else if (httpErrorCodeMessage.ToUpper() == "INVALID TYPE ARGUMENT") { ret = PubnubErrorCode.InvalidTypeArgument; } else if (httpErrorCodeMessage.ToUpper() == "CHANNEL GROUP OR GROUPS RESULT IN EMPTY SUBSCRIPTION SET") { ret = PubnubErrorCode.EmptyGroupSubscription; } else if (httpErrorCodeMessage.ToUpper() == "COULD NOT PARSE REQUEST") { ret = PubnubErrorCode.CouldNotParseRequest; } break; case 401: ret = PubnubErrorCode.InvalidSubscribeKey; break; case 402: if (httpErrorCodeMessage.ToUpper() == "NOT ENABLED") { ret = PubnubErrorCode.PamNotEnabled; } break; case 403: if (httpErrorCodeMessage.ToUpper() == "FORBIDDEN") { ret = PubnubErrorCode.Forbidden; } else if (httpErrorCodeMessage.ToUpper() == "SIGNATURE DOES NOT MATCH") { ret = PubnubErrorCode.SignatureDoesNotMatch; } break; case 404: ret = PubnubErrorCode.NotFound; break; case 414: ret = PubnubErrorCode.RequestUriTooLong; break; case 500: ret = PubnubErrorCode.InternalServerError; break; case 502: ret = PubnubErrorCode.BadGateway; break; case 503: ret = PubnubErrorCode.ServiceUnavailable; break; case 504: ret = PubnubErrorCode.GatewayTimeout; break; default: ret = PubnubErrorCode.None; break; } return(ret); }
public static PubnubErrorCode GetErrorType(int statusCode, string httpErrorCodeMessage) { PubnubErrorCode ret = PubnubErrorCode.None; switch (statusCode) { case 400: if (httpErrorCodeMessage.ToUpper().Equals("MESSAGE TOO LARGE")) { ret = PubnubErrorCode.MessageTooLarge; } else if (httpErrorCodeMessage.ToUpper().Equals("INVALID KEY")) { ret = PubnubErrorCode.InvalidKey; } else if (httpErrorCodeMessage.ToUpper().Equals("BADREQUEST")) { ret = PubnubErrorCode.BadRequest; } else if (httpErrorCodeMessage.ToUpper().Equals("NO UUID SPECIFIED")) { ret = PubnubErrorCode.NoUuidSpecified; } else if (httpErrorCodeMessage.ToUpper().Equals("INVALID TIMESTAMP")) { ret = PubnubErrorCode.InvalidTimestamp; } break; case 401: ret = PubnubErrorCode.InvalidSubscribeKey; break; case 402: if (httpErrorCodeMessage.ToUpper().Equals("NOT ENABLED")) { ret = PubnubErrorCode.PamNotEnabled; } break; case 403: if (httpErrorCodeMessage.ToUpper().Equals("FORBIDDEN")) { ret = PubnubErrorCode.Forbidden; } else if (httpErrorCodeMessage.ToUpper().Equals("SIGNATURE DOES NOT MATCH")) { ret = PubnubErrorCode.SignatureDoesNotMatch; } break; case 404: ret = PubnubErrorCode.NotFound; break; case 414: ret = PubnubErrorCode.RequestUriTooLong; break; case 500: ret = PubnubErrorCode.InternalServerError; break; case 502: ret = PubnubErrorCode.BadGateway; break; case 503: ret = PubnubErrorCode.ServiceUnavailable; break; case 504: ret = PubnubErrorCode.GatewayTimeout; break; default: ret = PubnubErrorCode.None; break; } return(ret); }
public static string GetStatusCodeDescription(PubnubErrorCode pubnubErrorCode) { string defaultDescription = "Please contact PubNub support with your error object details"; int key = (int)pubnubErrorCode; string description = dictionaryCodes.ContainsKey(key) ? dictionaryCodes[key] : defaultDescription; return description; }
internal static PubnubClientError CreatePubnubClientError <T>(string message, RequestState <T> requestState, string channel, PubnubErrorCode errorCode, PubnubErrorSeverity severity) { int statusCode = (int)errorCode; string errorDescription = PubnubErrorCodeDescription.GetStatusCodeDescription(errorCode); PubnubClientError error = new PubnubClientError(statusCode, severity, message, PubnubMessageSource.Client, (requestState == null)?null:requestState.Request, (requestState == null)?null:requestState.Response, errorDescription, channel); #if (ENABLE_PUBNUB_LOGGING) LoggingMethod.WriteToLog(string.Format("DateTime {0}, PubnubClientError = {1}", DateTime.Now.ToString(), error.ToString()), LoggingMethod.LevelInfo); #endif return(error); }
public static PubnubErrorCode GetErrorType(Exception ex) { PubnubErrorCode ret = PubnubErrorCode.None; string errorType = ex.GetType().ToString(); string errorMessage = ex.Message; if (errorType == "System.FormatException" && errorMessage == "Invalid length for a Base-64 char array or string.") { ret = PubnubErrorCode.PubnubMessageDecryptException; } else if (errorType == "System.FormatException" && errorMessage == "The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. ") { ret = PubnubErrorCode.PubnubMessageDecryptException; } else if (errorType == "System.ObjectDisposedException" && errorMessage == "Cannot access a disposed object.") { ret = PubnubErrorCode.PubnubObjectDisposedException; } else if (errorType == "System.Net.Sockets.SocketException" && errorMessage == "The requested name is valid, but no data of the requested type was found") { ret = PubnubErrorCode.PubnubSocketConnectException; } else if (errorType == "System.Net.Sockets.SocketException" && errorMessage == "No such host is known") { ret = PubnubErrorCode.PubnubSocketConnectException; } else if (errorType == "System.Security.Cryptography.CryptographicException" && errorMessage == "Padding is invalid and cannot be removed.") { ret = PubnubErrorCode.PubnubCryptographicException; } else if (errorType == "System.Runtime.InteropServices.SEHException" && errorMessage == "External component has thrown an exception.") { ret = PubnubErrorCode.PubnubInterOpSEHException; } else if (errorType == "System.Net.WebException" && errorMessage.Contains("The remote name could not be resolved:")) { ret = PubnubErrorCode.NameResolutionFailure; } else if (errorType == "System.Net.WebException" && errorMessage.Contains("Unable to connect to the remote server")) { ret = PubnubErrorCode.NameResolutionFailure; } else if (errorType == "System.Net.WebException" && errorMessage.Contains("Unable to read data from the transport connection")) { ret = PubnubErrorCode.ConnectFailure; } else if (errorType == "System.Net.WebException" && errorMessage.Contains("SecureChannelFailure")) { ret = PubnubErrorCode.ConnectFailure; } else if (errorType == "System.Net.WebException" && errorMessage.Contains("ConnectFailure")) { ret = PubnubErrorCode.ConnectFailure; } else if (errorType == "System.Net.WebException" && errorMessage.Contains("ReceiveFailure")) { ret = PubnubErrorCode.ConnectFailure; } else if (errorType == "System.Net.WebException" && errorMessage.Contains("SendFailure")) { ret = PubnubErrorCode.ConnectFailure; } else { //Console.WriteLine("ATTENTION: Error Type = " + errorType); //Console.WriteLine("ATTENTION: Error Message = " + errorMessage); ret = PubnubErrorCode.None; } return(ret); }
internal static void CallErrorCallback <T>(string message, Action <PubnubClientError> errorCallback, PubnubErrorCode errorCode, PubnubErrorSeverity severity, PubnubErrorFilter.Level errorLevel) { //request state can be null PubnubClientError clientError = Helpers.CreatePubnubClientError <T> (message, null, null, errorCode, severity); GoToCallback(clientError, errorCallback, errorLevel); }
public static PubnubErrorCode GetErrorType(WebExceptionStatus webExceptionStatus, string webExceptionMessage) { PubnubErrorCode ret = PubnubErrorCode.None; switch (webExceptionStatus) { //#if ((!__MonoCS__) && (!SILVERLIGHT) && !WINDOWS_PHONE && !NETFX_CORE) //case WebExceptionStatus.NameResolutionFailure: //ret = PubnubErrorCode.NameResolutionFailure; //break; //case WebExceptionStatus.ProtocolError: //ret = PubnubErrorCode.ProtocolError; //break; //case WebExceptionStatus.ServerProtocolViolation: //ret = PubnubErrorCode.ServerProtocolViolation; //break; //case WebExceptionStatus.ReceiveFailure: //ret = PubnubErrorCode.ReceiveFailure; //break; //#endif case WebExceptionStatus.RequestCanceled: ret = PubnubErrorCode.WebRequestCanceled; break; case WebExceptionStatus.ConnectFailure: ret = PubnubErrorCode.ConnectFailure; break; case WebExceptionStatus.SendFailure: ret = PubnubErrorCode.ConnectFailure; break; case WebExceptionStatus.Pending: if (webExceptionMessage == "Machine suspend mode enabled. No request will be processed.") { ret = PubnubErrorCode.PubnubClientMachineSleep; } break; case WebExceptionStatus.Success: ret = PubnubErrorCode.ConnectFailure; break; default: #if NETFX_CORE if (webExceptionStatus.ToString() == "NameResolutionFailure") { ret = PubnubErrorCode.NameResolutionFailure; } else { Debug.WriteLine("ATTENTION: webExceptionStatus = " + webExceptionStatus.ToString()); ret = PubnubErrorCode.None; } #else if (webExceptionStatus.ToString() == "SecureChannelFailure") { ret = PubnubErrorCode.ConnectFailure; } else { Debug.WriteLine("ATTENTION: webExceptionStatus = " + webExceptionStatus.ToString()); ret = PubnubErrorCode.None; } #endif break; } return(ret); }
internal static void FireErrorCallbacksForAllChannels <T> (string message, RequestState <T> requestState, PubnubErrorSeverity severity, PubnubErrorCode errorType, PubnubErrorFilter.Level errorLevel) { FireErrorCallbacksForAllChannelsCommon <T> (null, message, requestState, requestState.ChannelEntities, severity, errorType, requestState.RespType, errorLevel ); }
internal static void CallErrorCallback <T>(Exception ex, List <ChannelEntity> channelEntities, PubnubErrorCode errorCode, PubnubErrorSeverity severity, PubnubErrorFilter.Level errorLevel) { PubnubClientError clientError = Helpers.CreatePubnubClientError <T> (ex, null, channelEntities, errorCode, severity); CallCallbackForEachChannelEntity <T> (channelEntities, clientError, errorLevel); }
internal static void FireErrorCallbacksForAllChannelsCommon <T>(Exception ex, string message, RequestState <T> requestState, List <ChannelEntity> channelEntities, PubnubErrorSeverity severity, PubnubErrorCode errorType, ResponseType responseType, PubnubErrorFilter.Level errorLevel) { if ((channelEntities != null) && (channelEntities.Count > 0)) { foreach (ChannelEntity channelEntity in channelEntities) { string channel = ""; string channelGroup = ""; if (channelEntity.ChannelID.IsChannelGroup) { channelGroup = channelEntity.ChannelID.ChannelOrChannelGroupName; } else { channel = channelEntity.ChannelID.ChannelOrChannelGroupName; } PubnubClientError error = null; if (ex != null) { error = Helpers.CreatePubnubClientError <T> (ex, requestState, errorType, severity, channel, channelGroup); } else { error = Helpers.CreatePubnubClientError <T> (message, requestState, errorType, severity, channel, channelGroup); } FireErrorCallback <T> (channelEntity, errorLevel, error); } } else { if ((requestState != null) && (requestState.ErrorCallback != null)) { PubnubClientError error = null; if (ex != null) { error = Helpers.CreatePubnubClientError <T> (ex, requestState, errorType, severity, "", ""); } else { error = Helpers.CreatePubnubClientError <T> (message, requestState, errorType, severity, "", ""); } GoToCallback(error, requestState.ErrorCallback, errorLevel); } #if (ENABLE_PUBNUB_LOGGING) else { LoggingMethod.WriteToLog(string.Format("DateTime {0}, FireErrorCallbacksForAllChannelsCommon: {1}", DateTime.Now.ToString(), (requestState != null)?"ErrorCallback null":"requestState null" ), LoggingMethod.LevelInfo); } LoggingMethod.WriteToLog(string.Format("DateTime {0}, FireErrorCallbacksForAllChannelsCommon: channelEntities count: {1}", DateTime.Now.ToString(), (channelEntities != null)?channelEntities.Count.ToString():"channelEntities null" ), LoggingMethod.LevelInfo); #endif } }
internal static void FireErrorCallbacksForAllChannels <T> (Exception ex, RequestState <T> requestState, PubnubErrorSeverity severity, PubnubErrorCode errorType, PubnubErrorFilter.Level errorLevel) { FireErrorCallbacksForAllChannelsCommon <T> (ex, "", requestState, requestState.ChannelEntities, severity, errorType, requestState.RespType, errorLevel ); }
public static PubnubErrorCode GetErrorType(WebExceptionStatus webExceptionStatus, string webExceptionMessage) { PubnubErrorCode ret = PubnubErrorCode.None; switch (webExceptionStatus) { case WebExceptionStatus.NameResolutionFailure: ret = PubnubErrorCode.NameResolutionFailure; break; case WebExceptionStatus.ProtocolError: ret = PubnubErrorCode.ProtocolError; break; case WebExceptionStatus.ServerProtocolViolation: ret = PubnubErrorCode.ServerProtocolViolation; break; case WebExceptionStatus.ReceiveFailure: ret = PubnubErrorCode.ReceiveFailure; break; case WebExceptionStatus.SecureChannelFailure: ret = PubnubErrorCode.ReceiveFailure; break; case WebExceptionStatus.RequestCanceled: ret = PubnubErrorCode.WebRequestCanceled; break; case WebExceptionStatus.ConnectFailure: ret = PubnubErrorCode.ConnectFailure; break; case WebExceptionStatus.TrustFailure: ret = PubnubErrorCode.TrustFailure; break; case WebExceptionStatus.Timeout: ret = PubnubErrorCode.RequestTimeout; break; case WebExceptionStatus.Pending: if (webExceptionMessage == "Machine suspend mode enabled. No request will be processed.") { ret = PubnubErrorCode.PubnubClientMachineSleep; } break; default: #if NETFX_CORE if (webExceptionStatus.ToString() == "NameResolutionFailure") { ret = PubnubErrorCode.NameResolutionFailure; } else { Debug.WriteLine("ATTENTION: webExceptionStatus = " + webExceptionStatus.ToString()); ret = PubnubErrorCode.None; } #else Debug.WriteLine("ATTENTION: webExceptionStatus = " + webExceptionStatus.ToString()); ret = PubnubErrorCode.None; #endif break; } return(ret); }
internal static void CallErrorCallback <T>(string message, RequestState <T> requestState, string channel, PubnubErrorCode errorCode, PubnubErrorSeverity severity, Action <PubnubClientError> errorCallback, PubnubErrorFilter.Level errorLevel) { PubnubClientError clientError = Helpers.CreatePubnubClientError <T> (message, requestState, channel, errorCode, severity); GoToCallback(clientError, errorCallback, errorLevel); }
internal static void FireErrorCallbacksForAllChannels <T> (string message, RequestState <T> requestState, string[] channels, PubnubErrorSeverity severity, SafeDictionary <PubnubChannelCallbackKey, object> channelCallbacks, bool callbackObjectType, PubnubErrorCode errorType, ResponseType responseType, PubnubErrorFilter.Level errorLevel) { for (int index = 0; index < channels.Length; index++) { string activeChannel = channels [index].ToString(); PubnubClientError error = Helpers.CreatePubnubClientError <T> (message, requestState, activeChannel, errorType, severity); PubnubCallbacks.FireErrorCallback <T> (activeChannel, channelCallbacks, callbackObjectType, responseType, errorLevel, error); } }