void CreateSession(IAsyncPipeContextAgent <SessionContext> asyncContext, CancellationToken cancellationToken) { IPipe <ConnectionContext> connectionPipe = Pipe.ExecuteAsync <ConnectionContext>(async connectionContext => { if (_log.IsDebugEnabled) { _log.DebugFormat("Creating session: {0}", connectionContext.Description); } try { var session = await connectionContext.CreateSession().ConfigureAwait(false); var sessionContext = new ActiveMqSessionContext(connectionContext, session, _host, cancellationToken); await asyncContext.Created(sessionContext).ConfigureAwait(false); await asyncContext.Completed.ConfigureAwait(false); } catch (OperationCanceledException) { await asyncContext.CreateCanceled().ConfigureAwait(false); } catch (Exception exception) { await asyncContext.CreateFaulted(exception).ConfigureAwait(false); } }); _connectionCache.Send(connectionPipe, cancellationToken).ConfigureAwait(false); }
async Task <ModelContext> 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 model = await connectionContext.CreateModel().ConfigureAwait(false); var modelContext = new RabbitMqModelContext(connectionContext, model, _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); } }); _connectionCache.Send(connectionPipe, cancellationToken).ConfigureAwait(false); return(await asyncContext.Context.ConfigureAwait(false)); }
void CreateSession(IAsyncPipeContextAgent <SessionContext> asyncContext, CancellationToken cancellationToken) { IPipe <ConnectionContext> connectionPipe = Pipe.ExecuteAsync <ConnectionContext>(async connectionContext => { if (_log.IsDebugEnabled) { _log.DebugFormat("Creating session: {0}", connectionContext.Description); } try { var session = await connectionContext.CreateSession().ConfigureAwait(false); var sessionContext = new ActiveMqSessionContext(connectionContext, session, _host, cancellationToken); void HandleException(Exception exception) { var disposeAsync = sessionContext.DisposeAsync(CancellationToken.None); } connectionContext.Connection.ExceptionListener += HandleException; asyncContext.Completed.ContinueWith(task => { connectionContext.Connection.ExceptionListener -= HandleException; }); await asyncContext.Created(sessionContext).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); }
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); }