示例#1
0
 private void ReleaseContext(ServerActionContext context)
 {
     if (_contexts.Count < _poolSize)
     {
         context.Reset();
         _contexts.Enqueue(context);
     }
 }
示例#2
0
        public bool Handle(ServerActionContext context, Exception error)
        {
            if (error is BoltServerException)
            {
                HandleBoltServerError(context, error as BoltServerException);
                return(true);
            }

            return(false);
        }
示例#3
0
        public bool Handle(ServerActionContext context, Exception error)
        {
            if (error is BoltServerException)
            {
                HandleBoltServerError(context, error as BoltServerException);
                return true;
            }

            return false;
        }
示例#4
0
        private ServerActionContext CreateContext(RouteContext routeContext)
        {
            ServerActionContext context;

            if (!_contexts.TryDequeue(out context))
            {
                context = new ServerActionContext();
            }

            context.Init(routeContext.HttpContext, Configuration);
            return(context);
        }
示例#5
0
        public virtual Task ExecuteAsync(ServerActionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (Configuration != null)
            {
                context.Configuration.Merge(Configuration);
            }

            return Pipeline.Instance(context);
        }
示例#6
0
        public virtual Task ExecuteAsync(ServerActionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (Configuration != null)
            {
                context.Configuration.Merge(Configuration);
            }

            return(Pipeline.Instance(context));
        }
示例#7
0
        protected virtual void HandleBoltServerError(ServerActionContext actionContext, BoltServerException error)
        {
            int statusCode = 500;

            var response = actionContext.HttpContext.Response;
            response.StatusCode = statusCode;
            if (error.ErrorCode != null)
            {
                response.Headers[actionContext.Configuration.Options.ServerErrorHeader] = error.ErrorCode.Value.ToString(CultureInfo.InvariantCulture);
            }
            else if (error.Error != null)
            {
                response.Headers[actionContext.Configuration.Options.ServerErrorHeader] = error.Error.Value.ToString();
            }

            LogBoltServerError(actionContext, error);
        }
示例#8
0
        protected virtual void HandleBoltServerError(ServerActionContext actionContext, BoltServerException error)
        {
            int statusCode = 500;

            var response = actionContext.HttpContext.Response;

            response.StatusCode = statusCode;
            if (error.ErrorCode != null)
            {
                response.Headers[actionContext.Configuration.Options.ServerErrorHeader] = error.ErrorCode.Value.ToString(CultureInfo.InvariantCulture);
            }
            else if (error.ServerError != null)
            {
                response.Headers[actionContext.Configuration.Options.ServerErrorHeader] = error.ServerError.Value.ToString();
            }

            LogBoltServerError(actionContext, error);
        }
示例#9
0
        private void LogBoltServerError(ServerActionContext context, BoltServerException error)
        {
            if (error.ServerError != null)
            {
                Logger.LogError(
                    BoltLogId.RequestExecutionError,
                    "Execution of '{0}' failed with Bolt error '{1}'",
                    context.Action.Name,
                    error.ServerError);
            }

            if (error.ErrorCode != null)
            {
                Logger.LogError(
                    BoltLogId.RequestExecutionError,
                    "Execution of '{0}' failed with error code '{1}'",
                    context.Action.Name,
                    error.ErrorCode);
            }
        }
示例#10
0
        private void LogBoltServerError(ServerActionContext context, BoltServerException error)
        {
            if (error.Error != null)
            {
                Logger.LogError(
                    BoltLogId.RequestExecutionError,
                    "Execution of '{0}' failed with Bolt error '{1}'",
                    context.Action.Name,
                    error.Error);
            }

            if (error.ErrorCode != null)
            {
                Logger.LogError(
                    BoltLogId.RequestExecutionError,
                    "Execution of '{0}' failed with error code '{1}'",
                    context.Action.Name,
                    error.ErrorCode);
            }
        }
示例#11
0
        protected virtual async Task ExecuteAsync(ServerActionContext ctxt)
        {
            using (Logger.BeginScope("Execute"))
            {
                Stopwatch watch = null;
                if (Logger.IsEnabled(LogLevel.Debug))
                {
                    watch = Stopwatch.StartNew();
                }

                try
                {
                    await ctxt.ContractInvoker.ExecuteAsync(ctxt);
                }
                catch (OperationCanceledException)
                {
                    if (!ctxt.HttpContext.Response.HasStarted)
                    {
                        ctxt.HttpContext.Response.StatusCode = (int)HttpStatusCode.RequestTimeout;
                    }

                    Logger.LogWarning(BoltLogId.RequestCancelled, "Execution of action '{0}' on contract '{1}' has been aborted by client.", ctxt.Action.Name, ctxt.Contract.Name);
                }
                catch (Exception e)
                {
                    Logger.LogError(BoltLogId.RequestExecutionError, "Execution of action '{0}' on contract '{1}' failed with error '{2}'", ctxt.Action.Name, ctxt.Contract.Name, e);
                    throw;
                }
                finally
                {
                    if (watch != null)
                    {
                        Logger.LogDebug(BoltLogId.RequestExecutionTime, "Execution of action '{0}' on contract '{1}' has taken '{2}ms'", ctxt.Action.Name, ctxt.Contract.Name, watch.ElapsedMilliseconds);
                    }
                }
            }
        }
示例#12
0
 protected virtual IBoltFeature AssignBoltFeature(ServerActionContext actionContext)
 {
     actionContext.HttpContext.Features.Set <IBoltFeature>(actionContext);
     return(actionContext);
 }