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);
}
}
}
}