Esempio n. 1
0
        /// <summary>
        /// Handles the error.
        /// </summary>
        /// <param name="exceptionContext">The exception context.</param>
        protected virtual void HandleError(ExceptionContext exceptionContext)
        {
            var httpContext = exceptionContext.HttpContext;

            // Bail if we can't do anything; propogate the error for further processing.
            if (httpContext == null)
            {
                return;
            }

            if (!ShouldRenderErrors(httpContext))
            {
                return;
            }

            if (!CustomRenderingBehaviourRequired)
            {
                return;
            }

            if (exceptionContext.ExceptionHandled)
            {
                return;
            }

            if (httpContext.IsCustomErrorEnabled)
            {
                exceptionContext.ExceptionHandled = true;
            }

            var innerException = exceptionContext.Exception;

            ExceptionHandlerFactory.Create().HandleException(innerException, httpContext);
        }
Esempio n. 2
0
        public virtual bool HandleException(Exception ex, SearchQueryRequest searchQueryRequest)
        {
            ExceptionHandler handler = ExceptionHandlerFactory.Create(Cmdlet, ex);

            retryHandler.DelegateHandler = handler;

            return(retryHandler.HandleException(ex, searchQueryRequest));
        }
Esempio n. 3
0
        public ExecuteResult <T> Post <T>(object model)
        {
            if (model == null)
            {
                throw new Exception("model could not be null");
            }

            try
            {
                _request.Timeout          = (int)TimeSpan.FromMinutes(15).TotalMilliseconds;
                _request.ReadWriteTimeout = (int)TimeSpan.FromMinutes(15).TotalMilliseconds;
                _request.Method           = "POST";
                _request.ContentType      = "application/json";

                var    jsonObject  = JsonConvert.SerializeObject(model);
                byte[] requestData = Encoding.UTF8.GetBytes(jsonObject);

                using (Stream requesStream = _request.GetRequestStream())
                {
                    requesStream.Write(requestData, 0, requestData.Length);
                }

                using (HttpWebResponse response = (HttpWebResponse)_request.GetResponse())
                {
                    var responseStream = response.GetResponseStream();

                    if (responseStream == null)
                    {
                        return new ExecuteResult <T>
                               {
                                   Status = response.StatusCode
                               }
                    }
                    ;

                    var responseData = _responseHandler.Handle <T>(responseStream);

                    return(new ExecuteResult <T>
                    {
                        Status = HttpStatusCode.OK,
                        Data = responseData.Data,
                        Content = responseData.Content
                    });
                }
            }
            catch (Exception ex)
            {
                var exceptionHandlerFactory = new ExceptionHandlerFactory();

                var exceptionHandler = exceptionHandlerFactory.Create(ex);

                return(exceptionHandler.Handle <T>(ex));
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Called when [application error].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        void OnError(object sender, EventArgs e)
        {
            var application      = (HttpApplication)sender;
            var error            = application.Server.GetLastError();
            var exceptionHandler = ExceptionHandlerFactory.Create();

            var context = new HttpContextWrapper(HttpContext.Current);

            if (context.IsCustomErrorEnabled)
            {
                Logger.Write(new Log(error).GetExceptionInfo(context));
            }

            exceptionHandler.HandleException(error, context);
        }
Esempio n. 5
0
        public ExecuteResult <T> Get <T>()
        {
            try
            {
                _request.Timeout          = (int)TimeSpan.FromMinutes(15).TotalMilliseconds;
                _request.ReadWriteTimeout = (int)TimeSpan.FromMinutes(15).TotalMilliseconds;
                _request.Method           = "GET";
                _request.ContentType      = "application/x-www-form-urlencoded";

                using (HttpWebResponse response = (HttpWebResponse)_request.GetResponse())
                {
                    var responseStream = response.GetResponseStream();

                    if (responseStream == null)
                    {
                        return new ExecuteResult <T>
                               {
                                   Status = response.StatusCode
                               }
                    }
                    ;


                    var responseData = _responseHandler.Handle <T>(responseStream);

                    return(new ExecuteResult <T>
                    {
                        Data = responseData.Data,
                        Status = response.StatusCode,
                        Content = responseData.Content
                    });
                }
            }
            catch (Exception ex)
            {
                var exceptionHandlerFactory = new ExceptionHandlerFactory();

                var exceptionHandler = exceptionHandlerFactory.Create(ex);

                return(exceptionHandler.Handle <T>(ex));
            }
        }