Ejemplo n.º 1
0
 public Graph(IEnumerable <Node> nodes,
              GraphEvent onSuccess,
              GraphEvent onWarning,
              GraphEvent onError)
 {
     if (nodes != null)
     {
         Nodes = nodes.ToArray();
     }
     OnSuccess = onSuccess;
     OnWarning = onWarning;
     OnError   = onError;
 }
Ejemplo n.º 2
0
        private void Load()
        {
            XmlReader    xmlReader    = XmlReader.Create(this.WorkflowFilePath);
            XmlNameTable xmlNameTable = xmlReader.NameTable;

            XmlNamespaceManager = new XmlNamespaceManager(xmlNameTable);
            XmlNamespaceManager.AddNamespace("wf", "urn:wexflow-schema");

            // Loading settings
            XDocument xdoc = XDocument.Load(this.WorkflowFilePath);

            this.Id          = int.Parse(GetWorkflowAttribute(xdoc, "id"));
            this.Name        = GetWorkflowAttribute(xdoc, "name");
            this.Description = GetWorkflowAttribute(xdoc, "description");
            this.LaunchType  = (LaunchType)Enum.Parse(typeof(LaunchType), GetWorkflowSetting(xdoc, "launchType"), true);
            if (this.LaunchType == Core.LaunchType.Periodic)
            {
                this.Period = TimeSpan.Parse(GetWorkflowSetting(xdoc, "period"));
            }
            this.IsEnabled = bool.Parse(GetWorkflowSetting(xdoc, "enabled"));

            // Loading tasks
            List <Task> tasks = new List <Task>();

            foreach (XElement xTask in xdoc.XPathSelectElements("/wf:Workflow/wf:Tasks/wf:Task", this.XmlNamespaceManager))
            {
                string name         = xTask.Attribute("name").Value;
                string assemblyName = "Wexflow.Tasks." + name;
                string typeName     = "Wexflow.Tasks." + name + "." + name + ", " + assemblyName;
                Task   task         = (Task)Activator.CreateInstance(Type.GetType(typeName), xTask, this);
                tasks.Add(task);
            }
            this.Taks = tasks.ToArray();

            // Loading execution graph
            XElement xExectionGraph = xdoc.XPathSelectElement("/wf:Workflow/wf:ExecutionGraph", this.XmlNamespaceManager);

            if (xExectionGraph != null)
            {
                var taskNodes = GetTaskNodes(xExectionGraph);

                // Check parallel tasks and infinite loops
                CheckParallelTasks(taskNodes, "Parallel tasks execution detected in ExecutionGraph execution graph.");
                CheckInfiniteLoop(taskNodes, "Infinite loop detected in ExecutionGraph execution graph.");

                // OnSuccess
                GraphEvent onSuccess  = null;
                XElement   xOnSuccess = xExectionGraph.XPathSelectElement("wf:OnSuccess", this.XmlNamespaceManager);
                if (xOnSuccess != null)
                {
                    var onSuccessNodes = GetTaskNodes(xOnSuccess);
                    CheckParallelTasks(onSuccessNodes, "Parallel tasks execution detected in OnSuccess execution graph.");
                    CheckInfiniteLoop(onSuccessNodes, "Infinite loop detected in OnSuccess execution graph.");
                    onSuccess = new GraphEvent(onSuccessNodes);
                }

                // OnWarning
                GraphEvent onWarning  = null;
                XElement   xOnWarning = xExectionGraph.XPathSelectElement("wf:OnWarning", this.XmlNamespaceManager);
                if (xOnWarning != null)
                {
                    var onWarningNodes = GetTaskNodes(xOnWarning);
                    CheckParallelTasks(onWarningNodes, "Parallel tasks execution detected in OnWarning execution graph.");
                    CheckInfiniteLoop(onWarningNodes, "Infinite loop detected in OnWarning execution graph.");
                    onWarning = new GraphEvent(onWarningNodes);
                }

                // OnError
                GraphEvent onError  = null;
                XElement   xOnError = xExectionGraph.XPathSelectElement("wf:OnError", this.XmlNamespaceManager);
                if (xOnError != null)
                {
                    var onErrorNodes = GetTaskNodes(xOnError);
                    CheckParallelTasks(onErrorNodes, "Parallel tasks execution detected in OnError execution graph.");
                    CheckInfiniteLoop(onErrorNodes, "Infinite loop detected in OnError execution graph.");
                    onError = new GraphEvent(onErrorNodes);
                }

                this.ExecutionGraph = new Graph(taskNodes, onSuccess, onWarning, onError);
            }
        }
