Ejemplo n.º 1
0
        private static void ParseCheckSocketConnectException <T>(Exception ex, PNOperationType type, PNCallback <T> callback, Action <bool> internalcallback)
        {
            PNStatusCategory errorCategory = PNStatusCategoryHelper.GetPNStatusCategory(ex);
            StatusBuilder    statusBuilder = new StatusBuilder(pubnubConfig, jsonLib);
            PNStatus         status        = statusBuilder.CreateStatusResponse <T>(type, errorCategory, null, (int)System.Net.HttpStatusCode.NotFound, new PNException(ex));

            if (callback != null)
            {
                callback.OnResponse(default(T), status);
            }

            LoggingMethod.WriteToLog(pubnubLog, string.Format("DateTime {0} ParseCheckSocketConnectException Error. {1}", DateTime.Now.ToString(CultureInfo.InvariantCulture), ex.Message), pubnubConfig.LogVerbosity);
            internalcallback(false);
        }
Ejemplo n.º 2
0
 public override void OnResponse(PNFileUploadResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }
Ejemplo n.º 3
0
        public PNStatus CreateStatusResponse <T>(PNOperationType type, PNStatusCategory category, RequestState <T> asyncRequestState, int statusCode, PNException throwable)
        {
            int           serverErrorStatusCode       = 0;
            bool          serverErrorMessage          = false;
            List <string> serverAffectedChannels      = null;
            List <string> serverAffectedChannelGroups = null;

            PNStatus status = new PNStatus(asyncRequestState != null ? asyncRequestState.EndPointOperation : null);

            status.Category  = category;
            status.Operation = type;

            if ((asyncRequestState != null && !asyncRequestState.GotJsonResponse) || throwable != null)
            {
                status.Error = true;
            }

            Exception targetException = null;

            if (throwable != null)
            {
                if (throwable.DirectException)
                {
                    targetException = throwable.InnerException;
                }
                else
                {
                    targetException = throwable as Exception;
                }
            }

            if (targetException != null)
            {
                if (targetException.InnerException != null)
                {
                    PNErrorData errorData = new PNErrorData(jsonLibrary.SerializeToJsonString(targetException.InnerException.Message), targetException);
                    status.ErrorData = errorData;
                }
                else
                {
                    Dictionary <string, object> deserializeStatus = jsonLibrary.DeserializeToDictionaryOfObject(targetException.Message);
                    if (deserializeStatus != null && deserializeStatus.Count >= 1 &&
                        deserializeStatus.ContainsKey("error") && string.Equals(deserializeStatus["error"].ToString(), "true", StringComparison.CurrentCultureIgnoreCase) &&
                        deserializeStatus.ContainsKey("status") && Int32.TryParse(deserializeStatus["status"].ToString(), out serverErrorStatusCode))
                    {
                        serverErrorMessage = true;
                        if (deserializeStatus.ContainsKey("payload"))
                        {
                            Dictionary <string, object> payloadDic = jsonLibrary.ConvertToDictionaryObject(deserializeStatus["payload"]);
                            if (payloadDic != null && payloadDic.Count > 0)
                            {
                                if (payloadDic.ContainsKey("channels"))
                                {
                                    object[] chDic = jsonLibrary.ConvertToObjectArray(payloadDic["channels"]);
                                    if (chDic != null && chDic.Length > 0)
                                    {
                                        serverAffectedChannels = chDic.Select(x => x.ToString()).ToList();
                                    }
                                }

                                if (payloadDic.ContainsKey("channel-groups"))
                                {
                                    object[] cgDic = jsonLibrary.ConvertToObjectArray(payloadDic["channel-groups"]);
                                    if (cgDic != null && cgDic.Length > 0)
                                    {
                                        serverAffectedChannelGroups = cgDic.Select(x => x.ToString()).ToList();
                                    }
                                }
                            }
                        }
                    }

                    PNErrorData errorData = new PNErrorData(jsonLibrary.SerializeToJsonString(targetException.Message), targetException);
                    status.ErrorData = errorData;
                }
            }

            if (asyncRequestState != null)
            {
                if (asyncRequestState.Request != null)
                {
                    status.ClientRequest = asyncRequestState.Request;

                    HttpValueCollection restUriQueryCollection = HttpUtility.ParseQueryString(asyncRequestState.Request.RequestUri.Query);
                    if (restUriQueryCollection.ContainsKey("auth"))
                    {
                        string auth = restUriQueryCollection["auth"];
                        status.AuthKey = auth;
                    }
                    if (restUriQueryCollection.ContainsKey("uuid"))
                    {
                        string uuid = restUriQueryCollection["uuid"];
                        status.Uuid = uuid;
                    }
                }

                if (serverErrorMessage && serverErrorStatusCode > 0)
                {
                    status.StatusCode = serverErrorStatusCode;
                }
                else if (asyncRequestState.Response != null)
                {
                    status.StatusCode = (int)asyncRequestState.Response.StatusCode;
                }
                else
                {
                    status.StatusCode = statusCode;
                }

                if (serverErrorMessage)
                {
                    status.AffectedChannels      = serverAffectedChannels;
                    status.AffectedChannelGroups = serverAffectedChannelGroups;
                }
                else
                {
                    if (asyncRequestState.ChannelGroups != null)
                    {
                        status.AffectedChannelGroups = asyncRequestState.ChannelGroups.ToList <string>();
                    }

                    if (asyncRequestState.Channels != null)
                    {
                        status.AffectedChannels = asyncRequestState.Channels.ToList <string>();
                    }
                }
            }
            else
            {
                status.StatusCode = statusCode;
            }

            if (status.StatusCode == 403)
            {
                status.Category = PNStatusCategory.PNAccessDeniedCategory;
            }


            status.Origin     = config.Origin;
            status.TlsEnabled = config.Secure;

            return(status);
        }
 public override void OnResponse(PNPushListProvisionsResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }
