public ActionPipe(IActionPipeMap map, ActionToken actionToken, IDependencyResolver dependencyResolver) { ActionToken = actionToken; this.dependencyResolver = dependencyResolver; Map = map; actions = map .UsedActionTypes .ToDictionary(k => k, t => (IAction)dependencyResolver.Resolve(t)); Current = new IAction[0]; executions = actions.Keys.ToDictionary(k => k, _ => new Queue <TimeSpan>()); }
void Generate( IActionPipeMap map , StringBuilder buffer , Func <int> labelize , Type currentNode , int currentLabel , Predicate <Type> alreadyVisited , Action <Type> addVisit , Func <Type, string> getTokenValue) { foreach (var nextNode in map.GetNext(currentNode).Where(next => !alreadyVisited(next))) { addVisit(nextNode); var nextNodeLabel = labelize(); var token = getTokenValue(currentNode); buffer.AppendLine($"{currentLabel}[{currentNode.Name}] --> |{token}| {nextNodeLabel}[{nextNode.Name}]"); Generate(map, buffer, labelize, nextNode, nextNodeLabel, alreadyVisited, addVisit, getTokenValue); } }
string Visualize(IActionPipeMap map, IEnumerable <Type> entryPoints) { var buffer = new StringBuilder(); buffer.AppendLine(Header); int label = 1; int labelize() => label++; var alreadyVisited = new HashSet <Type>(); Func <Type, string> tokenDescriptionFunction = t => GetTokenName(t); foreach (var currentNode in entryPoints) { buffer.AppendLine($"subgraph {currentNode.Name}"); Generate(map, buffer, labelize, currentNode, labelize(), alreadyVisited.Contains, t => alreadyVisited.Add(t), tokenDescriptionFunction); buffer.AppendLine("end"); } return(buffer.ToString()); }
public string Visualize(IActionPipeMap map, Type beginAt) => Visualize(map, new[] { beginAt });
public string Visualize(IActionPipeMap map) => Visualize(map, map.GetEntryPoints());