public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var httpMethod          = context.HttpContext.Request.Method;
            var routeValues         = context.RouteData.Values;
            var workflowTypeEntries = _workflowTypeRouteEntries.GetWorkflowRouteEntries(httpMethod, routeValues);
            var workflowEntries     = _workflowRouteEntries.GetWorkflowRouteEntries(httpMethod, routeValues);

            if (workflowTypeEntries.Any())
            {
                var workflowTypeIds = workflowTypeEntries.Select(x => Int32.Parse(x.WorkflowId)).ToList();
                var workflowTypes   = (await _workflowTypeStore.GetAsync(workflowTypeIds)).ToDictionary(x => x.Id);
                var correlationId   = routeValues.GetValue <string>("correlationid");

                foreach (var entry in workflowTypeEntries)
                {
                    if (workflowTypes.TryGetValue(Int32.Parse(entry.WorkflowId), out var workflowType))
                    {
                        var activity = workflowType.Activities.Single(x => x.ActivityId == entry.ActivityId);

                        if (activity.IsStart)
                        {
                            // If this is not a singleton workflow or there is not already an halted instance, start a new workflow.
                            if (!workflowType.IsSingleton || !await _workflowStore.HasHaltedInstanceAsync(workflowType.WorkflowTypeId))
                            {
                                await _workflowManager.StartWorkflowAsync(workflowType, activity, null, correlationId);
                            }
                        }
                    }
                }
            }

            if (workflowEntries.Any())
            {
                var workflowIds   = workflowEntries.Select(x => x.WorkflowId).ToList();
                var workflows     = (await _workflowStore.GetAsync(workflowIds)).ToDictionary(x => x.WorkflowId);
                var correlationId = routeValues.GetValue <string>("correlationid");

                foreach (var entry in workflowEntries)
                {
                    if (workflows.TryGetValue(entry.WorkflowId, out var workflow) &&
                        (String.IsNullOrWhiteSpace(correlationId) ||
                         workflow.CorrelationId == correlationId))
                    {
                        var blockingActivity = workflow.BlockingActivities.Single(x => x.ActivityId == entry.ActivityId);
                        await _workflowManager.ResumeWorkflowAsync(workflow, blockingActivity);
                    }
                }
            }

            await next();
        }
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var httpMethod          = context.HttpContext.Request.Method;
            var routeValues         = context.RouteData.Values;
            var workflowTypeEntries = _workflowTypeRouteEntries.GetWorkflowRouteEntries(httpMethod, routeValues);
            var workflowEntries     = _workflowRouteEntries.GetWorkflowRouteEntries(httpMethod, routeValues);

            if (workflowTypeEntries.Any())
            {
                var workflowTypeIds = workflowTypeEntries.Select(x => Int32.Parse(x.WorkflowId)).ToList();
                var workflowTypes   = (await _workflowTypeStore.GetAsync(workflowTypeIds)).ToDictionary(x => x.Id);

                foreach (var entry in workflowTypeEntries)
                {
                    var workflowType = workflowTypes[Int32.Parse(entry.WorkflowId)];
                    var activity     = workflowType.Activities.Single(x => x.ActivityId == entry.ActivityId);
                    await _workflowManager.StartWorkflowAsync(workflowType, activity);
                }
            }

            await next();
        }