async Task IFilter <ConnectionContext> .Send(ConnectionContext context, IPipe <ConnectionContext> next) { var amazonSqs = await context.CreateAmazonSqs().ConfigureAwait(false); var amazonSns = await context.CreateAmazonSns().ConfigureAwait(false); var modelContext = new AmazonSqsModelContext(context, amazonSqs, amazonSns, _host, context.CancellationToken); try { await _pipe.Send(modelContext).ConfigureAwait(false); } finally { await modelContext.DisposeAsync(CancellationToken.None).ConfigureAwait(false); } await next.Send(context).ConfigureAwait(false); }
void CreateModel(IAsyncPipeContextAgent <ModelContext> asyncContext, CancellationToken cancellationToken) { IPipe <ConnectionContext> connectionPipe = Pipe.ExecuteAsync <ConnectionContext>(async connectionContext => { if (_log.IsDebugEnabled) { _log.DebugFormat("Creating model: {0}", connectionContext.Description); } try { var amazonSqs = await connectionContext.CreateAmazonSqs().ConfigureAwait(false); var amazonSns = await connectionContext.CreateAmazonSns().ConfigureAwait(false); var modelContext = new AmazonSqsModelContext(connectionContext, amazonSqs, amazonSns, _host, cancellationToken); await asyncContext.Created(modelContext).ConfigureAwait(false); await asyncContext.Completed.ConfigureAwait(false); } catch (OperationCanceledException) { await asyncContext.CreateCanceled().ConfigureAwait(false); } catch (Exception exception) { await asyncContext.CreateFaulted(exception).ConfigureAwait(false); } }); var connectionTask = _connectionCache.Send(connectionPipe, cancellationToken); Task NotifyCreateCanceled(Task task) => asyncContext.CreateCanceled(); connectionTask.ContinueWith(NotifyCreateCanceled, TaskContinuationOptions.OnlyOnCanceled); Task NotifyCreateFaulted(Task task) => asyncContext.CreateFaulted(task.Exception); connectionTask.ContinueWith(NotifyCreateFaulted, TaskContinuationOptions.OnlyOnFaulted); }