public static EventActivityBinder <Book, BookAdded> CopyDataToInstance(this EventActivityBinder <Book, BookAdded> binder) { return(binder.Then(x => { x.Instance.DateAdded = x.Data.Timestamp.Date; x.Instance.Title = x.Data.Title; x.Instance.Isbn = x.Data.Isbn; })); }
/// <summary> /// Use when a request is received after the initial request is still awaiting completion /// </summary> /// <param name="binder"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static EventActivityBinder <FutureState, T> AddSubscription <T>(this EventActivityBinder <FutureState, T> binder) where T : class { return(binder.Then(context => { ConsumeEventContext <FutureState, T> consumeContext = context.CreateConsumeContext(); context.Instance.AddSubscription(consumeContext.ResponseAddress, consumeContext.RequestId); })); }
/// <summary> /// Use when a request is received after the initial request is still awaiting completion /// </summary> /// <param name="binder"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static EventActivityBinder <FutureState, T> AddSubscription <T>(this EventActivityBinder <FutureState, T> binder) where T : class { return(binder.Then(context => { FutureConsumeContext <T> consumeContext = context.CreateFutureConsumeContext(context.Data); consumeContext.AddSubscription(); })); }
/// <summary> /// Initialize the FutureState properties of the request /// </summary> /// <param name="binder"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static EventActivityBinder <FutureState, T> InitializeFuture <T>(this EventActivityBinder <FutureState, T> binder) where T : class { return(binder .Then(context => { context.Instance.Created = DateTime.UtcNow; context.Instance.Request = new FutureMessage <T>(context.Data); context.Instance.Location = new FutureLocation(context.Instance.CorrelationId, context.CreateConsumeContext().ReceiveContext.InputAddress); }) .AddSubscription()); }
/// <summary> /// Set the result associated with the identifier using the message factory /// </summary> /// <param name="binder"></param> /// <param name="messageFactory">Should return the result message</param> /// <typeparam name="TResult">The result type</typeparam> /// <returns></returns> public static EventActivityBinder <FutureState, RoutingSlipFaulted> SetFault <TResult>(this EventActivityBinder <FutureState, RoutingSlipFaulted> binder, FutureMessageFactory <RoutingSlipFaulted, TResult> messageFactory) where TResult : class { return(binder.Then(context => { FutureConsumeContext <RoutingSlipFaulted> consumeContext = context.CreateFutureConsumeContext(); var resultId = consumeContext.Message.TrackingNumber; consumeContext.SetFault(resultId, messageFactory); })); }
public static EventActivityBinder <JobSaga, JobSubmitted> InitializeJob(this EventActivityBinder <JobSaga, JobSubmitted> binder) { return(binder.Then(context => { context.Instance.Submitted = context.Data.Timestamp; context.Instance.Job = context.Data.Job; context.Instance.ServiceAddress = context.GetPayload <ConsumeContext>().SourceAddress; context.Instance.JobTimeout = context.Data.JobTimeout; context.Instance.JobTypeId = context.Data.JobTypeId; context.Instance.AttemptId = NewId.NextGuid(); })); }
/// <summary> /// Set the result associated with the identifier using the message factory /// </summary> /// <param name="binder"></param> /// <param name="getResultId">Should return the result identifier</param> /// <param name="messageFactory">Should return the result message</param> /// <typeparam name="T">The event type</typeparam> /// <typeparam name="TResult">The result type</typeparam> /// <returns></returns> public static EventActivityBinder <FutureState, T> SetResult <T, TResult>(this EventActivityBinder <FutureState, T> binder, Func <FutureConsumeContext <T>, Guid> getResultId, FutureMessageFactory <T, TResult> messageFactory) where T : class where TResult : class { return(binder.Then(context => { FutureConsumeContext <T> consumeContext = context.CreateFutureConsumeContext(); var resultId = getResultId(consumeContext); consumeContext.SetResult(resultId, messageFactory); })); }
public static EventActivityBinder <JobTypeSaga, SetConcurrentJobLimit> SetConcurrentLimit( this EventActivityBinder <JobTypeSaga, SetConcurrentJobLimit> binder) { return(binder.Then(context => { if (context.Data.Kind == ConcurrentLimitKind.Configured) { context.Instance.ConcurrentJobLimit = context.Data.ConcurrentJobLimit; LogContext.Debug?.Log("Concurrent Job Limit: {ConcurrencyLimit}", context.Instance.ConcurrentJobLimit); } else if (context.Data.Kind == ConcurrentLimitKind.Override) { context.Instance.OverrideJobLimit = context.Data.ConcurrentJobLimit; context.Instance.OverrideLimitExpiration = DateTime.Now + (context.Data.Duration ?? TimeSpan.FromMinutes(30)); LogContext.Debug?.Log("Override Concurrent Job Limit: {ConcurrencyLimit}", context.Instance.OverrideJobLimit); } })); }
public static EventActivityBinder <ReceiveEndpoint, ReceiveEndpointFaulted> SetUnHealthy(this EventActivityBinder <ReceiveEndpoint, ReceiveEndpointFaulted> binder) { return(binder.Then(context => context.Instance.HealthResult = EndpointHealthResult.Unhealthy(context.Instance, context.Instance.Message, context.Data.Exception))); }
public static EventActivityBinder <ReceiveEndpoint, T> SetDegraded <T>(this EventActivityBinder <ReceiveEndpoint, T> binder) where T : class { return(binder.Then(context => context.Instance.HealthResult = EndpointHealthResult.Degraded(context.Instance, context.Instance.Message))); }
/// <summary> /// Captures the incoming request into a <see cref="RequestToken{TRequest}"/>. /// </summary> /// <typeparam name="TInstance"></typeparam> /// <typeparam name="TRequest"></typeparam> /// <param name="source"></param> /// <param name="captured"></param> /// <returns></returns> public static EventActivityBinder <TInstance, TRequest> CaptureRequest <TInstance, TRequest>(this EventActivityBinder <TInstance, TRequest> source, Action <BehaviorContext <TInstance, TRequest>, RequestToken <TRequest> > captured) where TInstance : class, SagaStateMachineInstance where TRequest : class { return(source.Then(context => captured(context, context.CaptureRequestToken()))); }
public static EventActivityBinder <BookSagaState, IBookAddedGlobalEvent> CopyDataToInstance( this EventActivityBinder <BookSagaState, IBookAddedGlobalEvent> binder) => binder.Then( x => { x.Instance.DateAdded = x.Data.TimeStamp.Date; x.Instance.Isbn = x.Data.Isbn; x.Instance.Title = x.Data.Title; });
/// <summary> /// Adds a synchronous delegate activity to the event's behavior with mapping to domain event and state /// </summary> /// <typeparam name="TInstance">The state machine instance type</typeparam> /// <typeparam name="TData">The event data type</typeparam> /// <param name="binder">The event binder</param> /// <param name="action">The synchronous delegate</param> public static EventActivityBinder <TInstance, TData> Then <TInstance, TData>( this EventActivityBinder <TInstance, TData> binder, Action <TInstance, TData> action) where TInstance : class { return(binder.Then(ctx => action(ctx.Instance, ctx.Data))); }