Exemple #1
0
        private CyPhy.Task GetInitialTask(CyPhy.Workflow workflow)
        {
            if (workflow != null)
            {
                var allTasks = new List <CyPhy.TaskBase>();
                allTasks.AddRange(workflow.Children.TaskBaseCollection);

                var sourceTasks = allTasks
                                  .Where(x => x.AllSrcConnections.Count() == 0);

                if (sourceTasks.Count() != 1)
                {
                    // Log warning or error
                    return(null);
                }

                var startTask = sourceTasks.FirstOrDefault();
                var processed = new List <CyPhy.TaskBase>();

                while (startTask != null &&
                       startTask.Impl.MetaBase.Name != (typeof(CyPhy.Task).Name) &&
                       processed.Contains(startTask) == false)
                {
                    processed.Add(startTask);

                    var flow = startTask.DstConnections.FlowCollection.FirstOrDefault();
                    if (flow == null)
                    {
                        startTask = null;
                    }
                    else
                    {
                        startTask = flow.DstEnds.TaskBase;
                    }
                }

                if (startTask != null &&
                    startTask.Impl.MetaBase.Name == (typeof(CyPhy.Task).Name))
                {
                    return(CyPhyClasses.Task.Cast(startTask.Impl));
                }
            }

            return(null);
        }
Exemple #2
0
        // Use this method in next iteration (13.17)
        public void DoTasks(CyPhy.Workflow workflow, bool update = true)
        {
            foreach (CyPhy.Task currentTask in workflow.Children.TaskCollection)
            {
                // TODO: use Tarjan's SCC for better efficiency; this will suffice for now
                HashSet <CyPhy.Task> seen = new HashSet <CyPhy.Task>();
                seen.Add(currentTask);

                Queue <CyPhy.Flow> flows = new Queue <CyPhy.Flow>();
                foreach (var flow in currentTask.DstConnections.FlowCollection)
                {
                    flows.Enqueue(flow);
                }

                while (flows.Any())
                {
                    var nextTask = flows.Dequeue().DstEnds.Task;
                    if (nextTask == currentTask)
                    {
                        // TODO: Flag cycle error with GMEConsole
                        return;
                    }

                    if (!seen.Contains(nextTask))
                    {
                        seen.Add(nextTask);
                        foreach (var nextFlow in nextTask.DstConnections.FlowCollection)
                        {
                            flows.Enqueue(nextFlow);
                        }
                    }
                }
            }

            HashSet <CyPhy.Task> processed = new HashSet <CyPhy.Task>();
            Queue <CyPhy.Task>   waiting   = new Queue <CyPhy.Task>();

            foreach (var item in workflow.Children.TaskCollection.Where(x => !x.SrcConnections.FlowCollection.Any()))
            {
                waiting.Enqueue(item);
            }

            // In the case of joins
            while (waiting.Any())
            {
                var  currTask        = waiting.Dequeue();
                bool allPreviousDone = true;

                foreach (var flow in currTask.SrcConnections.FlowCollection)
                {
                    if (!processed.Contains(flow.SrcEnds.Task))
                    {
                        waiting.Enqueue(currTask);
                        allPreviousDone = false;
                        break;
                    }
                }

                if (!allPreviousDone)
                {
                    continue;
                }

                processed.Add(currTask);

                var json = currTask.Attributes.Parameters;
                Dictionary <string, string> values =
                    JsonConvert.DeserializeObject <Dictionary <string, string> >(json);

                if (values != null)
                {
                    foreach (var item in values)
                    {
                        if (item.Key == "AnalysisTool")
                        {
                            //var toolInfo = META.AnalysisTool.GetByName(item.Value);
                            //if (toolInfo == null)
                            //{
                            //    // TODO:
                            //    // 1. Grab progID of interpreter from workflow
                            //    // 2. Set Invocation to progID.bat
                            //}

                            //// TODO: populate description with generic info from model about workflow, task item, progid

                            //var step = new Step();
                            //step.Invocation = toolInfo.RunCommand;
                            //this.Steps.Add(step);
                        }
                    }
                }

                foreach (var item in currTask.DstConnections.FlowCollection)
                {
                    if (!waiting.Contains(item.DstEnds.Task))
                    {
                        waiting.Enqueue(item.DstEnds.Task);
                    }
                }
            }
        }