private bool IsNextNode(ScriptWorkflow scriptWorkflow, int currentNode)
        {
            // Local Variables
            XmlSerializer xmlSerializer = null;
            StringReader  stringReader  = null;
            WorkflowNodes workflowNodes = null;
            WFNodeInfo    nextNode      = null;

            try
            {
                // Instantiate local variables
                stringReader = new StringReader(scriptWorkflow.WorkflowXML);
                WFHistArray  = new ArrayList();

                // Deserialize the WorkFlow Nodes
                xmlSerializer = new XmlSerializer(typeof(WorkflowNodes));
                workflowNodes = (WorkflowNodes)xmlSerializer.Deserialize(stringReader);

                foreach (WFNodeInfo WFN in workflowNodes.Nodes)
                {
                    if (WFN.NodeUniqueID == currentNode)
                    {
                        Int32 ProcNode = DetermineNextSection(WFN);
                        foreach (WFNodeInfo WFN2 in workflowNodes.Nodes)
                        {
                            if ((WFN2.NodeUniqueID == ProcNode) || (WFN.Conditions != null && WFN.Conditions.Count() > 0))
                            {
                                nextNode = WFN2;
                                break;
                            }
                        }
                        break;
                    }
                }

                return(nextNode != null);
            }
            catch
            {
                return(false);
            }
            finally
            {
                xmlSerializer = null;
                stringReader  = null;
                workflowNodes = null;
            }
        }
Exemplo n.º 2
0
        public static WFNodeInfo GetNextNode(HttpSessionStateBase Session)
        {
            WFNodeInfo node = (Session["NextNode"] == null) ? null : (WFNodeInfo)Session["NextNode"];

            return(node);
        }
