private static async Task <FlowContext> EnrichWithFlowContext(IControllerMessageContext context)
        {
            if (context.Get(ContextItems.FlowContext, out FlowContext flowContext))
            {
                return(flowContext);
            }


            if (context.Properties.CorrelationId == null)
            {
                return(null);
            }

            if (!Guid.TryParse(context.Properties.CorrelationId, out var continuationID))
            {
                return(null);
            }

            var flowStore = context.Config.DependencyResolver.Resolve <IFlowStore>();

            var flowID = await flowStore.FindFlowID(continuationID);

            if (!flowID.HasValue)
            {
                return(null);
            }

            var flowStateLock = await flowStore.LockFlowState(flowID.Value);

            var flowState = await flowStateLock.GetFlowState();

            if (flowState == null)
            {
                return(null);
            }

            flowContext = new FlowContext
            {
                HandlerContext = new FlowHandlerContext(context),

                FlowStateLock = flowStateLock,
                FlowState     = flowState,

                ContinuationID       = continuationID,
                ContinuationMetadata = flowState.Continuations.TryGetValue(continuationID, out var continuation) ? continuation : null
            };

            // IDisposable items in the IMessageContext are automatically disposed
            context.Store(ContextItems.FlowContext, flowContext);
            return(flowContext);
        }
Exemple #2
0
        private async Task CallControllerMethod <TController>(MethodInfo method, Func <object, Task <IYieldPoint> > getYieldPointResult, object[] parameters) where TController : class
        {
            var controller = config.DependencyResolver.Resolve <TController>();
            var yieldPoint = await getYieldPointResult(method.Invoke(controller, parameters));

            var context = new FlowHandlerContext
            {
                Config     = config,
                Controller = controller,
                Method     = method
            };

            var flowHandler = config.DependencyResolver.Resolve <IFlowHandler>();
            await flowHandler.Execute(context, yieldPoint);
        }