public async Task <object> Connect(TContext context, CancellationToken cancellationToken) { try { await _specification.BeforeExecute(context, cancellationToken); await _specification.Execute(context, cancellationToken); if (Next != null) { await Next.Connect(context, cancellationToken); } else { if (context.TryGetService(out IMediator mediator)) { await mediator.PublishAsync(context.Message, cancellationToken); } else { throw new MediatorIsNotAddedToTheContextException(); } } await _specification.AfterExecute(context, cancellationToken); } catch (Exception e) { await _specification.OnException(e, context); } return(null); }
public async Task <object> Connect(TContext context, CancellationToken cancellationToken) { object result = null; try { await _specification.BeforeExecute(context, cancellationToken); await _specification.Execute(context, cancellationToken); if (Next != null) { await Next.Connect(context, cancellationToken); } else { result = await ConnectToPipe(context, cancellationToken); } await _specification.AfterExecute(context, cancellationToken); return(result); } catch (Exception e) { _specification.OnException(e, context); } return(result); }
public async Task <object> Connect(TContext context, CancellationToken cancellationToken) { object result = null; try { await _specification.BeforeExecute(context, cancellationToken).ConfigureAwait(false); await _specification.Execute(context, cancellationToken).ConfigureAwait(false); if (Next != null) { result = await Next.Connect(context, cancellationToken).ConfigureAwait(false); } else { result = await ConnectToPipe(context, cancellationToken).ConfigureAwait(false); } await _specification.AfterExecute(context, cancellationToken).ConfigureAwait(false); return(result); } catch (Exception e) { var task = _specification.OnException(e, context); result = PipeHelper.GetResultFromTask(task); } return(result); }
public async Task <object> Connect(TContext context, CancellationToken cancellationToken) { try { await _specification.BeforeExecute(context, cancellationToken); await _specification.Execute(context, cancellationToken); await(Next?.Connect(context, cancellationToken) ?? ConnectToHandler(context, cancellationToken)); await _specification.AfterExecute(context, cancellationToken); } catch (Exception e) { _specification.OnException(e, context); } return(null); }
public async Task <object> Connect(TContext context, CancellationToken cancellationToken) { object result = null; try { await _specification.BeforeExecute(context, cancellationToken); await _specification.Execute(context, cancellationToken); result = await(Next?.Connect(context, cancellationToken) ?? ConnectToHandler(context, cancellationToken)); await _specification.AfterExecute(context, cancellationToken); } catch (Exception e) { var task = _specification.OnException(e, context); result = PipeHelper.GetResultFromTask(task); } return(result); }