Ejemplo n.º 3
0
        void Load()
        {
            using (var xmlReader = XmlReader.Create(WorkflowFilePath))
            {
                var xmlNameTable = xmlReader.NameTable;
                if (xmlNameTable != null)
                {
                    XmlNamespaceManager = new XmlNamespaceManager(xmlNameTable);
                    XmlNamespaceManager.AddNamespace("wf", "urn:wexflow-schema");
                }
                else
                {
                    throw new Exception("xmlNameTable of " + WorkflowFilePath + " is null");
                }

                // Loading settings
                var xdoc = XDocument.Load(WorkflowFilePath);
                XDoc         = xdoc;
                XNamespaceWf = "urn:wexflow-schema";

                Id          = int.Parse(GetWorkflowAttribute(xdoc, "id"));
                Name        = GetWorkflowAttribute(xdoc, "name");
                Description = GetWorkflowAttribute(xdoc, "description");
                LaunchType  = (LaunchType)Enum.Parse(typeof(LaunchType), GetWorkflowSetting(xdoc, "launchType"), true);
                if (LaunchType == LaunchType.Periodic)
                {
                    Period = TimeSpan.Parse(GetWorkflowSetting(xdoc, "period"));
                }
                IsEnabled = bool.Parse(GetWorkflowSetting(xdoc, "enabled"));

                if (xdoc.Root != null)
                {
                    var xExecutionGraph = xdoc.Root.Element(XNamespaceWf + "ExecutionGraph");
                    IsExecutionGraphEmpty = xExecutionGraph == null || !xExecutionGraph.Elements().Any();
                }
                // Loading tasks
                var tasks = new List <Task>();
                foreach (var xTask in xdoc.XPathSelectElements("/wf:Workflow/wf:Tasks/wf:Task", XmlNamespaceManager))
                {
                    var xAttribute = xTask.Attribute("name");
                    if (xAttribute != null)
                    {
                        var name         = xAttribute.Value;
                        var assemblyName = "Wexflow.Tasks." + name;
                        var typeName     = "Wexflow.Tasks." + name + "." + name + ", " + assemblyName;
                        var type         = Type.GetType(typeName);

                        if (type != null)
                        {
                            var task = (Task)Activator.CreateInstance(type, xTask, this);
                            tasks.Add(task);
                        }
                        else
                        {
                            throw new Exception("The type of the task " + name + " could not be loaded.");
                        }
                    }
                    else
                    {
                        throw new Exception("Name attribute of the task " + xTask + " does not exist.");
                    }
                }
                Taks = tasks.ToArray();

                // Loading execution graph
                var xExectionGraph = xdoc.XPathSelectElement("/wf:Workflow/wf:ExecutionGraph", XmlNamespaceManager);
                if (xExectionGraph != null)
                {
                    var taskNodes = GetTaskNodes(xExectionGraph);

                    // Check startup node, parallel tasks and infinite loops
                    if (taskNodes.Any())
                    {
                        CheckStartupNode(taskNodes, "Startup node with parentId=-1 not found in ExecutionGraph execution graph.");
                    }
                    CheckParallelTasks(taskNodes, "Parallel tasks execution detected in ExecutionGraph execution graph.");
                    CheckInfiniteLoop(taskNodes, "Infinite loop detected in ExecutionGraph execution graph.");

                    // OnSuccess
                    GraphEvent onSuccess  = null;
                    var        xOnSuccess = xExectionGraph.XPathSelectElement("wf:OnSuccess", XmlNamespaceManager);
                    if (xOnSuccess != null)
                    {
                        var onSuccessNodes = GetTaskNodes(xOnSuccess);
                        CheckStartupNode(onSuccessNodes, "Startup node with parentId=-1 not found in OnSuccess execution graph.");
                        CheckParallelTasks(onSuccessNodes, "Parallel tasks execution detected in OnSuccess execution graph.");
                        CheckInfiniteLoop(onSuccessNodes, "Infinite loop detected in OnSuccess execution graph.");
                        onSuccess = new GraphEvent(onSuccessNodes);
                    }

                    // OnWarning
                    GraphEvent onWarning  = null;
                    var        xOnWarning = xExectionGraph.XPathSelectElement("wf:OnWarning", XmlNamespaceManager);
                    if (xOnWarning != null)
                    {
                        var onWarningNodes = GetTaskNodes(xOnWarning);
                        CheckStartupNode(onWarningNodes, "Startup node with parentId=-1 not found in OnWarning execution graph.");
                        CheckParallelTasks(onWarningNodes, "Parallel tasks execution detected in OnWarning execution graph.");
                        CheckInfiniteLoop(onWarningNodes, "Infinite loop detected in OnWarning execution graph.");
                        onWarning = new GraphEvent(onWarningNodes);
                    }

                    // OnError
                    GraphEvent onError  = null;
                    var        xOnError = xExectionGraph.XPathSelectElement("wf:OnError", XmlNamespaceManager);
                    if (xOnError != null)
                    {
                        var onErrorNodes = GetTaskNodes(xOnError);
                        CheckStartupNode(onErrorNodes, "Startup node with parentId=-1 not found in OnError execution graph.");
                        CheckParallelTasks(onErrorNodes, "Parallel tasks execution detected in OnError execution graph.");
                        CheckInfiniteLoop(onErrorNodes, "Infinite loop detected in OnError execution graph.");
                        onError = new GraphEvent(onErrorNodes);
                    }

                    ExecutionGraph = new Graph(taskNodes, onSuccess, onWarning, onError);
                }
            }
        }