From 3d41168e85c42f28e46bd7f45dfd02cb9fab3a7d Mon Sep 17 00:00:00 2001 From: Rene Modery Date: Sat, 28 Jan 2023 12:16:21 +0800 Subject: [PATCH] Adding proper "Apply to each" parsing as well as an order number to each action (so that we can sort the output in the documentation by name or order) --- PowerDocu.Common/ActionGraph.cs | 1 + PowerDocu.Common/FlowParser.cs | 31 ++++++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/PowerDocu.Common/ActionGraph.cs b/PowerDocu.Common/ActionGraph.cs index 0078f73..0df12ac 100644 --- a/PowerDocu.Common/ActionGraph.cs +++ b/PowerDocu.Common/ActionGraph.cs @@ -21,6 +21,7 @@ public class ActionNode public Dictionary nodeRunAfterConditions = new Dictionary(); //list of children that are called as part of a switch public Dictionary switchRelationship = new Dictionary(); + public int Order; public ActionNode(string name) { diff --git a/PowerDocu.Common/FlowParser.cs b/PowerDocu.Common/FlowParser.cs index 385194f..7cbb0dd 100644 --- a/PowerDocu.Common/FlowParser.cs +++ b/PowerDocu.Common/FlowParser.cs @@ -20,6 +20,8 @@ public enum PackageType private readonly List flows = new List(); public PackageType packageType; + private int orderCounter = 1; + public FlowParser(string filename) { NotificationHelper.SendNotification(" - Processing " + filename); @@ -73,6 +75,7 @@ private FlowEntity parseFlow(string flowJSON) parseMetadata(flow); parseTrigger(flow); parseActions(flow, flowDefinition.properties.definition.actions.Children(), null); + updateOrderNumbers(flow.actions.getRootNode()); parseConnectionReferences(flow); return flow; } @@ -278,11 +281,8 @@ private void parseActions(FlowEntity flow, JEnumerable actions, ActionNo aNode.Description = property.Value.ToString(); break; case "foreach": - //TODO - //{"foreach": "@outputs('List_Environment_Capacity_information')?['body/value']"} - //{"foreach": "@body('Get_calendar_view_of_events_(V2)')?['value']"} - //{"foreach": "@items('Apply_to_each_Environment')?['properties/capacity']"} - //{"foreach": "@variables('Apps_Editted')"} + // foreach is the "Apply to each" action. We simply add it to the Inputs section + aNode.actionInputs.Add(Expression.parseExpressions(property)); break; case "runtimeConfiguration": //TODO @@ -371,5 +371,26 @@ public List getFlows() { return flows; } + + private void updateOrderNumbers(ActionNode actionNode) + { + //only process it if it hasn't been processed already + if (actionNode.Order == 0) + { + actionNode.Order = orderCounter++; + foreach (ActionNode action in actionNode.Subactions) + { + updateOrderNumbers(action); + } + foreach (ActionNode action in actionNode.Elseactions) + { + updateOrderNumbers(action); + } + foreach (ActionNode action in actionNode.Neighbours) + { + updateOrderNumbers(action); + } + } + } } } \ No newline at end of file