Exemplo n.º 3
0
 public static void StoreNextNode(HttpSessionStateBase Session, WFNodeInfo node)
 {
     Session["NextNode"] = node;
 }
        private WFNodeInfo DetermineNextNode(ScriptWorkflow scriptWorkflow, int currentNode, MoveDirection direction)
        {
            // Local Variables
            XmlSerializer xmlSerializer = null;
            StringReader  stringReader  = null;
            WorkflowNodes workflowNodes = null;
            WFNodeInfo    nextNode      = null;
            //wfHistory[] WorkflowHistory = null;
            ArrayList WFHistArray = null;

            try
            {
                // Instantiate local variables
                stringReader = new StringReader(scriptWorkflow.WorkflowXML);
                WFHistArray  = new ArrayList();

                // Deserialize the WorkFlow Nodes
                xmlSerializer = new XmlSerializer(typeof(WorkflowNodes));
                workflowNodes = (WorkflowNodes)xmlSerializer.Deserialize(stringReader);

                // Determin by direction
                switch (direction)
                {
                case MoveDirection.Forward:
                    foreach (WFNodeInfo WFN in workflowNodes.Nodes)
                    {
                        if (WFN.NodeUniqueID == currentNode)     //WorkflowObject.CurrentNode
                        {
                            Int32 ProcNode = DetermineNextSection(WFN);
                            foreach (WFNodeInfo WFN2 in workflowNodes.Nodes)
                            {
                                if (WFN2.NodeUniqueID == ProcNode)
                                {
                                    nextNode = WFN2;
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    break;

                case MoveDirection.Back:

                    if (SessionManager.GetWorkflowHistory(HttpContext.Session) != null)
                    {
                        foreach (wfHistory wfhis in SessionManager.GetWorkflowHistory(HttpContext.Session))
                        {
                            WFHistArray.Add(wfhis);
                        }
                        if (WFHistArray.Count < 2)
                        {
                            return(null);
                        }
                        wfHistory lastone = (wfHistory)WFHistArray[WFHistArray.Count - 2];

                        if (lastone.WorkFlowID == scriptWorkflow.ScriptWorkflowID && lastone.NodeID == currentNode)
                        {
                            return(null);
                        }

                        if (lastone.WorkFlowID == scriptWorkflow.ScriptWorkflowID)
                        {
                            currentNode = lastone.NodeID;

                            WFHistArray.RemoveAt(WFHistArray.Count - 1);
                            WFHistArray.RemoveAt(WFHistArray.Count - 1);
                            SessionManager.StoreWorkflowHistory(HttpContext.Session, (wfHistory[])WFHistArray.ToArray(typeof(wfHistory)));
                            nextNode = DetermineNextNode(scriptWorkflow, currentNode, MoveDirection.Current);
                        }
                        else
                        {
                            nextNode = new WFNodeInfo();
                            nextNode.NodeUniqueID = lastone.WorkFlowID;
                            nextNode.nodeName     = lastone.WorkFlowName;
                            nextNode.nodeType     = NodeType.PreviousWorkflow;
                            nextNode.DocUID       = lastone.NodeID; // Use DocUID parameter as  NodeId
                            WFHistArray.RemoveAt(WFHistArray.Count - 1);
                            WFHistArray.RemoveAt(WFHistArray.Count - 1);
                            SessionManager.StoreWorkflowHistory(HttpContext.Session, (wfHistory[])WFHistArray.ToArray(typeof(wfHistory)));
                            return(nextNode);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                    break;

                case MoveDirection.Current:
                    foreach (WFNodeInfo WFN in workflowNodes.Nodes)
                    {
                        if (WFN.NodeUniqueID == currentNode)
                        {
                            nextNode = WFN;
                            break;
                        }
                    }
                    break;

                case MoveDirection.Start:
                    foreach (WFNodeInfo wFNodeInfo in workflowNodes.Nodes)
                    {
                        Int32 ProcNode = DetermineNextSection(wFNodeInfo);
                        foreach (WFNodeInfo wFNodeInfo2 in workflowNodes.Nodes)
                        {
                            if (wFNodeInfo2.NodeUniqueID == ProcNode)
                            {
                                nextNode = wFNodeInfo2;
                                break;
                            }
                        }
                        break;
                    }
                    break;

                default:
                    break;
                }

                if (nextNode == null) //&& nextNode.nodeType.Equals(NodeType.SignPost)
                {
                    nextNode = DetermineNextNode(scriptWorkflow, nextNode.NodeUniqueID, MoveDirection.Forward);
                }

                return(nextNode);
            }
            catch
            {
                return(null);
            }
            finally
            {
                xmlSerializer = null;
                stringReader  = null;
                workflowNodes = null;
                WFHistArray   = null;
            }
        }
        // GET: /Workflow/
        public ActionResult Display(int id)
        {
            //DataObjectLoader DOL = new API.ExternalData.DataObjectLoader();
            WorkflowDisplay wfDisplay = new WorkflowDisplay();

            WFNodeInfo nextNode = null;

            ScreenViewer.API.WorkflowController WFC = new API.WorkflowController();
            var actionResult      = WFC.GetScriptWorkflow(id);
            DataObjectManager DOM = new DataObjectManager();

            if (actionResult != null)
            {
                var response = actionResult as OkNegotiatedContentResult <ScriptWorkflow>;
                ViewBag.WorkflowName   = response.Content.WorkflowName;
                wfDisplay.workflowName = response.Content.WorkflowName;

                nextNode = DetermineNextNode((ScriptWorkflow)response.Content, currentNode, direction);

                if (nextNode != null)
                {
                    if (!direction.Equals(MoveDirection.Current) && nextNode.nodeName != null && nextNode.nodeType.Equals(NodeType.Section))
                    {
                        SessionManager.StoreNavigation(HttpContext.Session, nextNode.nodeName, wfDisplay.workflowName.ToString());
                    }

                    if (nextNode.nodeActions != "") //&& fireactions
                    {
                        FireActions(nextNode.nodeActions);
                    }

                    switch (nextNode.nodeType)
                    {
                    case NodeType.Section:
                        AddtoWFHistory(response.Content.ScriptWorkflowID, nextNode.NodeUniqueID, response.Content.WorkflowName, nextNode.nodeName);
                        break;

                    case NodeType.Workflow:
                        return(RedirectToAction("Display", "Workflow", new { id = WFC.GetScriptWorkflowId(nextNode.nodeName) }));

                    case NodeType.PreviousWorkflow:
                        return(RedirectToAction("DisplayByDirection", "Workflow", new { id = WFC.GetScriptWorkflowId(nextNode.nodeName), currentNode = nextNode.DocUID, moveDirection = MoveDirection.Current }));

                    case NodeType.SignPost:
                        MoveDirection direction2 = direction == MoveDirection.Start ? MoveDirection.Forward : direction;
                        WFNodeInfo    holdNode   = nextNode;
                        nextNode = DetermineNextNode((ScriptWorkflow)response.Content, nextNode.NodeUniqueID, direction2);
                        if (nextNode == null)
                        {
                            direction = MoveDirection.Current;
                            return(Display(Convert.ToInt32(Request.Form["hdnWorkflowId"])));
                            //nextNode = holdNode;
                        }
                        else
                        {
                            if (!direction.Equals(MoveDirection.Current) && nextNode.nodeName != null)
                            {
                                SessionManager.StoreNavigation(HttpContext.Session, nextNode.nodeName, wfDisplay.workflowName.ToString());
                                AddtoWFHistory(response.Content.ScriptWorkflowID, nextNode.NodeUniqueID, response.Content.WorkflowName, nextNode.nodeName);
                            }

                            if (nextNode.nodeType.Equals(NodeType.Workflow))
                            {
                                return(RedirectToAction("Display", "Workflow", new { id = WFC.GetScriptWorkflowId(nextNode.nodeName) }));
                            }
                        }
                        FireActions(nextNode.nodeActions);
                        if (nextNode.nodeType.Equals(NodeType.SignPost))
                        {
                            nextNode = DetermineNextNode((ScriptWorkflow)response.Content, nextNode.NodeUniqueID, direction2);

                            if (nextNode == null)
                            {
                                direction = MoveDirection.Current;
                                return(Display(Convert.ToInt32(Request.Form["hdnWorkflowId"])));
                                //nextNode = holdNode;
                            }
                            else
                            {
                                if (!direction.Equals(MoveDirection.Current) && nextNode.nodeName != null)
                                {
                                    SessionManager.StoreNavigation(HttpContext.Session, nextNode.nodeName, wfDisplay.workflowName.ToString());
                                    AddtoWFHistory(response.Content.ScriptWorkflowID, nextNode.NodeUniqueID, response.Content.WorkflowName, nextNode.nodeName);
                                }

                                if (nextNode.nodeType.Equals(NodeType.Workflow))
                                {
                                    return(RedirectToAction("Display", "Workflow", new { id = WFC.GetScriptWorkflowId(nextNode.nodeName) }));
                                }
                            }
                            FireActions(nextNode.nodeActions);
                        }
                        break;
                    }

                    if (IsNextNode((ScriptWorkflow)response.Content, nextNode.NodeUniqueID))
                    {
                        wfDisplay.showNext = true;
                    }
                    else
                    {
                        wfDisplay.showNext = false;
                    }
                }
                else
                {
                    direction = MoveDirection.Current;
                    return(Display(Convert.ToInt32(Request.Form["hdnWorkflowId"])));
                }
            }

            if (AddHistory)
            {
                if (SessionManager.GetWorkflowHistory(HttpContext.Session).Length >= 2)
                {
                    wfDisplay.showPrevious = true;
                }
                else
                {
                    wfDisplay.showPrevious = false;
                }
            }
            Session["layout"]    = null;
            wfDisplay.nextNode   = nextNode;
            wfDisplay.workflowID = id.ToString();
            nextNode.DocUID      = id;
            SessionManager.StoreNextNode(HttpContext.Session, nextNode);
            wfDisplay.callNotes = SessionManager.GetContactNotes(HttpContext.Session);

            string layoutname = "_default";

            if (!string.IsNullOrEmpty(SessionManager.GetScreenLayout(HttpContext.Session)))
            {
                layoutname = SessionManager.GetScreenLayout(HttpContext.Session);
            }

            WorkflowLayoutsController WLC = new WorkflowLayoutsController();

            //var actionResult2 = WLC.GetWorkflowLayoutString(layoutname, ScreenViewer.ClientHelper.GetClientIdByUserID(System.Web.HttpContext.Current.User.Identity.GetUserId()));
            var actionResult2 = WLC.GetWorkflowLayoutString(layoutname, SessionManager.GetScriptParameterByKey("ClientId", HttpContext.Session));

            if (actionResult2 != null)
            {
                var response = actionResult2 as OkNegotiatedContentResult <string>;
                wfDisplay.Layout = response.Content;
            }
            ScriptProject scriptproject = null;

            API.ProjectController PC = new API.ProjectController();
            var actionResult3        = PC.GetScriptProject(SessionManager.GetProjectId(HttpContext.Session));

            if (actionResult3 != null)
            {
                var response = actionResult3 as OkNegotiatedContentResult <ScriptProject>;
                scriptproject = response.Content;
            }

            string notif = scriptproject.NotificationText;

            wfDisplay.menuHTML = SessionManager.GetMenuHTML(HttpContext.Session);

            wfDisplay.Notifications = scriptproject.NotificationText; //notif.Replace(System.Environment.NewLine,"");

            return(View("_WorkFlowViewLayout1", wfDisplay));
        }
        public ActionResult Display(int id, int currentNode, MoveDirection moveDirection)
        {
            WFNodeInfo      nextNode  = null;
            WorkflowDisplay wfDisplay = new WorkflowDisplay();

            ScreenViewer.API.WorkflowController WFC = new API.WorkflowController();
            var actionResult = WFC.GetScriptWorkflow(id);

            if (actionResult != null)
            {
                var response = actionResult as OkNegotiatedContentResult <ScriptWorkflow>;
                wfDisplay.workflowName = response.Content.WorkflowName;

                nextNode = DetermineNextNode((ScriptWorkflow)response.Content, currentNode, moveDirection);

                if (nextNode != null)
                {
                    if (!direction.Equals(MoveDirection.Current) && nextNode.nodeName != null)
                    {
                        SessionManager.StoreNavigation(HttpContext.Session, nextNode.nodeName, wfDisplay.workflowName.ToString());
                    }

                    if (nextNode.nodeActions != "" && FireAway)
                    {
                        FireActions(nextNode.nodeActions);
                    }

                    switch (nextNode.nodeType)
                    {
                    case NodeType.Section:
                        AddtoWFHistory(response.Content.ScriptWorkflowID, nextNode.NodeUniqueID, response.Content.WorkflowName, nextNode.nodeName);
                        break;

                    case NodeType.Workflow:
                        return(RedirectToAction("Display", "Workflow", new { id = WFC.GetScriptWorkflowId(nextNode.nodeName) }));

                    case NodeType.PreviousWorkflow:
                        return(RedirectToAction("DisplayByDirection", "Workflow", new { id = WFC.GetScriptWorkflowId(nextNode.nodeName), moveDirection = MoveDirection.Current }));

                    case NodeType.SignPost:

                        nextNode = DetermineNextNode((ScriptWorkflow)response.Content, currentNode, direction);

                        if (!direction.Equals(MoveDirection.Current) && nextNode.nodeName != null)
                        {
                            SessionManager.StoreNavigation(HttpContext.Session, nextNode.nodeName, wfDisplay.workflowName.ToString());
                        }

                        if (nextNode.nodeActions != "" & FireAway)
                        {
                            FireActions(nextNode.nodeActions);
                        }
                        break;
                    }

                    if (IsNextNode((ScriptWorkflow)response.Content, nextNode.NodeUniqueID))
                    {
                        wfDisplay.showNext = true;
                    }
                    else
                    {
                        wfDisplay.showNext = false;
                    }
                }
            }

            if (AddHistory)
            {
                if (SessionManager.GetWorkflowHistory(HttpContext.Session).Length >= 2)
                {
                    wfDisplay.showPrevious = true;
                }
                else
                {
                    wfDisplay.showPrevious = false;
                }
            }

            wfDisplay.nextNode   = nextNode;
            wfDisplay.workflowID = id.ToString();

            string layoutname = "_default";

            if (!string.IsNullOrEmpty(SessionManager.GetScreenLayout(HttpContext.Session)))
            {
                layoutname = SessionManager.GetScreenLayout(HttpContext.Session);
            }

            WorkflowLayoutsController WLC = new WorkflowLayoutsController();

            //var actionResult2 = WLC.GetWorkflowLayoutString(layoutname, ScreenViewer.ClientHelper.GetClientIdByUserID(System.Web.HttpContext.Current.User.Identity.GetUserId()));
            var actionResult2 = WLC.GetWorkflowLayoutString(layoutname, SessionManager.GetScriptParameterByKey("ClientId", HttpContext.Session));

            if (actionResult2 != null)
            {
                var response = actionResult2 as OkNegotiatedContentResult <string>;
                wfDisplay.Layout = response.Content;
            }
            wfDisplay.menuHTML = SessionManager.GetMenuHTML(HttpContext.Session);

            return(View("_WorkFlowViewLayout1", wfDisplay));
        }
        public Int32 DetermineNextSection(WFNodeInfo CurrentNode)
        {
            Int32 gotonode = -1;

            if (CurrentNode.Conditions == null)
            {
                return(gotonode);
            }

            foreach (WFCondition Cond in CurrentNode.Conditions)
            {
                if (Cond.conditionType == ConditionType.Default)
                {
                    gotonode = Cond.linktoNode;
                }
                else
                {
                    switch (Cond.conditionType)
                    {
                    case ConditionType.Question:
                        try
                        {
                            string qresp = GetQuestionResponse(Cond.Question.ToString());
                            if (qresp == Cond.QuestionResponse)
                            {
                                return(Cond.linktoNode);
                            }
                        }
                        catch
                        {
                        }
                        break;

                    case ConditionType.DataObject:
                        try
                        {
                            string doValue = GetDataObjectValue(Cond.DataObject);

                            if (doValue == Cond.DataObjectValue)
                            {
                                return(Cond.linktoNode);
                            }
                        }
                        catch
                        {
                        }
                        break;

                    case ConditionType.Clause:
                        ClauseEvaluator CE         = new ClauseEvaluator(HttpContext.Session);
                        bool            usesection = CE.EvaluateClause(Cond.ClauseID.ToString(), Cond.Result);

                        if (usesection)
                        {
                            return(Cond.linktoNode);
                        }

                        break;

                    case ConditionType.LinkTo:
                        return(Cond.linktoNode);
                    }
                }
            }
            return(gotonode);
        }