diff --git a/src/dashboard/Synapse.Dashboard/Services/WorkflowGraphBuilder.cs b/src/dashboard/Synapse.Dashboard/Services/WorkflowGraphBuilder.cs index 31726aaf..8f332508 100644 --- a/src/dashboard/Synapse.Dashboard/Services/WorkflowGraphBuilder.cs +++ b/src/dashboard/Synapse.Dashboard/Services/WorkflowGraphBuilder.cs @@ -100,7 +100,7 @@ protected virtual TaskIdentity GetNextTask(Map tasksList { ArgumentNullException.ThrowIfNull(tasksList); var taskDefinition = tasksList.FirstOrDefault(taskEntry => taskEntry.Key == currentTask)?.Value; - transition = !string.IsNullOrWhiteSpace(transition) ? transition : taskDefinition != null ? taskDefinition.Then : null; + transition = !string.IsNullOrWhiteSpace(transition) ? transition : taskDefinition?.Then; if (transition == FlowDirective.End || transition == FlowDirective.Exit) { return new TaskIdentity(transition, -1, null); @@ -122,11 +122,8 @@ protected virtual TaskIdentity GetNextTask(Map tasksList { index = 0; } - if (context.Graph.AllNodes.ContainsKey(reference)) - { - return (NodeViewModel)context.Graph.AllNodes[reference]; - } - throw new IndexOutOfRangeException($"Unable to find the task with reference '{reference}' in the provided context."); + var taskEntry = tasksList.ElementAt(index); + return new TaskIdentity(taskEntry.Key, index, taskEntry.Value); } /// @@ -138,35 +135,35 @@ protected virtual void BuildTransitions(INodeViewModel node, TaskNodeRenderingCo { ArgumentNullException.ThrowIfNull(node); ArgumentNullException.ThrowIfNull(context); - this.Logger.LogTrace($"Starting WorkflowGraphBuilder.BuildTransitions from '{node.Id}'"); + this.Logger.LogTrace("Starting WorkflowGraphBuilder.BuildTransitions from '{nodeId}'", node.Id); List transitions = []; TaskIdentity nextTask = this.GetNextTask(context.TasksList, context.TaskName); transitions.Add(nextTask); - this.Logger.LogTrace($"[WorkflowGraphBuilder.BuildTransitions][{node.Id}] found transition to '{nextTask?.Name}'"); + this.Logger.LogTrace("[WorkflowGraphBuilder.BuildTransitions][{nodeId}] found transition to '{nextTaskName}'", node.Id, nextTask?.Name); while (!string.IsNullOrWhiteSpace(nextTask?.Definition?.If)) { - this.Logger.LogTrace($"[WorkflowGraphBuilder.BuildTransitions][{node.Id}] if clause found, looking up next task."); + this.Logger.LogTrace("[WorkflowGraphBuilder.BuildTransitions][{nodeId}] if clause found, looking up next task.", node.Id); nextTask = this.GetNextTask(context.TasksList, nextTask.Name); transitions.Add(nextTask); - this.Logger.LogTrace($"[WorkflowGraphBuilder.BuildTransitions][{node.Id}] found transition to '{nextTask?.Name}'"); + this.Logger.LogTrace("[WorkflowGraphBuilder.BuildTransitions][{nodeId}] found transition to '{nextTaskName}'", node.Id, nextTask?.Name); } foreach (var transition in transitions.Distinct(new TaskIdentityComparer())) { if (transition.Index != -1) { - this.Logger.LogTrace($"[WorkflowGraphBuilder.BuildTransitions][{node.Id}] Building node '{transition.Name}'"); + this.Logger.LogTrace("[WorkflowGraphBuilder.BuildTransitions][{nodeId}] Building node '{transitionName}'", node.Id, transition.Name); var transitionNode = this.BuildTaskNode(new(context.Workflow, context.Graph, context.TasksList, transition.Index, transition.Name, transition.Definition, context.TaskGroup, context.ParentReference, context.ParentContext, context.EntryNode, context.ExitNode)); - this.Logger.LogTrace($"[WorkflowGraphBuilder.BuildTransitions][{node.Id}] Building edge to node '{transition.Name}'"); + this.Logger.LogTrace("[WorkflowGraphBuilder.BuildTransitions][{nodeId}] Building edge to node '{transitionName}'", node.Id, transition.Name); this.BuildEdge(context.Graph, this.GetNodeAnchor(node, NodePortType.Exit), GetNodeAnchor(transitionNode, NodePortType.Entry)); } - else if(transition.Name == FlowDirective.Exit) + else if (transition.Name == FlowDirective.Exit) { - this.Logger.LogTrace($"[WorkflowGraphBuilder.BuildTransitions][{node.Id}] Exit transition, building edge to node '{context.ExitNode}'"); + this.Logger.LogTrace("[WorkflowGraphBuilder.BuildTransitions][{nodeId}] Exit transition, building edge to node '{contextExitNode}'", node.Id, context.ExitNode); this.BuildEdge(context.Graph, this.GetNodeAnchor(node, NodePortType.Exit), context.ExitNode); } else if (transition.Name == FlowDirective.End) { - this.Logger.LogTrace($"[WorkflowGraphBuilder.BuildTransitions][{node.Id}] End transition, building edge to node '{context.ExitNode}'"); + this.Logger.LogTrace("[WorkflowGraphBuilder.BuildTransitions][{nodeId}] End transition, building edge to node '{contextExitNode}'", node.Id, context.ExitNode); this.BuildEdge(context.Graph, this.GetNodeAnchor(node, NodePortType.Exit), context.Graph.AllNodes.Skip(1).First().Value); } else @@ -174,7 +171,7 @@ protected virtual void BuildTransitions(INodeViewModel node, TaskNodeRenderingCo throw new IndexOutOfRangeException("Invalid transition"); } } - this.Logger.LogTrace($"Exiting WorkflowGraphBuilder.BuildTransitions from '{node.Id}'"); + this.Logger.LogTrace("Exiting WorkflowGraphBuilder.BuildTransitions from '{nodeId}'", node.Id); } /// @@ -191,15 +188,15 @@ protected virtual void BuildTransitions(INodeViewModel node, TaskNodeRenderingCo protected INodeViewModel BuildTaskNode(TaskNodeRenderingContext context) { ArgumentNullException.ThrowIfNull(context); - this.Logger.LogTrace($"Starting WorkflowGraphBuilder.BuildTaskNode for {context.TaskName}"); + this.Logger.LogTrace("Starting WorkflowGraphBuilder.BuildTaskNode for '{contextTaskName}'", context.TaskName); if (context.Graph.AllNodes.ContainsKey(context.TaskReference)) { - this.Logger.LogTrace($"Exiting WorkflowGraphBuilder.BuildTaskNode for {context.TaskName}, found existing node."); + this.Logger.LogTrace("Exiting WorkflowGraphBuilder.BuildTaskNode for '{contextTaskName}', found existing node.", context.TaskName); return context.Graph.AllNodes[context.TaskReference]; } if (context.Graph.AllClusters.ContainsKey(context.TaskReference)) { - this.Logger.LogTrace($"Exiting WorkflowGraphBuilder.BuildTaskNode for {context.TaskName}, found existing cluster."); + this.Logger.LogTrace("Exiting WorkflowGraphBuilder.BuildTaskNode for '{contextTaskName}', found existing cluster.", context.TaskName); return context.Graph.AllClusters[context.TaskReference]; } return context.TaskDefinition switch @@ -360,7 +357,7 @@ protected virtual NodeViewModel BuildForkTaskNode(TaskNodeRenderingContext string.IsNullOrEmpty(switchCase.Value.When))) @@ -532,7 +529,7 @@ protected virtual NodeViewModel BuildTryTaskNode(TaskNodeRenderingContext keyValuePair.Value).FirstOrDefault(edge => edge.SourceId == source.Id && edge.TargetId == target.Id); if (edge != null) { - if (!string.IsNullOrEmpty(label)) { + if (!string.IsNullOrEmpty(label)) + { edge.Label = edge.Label + " / " + label; edge.Width = edge.Label.Length * characterSize; } @@ -752,7 +750,7 @@ public bool Equals(TaskIdentity? identity1, TaskIdentity? identity2) if (identity1 is null || identity2 is null) return false; - return identity1.Name == identity2.Name && + return identity1.Name == identity2.Name && identity1.Index == identity2.Index && identity1.Definition == identity2.Definition; }