Exemple #1
0
        public static void SetCorrelationId(string name, object id)
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            if (state == null)
            {
                throw new RouteFlowException("RouteFlow:SetCorrelationId:Session state invalid");
            }

            if (name == "key")
            {
                // Verify duplicate correlation key while in a session
                // Reserved "key" is used to correlate an entire workflow to a single object id
                var keyValue = GetCorrelationId("key");
                if (keyValue != null)
                {
                    if (keyValue.ToString() != id.ToString())
                    {
                        throw new RouteFlowException("RouteFlow:SetCorrelationId:Cannot reassign the primary correlation key.");
                    }
                }
            }

            StateManager.SetCorrelationId(SessionProvider.SessionId, name, id);
        }
Exemple #2
0
        public static void Prepare(ActionExecutingContext context)
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            if (state == null)
            {
                return;
            }

            state.Current.SetContext(context);
        }
Exemple #3
0
        public static ActionResult SkipTo(string name)
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            if (state == null)
            {
                return(null);
            }
            state.Current.SkipTo = name;
            return(Next(null));
        }
Exemple #4
0
        public static bool OnPath <T>()
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            if (state == null)
            {
                return(false);
            }

            return(state.Path == typeof(T).Name);
        }
Exemple #5
0
        public static bool OnPath(string path)
        {
            if (path == null)
            {
                return(false);
            }

            var state = StateManager.GetState(SessionProvider.SessionId);

            if (state == null)
            {
                return(false);
            }

            return(state.Path == path);
        }
Exemple #6
0
        public static bool Active <T>(int?id)
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            if (state == null)
            {
                return(false);
            }

            var primaryKey = StateManager.GetCorrelationId(SessionProvider.SessionId, "key");

            if (primaryKey == null)
            {
                return(false);
            }

            return(state.Path == typeof(T).Name && (int)primaryKey == id);
        }
Exemple #7
0
        public static bool Active <T>()
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            return(state != null && state.Path == typeof(T).Name);
        }
Exemple #8
0
        public static bool Active()
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            return(state != null);
        }
Exemple #9
0
        public static ActionResult Resume()
        {
            var state = StateManager.GetState(SessionProvider.SessionId);

            if (state == null)
            {
                throw new RouteFlowException("RouteFlow:SessionID not valid in RouteFlow table");
            }

            var result = PathManager.GetEndpointByName(state.Path, state.Current.Name);

            if (result == null)
            {
                // stumped
                return(null);
            }

            var routeValues = new RouteValueDictionary();

            if (result.Correlations != null)
            {
                result.Correlations.ForEach(x =>
                {
                    if (x.Type == "SET")
                    {
                        if (routeValues.ContainsKey(x.RouteItem))
                        {
                            SetCorrelationId(x.Key, routeValues[x.RouteItem]);
                        }
                    }
                    //SetCorrelationId(x.Key, state.Current.Context.ActionParameters[x.RouteItem]);
                    if (x.Type == "GET")
                    {
                        var value = GetCorrelationId(x.Key);
                        if (value == null && x.IsRequired)
                        {
                            throw new ApplicationException(string.Format("RouteFlow:Correlation ({0}) is Required but not present", x.Key));
                        }
                        if (routeValues.ContainsKey(x.RouteItem))
                        {
                            routeValues[x.RouteItem] = value;
                        }
                        else
                        {
                            routeValues.Add(x.RouteItem, value);
                        }
                    }
                });
            }


            routeValues.Add("controller", result.Controller);
            routeValues.Add("action", result.Action);
            routeValues.Add("area", result.Area);

            routeValues.Extend(result.RouteValues);

            state.Current.SkipTo = null;
            state.Current.Name   = result.StepName;

            return(new RedirectToRouteResult(routeValues));
        }