/// <summary> /// Creates a new node with the specified task name. /// </summary> /// <param name="taskName">Name of the task.</param> /// <param name="action">The action.</param> /// <returns></returns> public TaskNode <T> Create(string taskName, Func <T, bool> action) { var node = new TaskNode <T>() { TaskName = taskName, Action = action, Parent = this, }; _nodes.Add(node); if (!_runnings.ContainsKey(node.TaskName)) { _runnings.Add(node.TaskName, new Count()); } return(node); }
protected internal virtual void Event(EventKind kind, TaskNode <T> taskNode, Exception exception = null) { string msg = string.Empty; if (exception != null) { msg = $"{taskNode.TaskName} is {kind} at {DateTime.Now}. {exception.Message}"; } else { msg = $"{taskNode.TaskName} is {kind} at {DateTime.Now}"; } #if DEBUG Debug.WriteLine(msg); #endif Trace.WriteLine(msg); }
/// <summary> /// Continues with the specified node /// </summary> /// <param name="node">The node.</param> /// <param name="stopIfFailed">if set to <c>true</c> [stop if the current node is failed].</param> /// <returns></returns> public TaskNode <T> ContinueWith(TaskNode <T> node, bool stopIfFailed = true) { node._guards.Add(new Guard(this, stopIfFailed)); return(node); }
public TaskNode <T> ContinueWith(string taskName, bool stopIfFailed = true) { TaskNode <T> node = Parent.Get(taskName) ?? throw new Exception($"task node {taskName} can't be resolved"); return(ContinueWith(node, stopIfFailed)); }
public Guard(TaskNode <T> taskNode, bool stopIfFailed) { _taskNode = taskNode; _stopIfFailed = stopIfFailed; }
internal void Stop(TaskNode <T> task) { _runnings[task.TaskName].Decrement(); }
internal void Start(TaskNode <T> task) { _runnings[task.TaskName].Increment(); }