public async Task <object> Invoke(CancellationToken token) { var stopwatch = new Stopwatch(); var result = default(object); var workerData = _actionInvoker is IActionInvokerData data ? data.Data : default(object); try { stopwatch.Start(); result = await _actionInvoker.Invoke(token); stopwatch.Stop(); _progress.Report(new WorkerProgressData { Duration = stopwatch.ElapsedMilliseconds, Index = _index, Result = result, Data = workerData }); } catch (TaskCanceledException ex) { stopwatch.Stop(); _progress.Report(new WorkerProgressData { Duration = stopwatch.ElapsedMilliseconds, Index = _index, IsError = true, IsCancelled = true, Data = workerData, Error = ex }); throw; } catch (Exception ex) { stopwatch.Stop(); _progress.Report(new WorkerProgressData { Duration = stopwatch.ElapsedMilliseconds, Index = _index, IsError = true, Data = workerData, Error = ex }); throw; } return(result); }
private void OnMessage(IMessage message) { if (!message.IsResponse) { IActionInvoker invoker = this; invoker.Invoke(message).ContinueWith((t) => channelDispatcher.Post(t.Result)); } }
public async Task <object> Invoke(TData data, CancellationToken token) { try { var result = await _actionInvoker.Invoke(data, token); return(result); } finally { _counterBlocked.Decremenet(); } }
protected virtual async Task ProcessMessage(IActionInvoker actionInvoker, CancellationToken cancellationToken) { var stopwatch = Stopwatch.StartNew(); await actionInvoker.Invoke(cancellationToken).ContinueWith(async actionResultTask => { stopwatch.Stop(); if (actionResultTask.IsCanceled || actionResultTask.IsFaulted) { _workerHandler.HandleError(actionResultTask.Exception, stopwatch.ElapsedMilliseconds, actionResultTask.IsCanceled); } else { var result = await actionResultTask; _workerHandler.HandleResult(result, stopwatch.ElapsedMilliseconds); } }); }
/// <summary> /// 拦截方法的调用 /// </summary> /// <param name="actionInvoker">action执行器</param> /// <param name="arguments">方法的参数集合</param> /// <returns></returns> public object Intercept(IActionInvoker actionInvoker, object?[] arguments) { return(actionInvoker.Invoke(this.context, arguments)); }
/// <summary> /// Gets called by ASP.NET framework /// </summary> /// <param name="httpCtx">Instance of <see cref="HttpContext"/> provided by ASP.NET framework</param> /// <returns></returns> public async Task Invoke(HttpContext httpCtx) { httpCtx.SetLiteApiOptions(Options); ILogger log = new ContextAwareLogger(_isLoggingEnabled, _logger, httpCtx.TraceIdentifier); log.LogInformation($"Received request: {httpCtx.Request.Path} with query: {httpCtx.Request.QueryString.ToString() ?? ""}"); if (Options.RequiresHttps && !httpCtx.Request.IsHttps) { log.LogInformation("LiteApi options are set to require HTTPS, request rejected because request is HTTP"); httpCtx.Response.StatusCode = 400; await httpCtx.Response.WriteAsync("Bad request, HTTPS request was expected."); return; } if (Options.DiscoveryEnabled) { bool handledOnDiscovery = await _discoveryHandler.HandleIfNeeded(httpCtx); if (handledOnDiscovery) { return; } } ActionContext action = _pathResolver.ResolveAction(httpCtx.Request, log); if (action == null) { log.LogInformation("Request is skipped to next middleware"); if (_next != null) { log.LogInformation("Invoking next middleware"); await _next?.Invoke(httpCtx); log.LogInformation("Next middleware invoked"); } else { log.LogInformation("There is no next middleware to invoke"); } } else { // TODO: consider replacing RequiresHttps with global filter httpCtx.SetActionContext(action); if (!(await CheckGlobalFiltersAndWriteResponseIfAny(httpCtx, log, action.SkipAuth))) { return; } await _actionInvoker.Invoke(httpCtx, action, log); log.LogInformation("Action is invoked"); } log.LogInformation("Request is processed"); }
protected virtual async Task <IMessage> InvokeAsync(IMessage message, IActionInvoker invoker) { return(await invoker.Invoke(message)); }
public Task <IMessage> APICall(IMessage message, IActionInvoker invoker) { return(Task.Run(async() => await invoker.Invoke(message))); }
public void Invoke(Type[] valueTypes, object[] values) { _invoker.Invoke(valueTypes, values); }
public virtual Task <HttpResponseMessage> Invoke() { var handler = _container.GetInstance(_actionMethod.HandlerTypeDescriptor.Type); return(_actionInvoker.Invoke(handler)); }
public virtual Task <HttpResponseMessage> Invoke() { var handler = _container.GetInstance(_requestContext.Action.HandlerType.Type); return(_actionInvoker.Invoke(handler)); }
public virtual async Task <object> Invoke(CancellationToken token) { return(await _actionInvoker.Invoke(_data, token)); }