public override TPayload GetOrAddPayload <TPayload>(PayloadFactory <TPayload> payloadFactory) { TPayload payload; if (_context.TryGetPayload(out payload)) { return(payload); } if (base.TryGetPayload(out payload)) { return(payload); } return(_context.GetOrAddPayload(() => payloadFactory())); }
async Task Faulted(BehaviorContext <TInstance> context) { ConsumeContext consumeContext; if (!context.TryGetPayload(out consumeContext)) { throw new ContextException("The consume context could not be retrieved."); } MessageSchedulerContext schedulerContext; if (!consumeContext.TryGetPayload(out schedulerContext)) { throw new ContextException("The scheduler context could not be retrieved."); } var previousTokenId = _schedule.GetTokenId(context.Instance); if (previousTokenId.HasValue) { await schedulerContext.CancelScheduledSend(previousTokenId.Value).ConfigureAwait(false); _schedule.SetTokenId(context.Instance, default(Guid?)); } }
async Task Execute(BehaviorContext <TInstance> context) { ConsumeContext consumeContext; if (!context.TryGetPayload(out consumeContext)) { throw new ContextException("The consume context could not be retrieved."); } var consumeEventContext = new AutomatonymousConsumeEventContext <TInstance>(context, consumeContext); TMessage message = _messageFactory(consumeEventContext); MessageSchedulerContext schedulerContext; if (!consumeContext.TryGetPayload(out schedulerContext)) { throw new ContextException("The scheduler context could not be retrieved."); } var scheduledMessage = await schedulerContext.ScheduleSend(message, _schedule.Delay, _sendPipe); var previousTokenId = _schedule.GetTokenId(context.Instance); if (previousTokenId.HasValue) { await schedulerContext.CancelScheduledSend(previousTokenId.Value); } _schedule?.SetTokenId(context.Instance, scheduledMessage.TokenId); }
public override bool TryGetPayload <TPayload>(out TPayload context) { if (_context.TryGetPayload(out context)) { return(true); } return(base.TryGetPayload(out context)); }
public static ConsumeEventContext <TInstance, TData> CreateConsumeContext <TInstance, TData>(this BehaviorContext <TInstance, TData> context) where TData : class { if (!context.TryGetPayload(out ConsumeContext <TData> consumeContext)) { throw new ArgumentException("The ConsumeContext was not available"); } return(new AutomatonymousConsumeEventContext <TInstance, TData>(context, consumeContext)); }
static ConsumeContext GetConsumeContext <TInstance>(BehaviorContext <TInstance> context) { ConsumeContext consumeContext; if (context.TryGetPayload(out consumeContext)) { return(consumeContext); } throw new ArgumentException("The ConsumeContext was not present", nameof(context)); }
public async Task Execute(BehaviorContext <TInstance, TData> context, Behavior <TInstance, TData> next) { ConsumeContext <TData> consumeContext; if (!context.TryGetPayload(out consumeContext)) { throw new ArgumentException("The ConsumeContext was not available"); } TRequest requestMessage = _requestMessageFactory(consumeContext); await next.Execute(context); }
async Task Execute(BehaviorContext <TInstance> context) { ConsumeContext consumeContext; if (!context.TryGetPayload(out consumeContext)) { throw new ContextException("The consume context could not be retrieved."); } var consumeEventContext = new AutomatonymousConsumeEventContext <TInstance>(context, consumeContext); TMessage message = _messageFactory(consumeEventContext); await consumeContext.Publish(message, _publishPipe); }
async Task Execute(BehaviorContext <TInstance> context) { ConsumeContext consumeContext; if (!context.TryGetPayload(out consumeContext)) { throw new ArgumentException("The ConsumeContext was not available"); } var consumeEventContext = new AutomatonymousConsumeEventContext <TInstance>(context, consumeContext); TRequest requestMessage = _messageFactory(consumeEventContext); await SendRequest(context, consumeContext, requestMessage); }
async Task Activity <TInstance, TData> .Execute(BehaviorContext <TInstance, TData> context, Behavior <TInstance, TData> next) { ConsumeContext <TData> consumeContext; if (!context.TryGetPayload(out consumeContext)) { throw new ContextException("The consume context could not be retrieved."); } var consumeEventContext = new AutomatonymousConsumeEventContext <TInstance, TData>(context, consumeContext); TMessage message = _messageFactory(consumeEventContext); await consumeContext.RespondAsync(message, _responsePipe); await next.Execute(context); }
public static bool TryGetExceptionContext <TInstance, TData, TException>(this BehaviorContext <TInstance, TData> context, out ConsumeExceptionEventContext <TInstance, TData, TException> exceptionContext) where TData : class where TException : Exception { if (context is BehaviorExceptionContext <TInstance, TData, TException> behaviorExceptionContext) { if (!context.TryGetPayload(out ConsumeContext <TData> consumeContext)) { throw new ContextException("The consume context could not be retrieved."); } exceptionContext = new AutomatonymousConsumeExceptionEventContext <TInstance, TData, TException>(behaviorExceptionContext, consumeContext); return(true); } exceptionContext = null; return(false); }
public static bool TryGetExceptionContext <TInstance, TException>( this BehaviorContext <TInstance> context, out ConsumeExceptionEventContext <TInstance, TException> exceptionContext) where TException : Exception { var behaviorExceptionContext = context as BehaviorExceptionContext <TInstance, TException>; if (behaviorExceptionContext != null) { ConsumeContext consumeContext; if (!context.TryGetPayload(out consumeContext)) { throw new ContextException("The consume context could not be retrieved."); } exceptionContext = new AutomatonymousConsumeExceptionEventContext <TInstance, TException>(behaviorExceptionContext, consumeContext); return(true); } exceptionContext = null; return(false); }
public async Task Execute(BehaviorContext <RequestState, RequestCompleted> context, Behavior <RequestState, RequestCompleted> next) { if (!context.Instance.ExpirationTime.HasValue || context.Instance.ExpirationTime.Value > DateTime.UtcNow) { if (!context.TryGetPayload(out ConsumeContext <RequestCompleted> consumeContext)) { throw new ArgumentException("The ConsumeContext was not present", nameof(context)); } string body = GetResponseBody(consumeContext, context.Instance); IPipe <SendContext> pipe = new CompletedMessagePipe(context.GetPayload <ConsumeContext <RequestCompleted> >(), context.Instance, body); var endpoint = await context.GetSendEndpoint(context.Instance.ResponseAddress).ConfigureAwait(false); var scheduled = new CompletedEvent(); await endpoint.Send(scheduled, pipe).ConfigureAwait(false); } await next.Execute(context).ConfigureAwait(false); }
public bool TryGetPayload <TPayload>(out TPayload payload) where TPayload : class { return(_context.TryGetPayload(out payload)); }
public override bool TryGetPayload <TPayload>(out TPayload context) { return(_context.TryGetPayload(out context)); }