/// <summary> /// Invokes the middleware to controls the specified request. /// </summary> #pragma warning disable CA1822 public async SystemTask InvokeAsync(WebFramework.HttpContext context) { WebFramework.HttpRequest request = context.Request; if (request != null && TryExtractRuntime(request, out CoyoteRuntime runtime)) { IO.Debug.WriteLine("<Coyote> Runtime '{0}' takes control of the '{1} {2}' handler on thread '{3}'.", runtime.Id, request.Method, request.Path, SystemThread.CurrentThread.ManagedThreadId); TryExtractSourceOperation(request, runtime, out ControlledOperation source); var op = HttpOperation.Create(ToHttpMethod(request.Method), request.Path, runtime, source); OperationGroup.SetCurrent(op.Group); await runtime.TaskFactory.StartNew(state => { SystemTask task = this.Next(context); runtime.WaitUntilTaskCompletes(task); task.GetAwaiter().GetResult(); }, op,