Ejemplo n.º 5
0
 public override void Status(Pubnub pubnub, PNStatus status)
 {
     statusAction?.Invoke(pubnub, status);
 }
Ejemplo n.º 6
0
 public abstract void OnResponse(T result, PNStatus status);
Ejemplo n.º 7
0
 public override void OnResponse(PNFetchHistoryResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }
 public override void OnResponse(PNChannelGroupsRemoveChannelResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }
Ejemplo n.º 9
0
 public abstract void Status(Pubnub pubnub, PNStatus status);
Ejemplo n.º 10
0
 public override void OnResponse(PNUpdateSpaceResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }
Ejemplo n.º 11
0
 public override void OnResponse(PNRemoveChannelMetadataResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }
Ejemplo n.º 12
0
 public override void OnResponse(PNGetMembershipsResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }
Ejemplo n.º 13
0
 public override void OnResponse(PNCreateUserResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }
Ejemplo n.º 14
0
        public PNStatus CreateStatusResponse <T>(PNOperationType type, PNStatusCategory category, RequestState <T> asyncRequestState, int statusCode, Exception throwable)
        {
            PNStatus status = new PNStatus(asyncRequestState != null ? asyncRequestState.EndPointOperation : null);

            status.Category  = category;
            status.Operation = type;

            if ((asyncRequestState != null && !asyncRequestState.GotJsonResponse) || throwable != null)
            {
                status.Error = true;
            }

            if (throwable != null)
            {
                if (throwable.InnerException != null)
                {
                    PNErrorData errorData = new PNErrorData(throwable.InnerException.Message, throwable);
                    status.ErrorData = errorData;
                }
                else
                {
                    PNErrorData errorData = new PNErrorData(throwable.Message, throwable);
                    status.ErrorData = errorData;
                }
            }

            if (asyncRequestState != null)
            {
                if (asyncRequestState.Request != null)
                {
                    status.ClientRequest = asyncRequestState.Request;

                    HttpValueCollection restUriQueryCollection = HttpUtility.ParseQueryString(asyncRequestState.Request.RequestUri.Query);
                    if (restUriQueryCollection.ContainsKey("auth"))
                    {
                        string auth = restUriQueryCollection["auth"];
                        status.AuthKey = auth;
                    }
                    if (restUriQueryCollection.ContainsKey("uuid"))
                    {
                        string uuid = restUriQueryCollection["uuid"];
                        status.Uuid = uuid;
                    }
                }

                if (asyncRequestState.Response != null)
                {
                    status.StatusCode = (int)asyncRequestState.Response.StatusCode;
                }
                else
                {
                    status.StatusCode = statusCode;
                }

                if (asyncRequestState.ChannelGroups != null)
                {
                    status.AffectedChannelGroups = asyncRequestState.ChannelGroups.ToList <string>();
                }

                if (asyncRequestState.Channels != null)
                {
                    status.AffectedChannels = asyncRequestState.Channels.ToList <string>();
                }
            }
            else
            {
                status.StatusCode = statusCode;
            }
            status.Origin     = config.Origin;
            status.TlsEnabled = config.Secure;

            return(status);
        }
Ejemplo n.º 15
0
 public override void OnResponse(PNAccessManagerAuditResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }
 public override void OnResponse(PNDeleteMessageResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }
Ejemplo n.º 17
0
 public override void OnResponse(PNPushAddChannelResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }
Ejemplo n.º 18
0
 public override void OnResponse(PNSetUuidMetadataResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }
Ejemplo n.º 19
0
 public override void OnResponse(PNHereNowResult result, PNStatus status)
 {
     callbackAction?.Invoke(result, status);
 }