Exemple #1
0
        private Status RunTasks(IEnumerable <Node> nodes, IEnumerable <Task> tasks)
        {
            bool success           = true;
            bool warning           = false;
            bool atLeastOneSucceed = false;

            if (nodes.Count() > 0)
            {
                Node startNode = nodes.ElementAt(0);

                if (startNode is DoIf)
                {
                    DoIf doIf = (DoIf)startNode;
                    RunDoIf(tasks, nodes, doIf, ref success, ref warning, ref atLeastOneSucceed);
                }
                else if (startNode is DoWhile)
                {
                    DoWhile doWhile = (DoWhile)startNode;
                    RunDoWhile(tasks, nodes, doWhile, ref success, ref warning, ref atLeastOneSucceed);
                }
                else
                {
                    if (startNode.ParentId == START_ID)
                    {
                        RunTasks(tasks, nodes, startNode, ref success, ref warning, ref atLeastOneSucceed);
                    }
                }
            }
            else
            {
                RunSequentialTasks(tasks, ref success, ref warning, ref atLeastOneSucceed);
            }

            if (success)
            {
                return(Status.Success);
            }
            else
            {
                if (atLeastOneSucceed || warning)
                {
                    return(Status.Warning);
                }
                else
                {
                    return(Status.Error);
                }
            }
        }
Exemple #2
0
        private void RunDoIf(IEnumerable <Task> tasks, IEnumerable <Node> nodes, DoIf doIf, ref bool success, ref bool warning, ref bool atLeastOneSucceed)
        {
            Task ifTask = GetTask(doIf.If);

            if (ifTask != null)
            {
                if (ifTask.IsEnabled)
                {
                    TaskStatus status = ifTask.Run();

                    success &= status.Status == Status.Success;
                    warning |= status.Status == Status.Warning;
                    if (!atLeastOneSucceed && status.Status == Status.Success)
                    {
                        atLeastOneSucceed = true;
                    }

                    if (status.Condition == true)
                    {
                        if (doIf.DoNodes.Length > 0)
                        {
                            // Build Tasks
                            var doIfTasks = NodesToTasks(doIf.DoNodes);

                            // Run Tasks
                            Node doIfStartNode = doIf.DoNodes[0];

                            if (doIfStartNode.ParentId == START_ID)
                            {
                                RunTasks(doIfTasks, doIf.DoNodes, doIfStartNode, ref success, ref warning, ref atLeastOneSucceed);
                            }
                        }
                    }
                    else if (status.Condition == false)
                    {
                        if (doIf.OtherwiseNodes.Length > 0)
                        {
                            // Build Tasks
                            var otherwiseTasks = NodesToTasks(doIf.OtherwiseNodes);

                            // Run Tasks
                            Node otherwiseStartNode = doIf.OtherwiseNodes[0];

                            if (otherwiseStartNode.ParentId == START_ID)
                            {
                                RunTasks(otherwiseTasks, doIf.OtherwiseNodes, otherwiseStartNode, ref success, ref warning, ref atLeastOneSucceed);
                            }
                        }
                    }

                    // Child node
                    Node childNode = nodes.Where(n => n.ParentId == doIf.Id).FirstOrDefault();

                    if (childNode != null)
                    {
                        RunTasks(this.Taks, nodes, childNode, ref success, ref warning, ref atLeastOneSucceed);
                    }
                }
            }
            else
            {
                throw new Exception("Task " + doIf.Id + " not found.");
            }
        }
Exemple #3
0
        private void RunTasks(IEnumerable <Task> tasks, IEnumerable <Node> nodes, Node node, ref bool success, ref bool warning, ref bool atLeastOneSucceed)
        {
            if (node != null)
            {
                Task task = GetTask(tasks, node.Id);
                if (task != null)
                {
                    if (task.IsEnabled)
                    {
                        TaskStatus status = task.Run();

                        success &= status.Status == Status.Success;
                        warning |= status.Status == Status.Warning;
                        if (!atLeastOneSucceed && status.Status == Status.Success)
                        {
                            atLeastOneSucceed = true;
                        }

                        Node childNode = nodes.Where(n => n.ParentId == node.Id).FirstOrDefault();

                        if (childNode != null)
                        {
                            if (childNode is DoIf)
                            {
                                DoIf doIf = (DoIf)childNode;
                                RunDoIf(tasks, nodes, doIf, ref success, ref warning, ref atLeastOneSucceed);
                            }
                            else if (childNode is DoWhile)
                            {
                                DoWhile doWhile = (DoWhile)childNode;
                                RunDoWhile(tasks, nodes, doWhile, ref success, ref warning, ref atLeastOneSucceed);
                            }
                            else
                            {
                                Task childTask = GetTask(tasks, childNode.Id);
                                if (childTask != null)
                                {
                                    if (childTask.IsEnabled)
                                    {
                                        TaskStatus childStatus = childTask.Run();

                                        success &= childStatus.Status == Status.Success;
                                        warning |= childStatus.Status == Status.Warning;
                                        if (!atLeastOneSucceed && status.Status == Status.Success)
                                        {
                                            atLeastOneSucceed = true;
                                        }

                                        // Recusive call
                                        Node ccNode = nodes.Where(n => n.ParentId == childNode.Id).FirstOrDefault();

                                        if (ccNode is DoIf)
                                        {
                                            DoIf doIf = (DoIf)ccNode;
                                            RunDoIf(tasks, nodes, doIf, ref success, ref warning, ref atLeastOneSucceed);
                                        }
                                        else if (ccNode is DoWhile)
                                        {
                                            DoWhile doWhile = (DoWhile)ccNode;
                                            RunDoWhile(tasks, nodes, doWhile, ref success, ref warning, ref atLeastOneSucceed);
                                        }
                                        else
                                        {
                                            RunTasks(tasks, nodes, ccNode, ref success, ref warning, ref atLeastOneSucceed);
                                        }
                                    }
                                }
                                else
                                {
                                    throw new Exception("Task " + childNode.Id + " not found.");
                                }
                            }
                        }
                    }
                }
                else
                {
                    throw new Exception("Task " + node.Id + " not found.");
                }
            }
        }