Skip to content

Commit

Permalink
Adding proper "Apply to each" parsing as well as an order number to e…
Browse files Browse the repository at this point in the history
…ach action (so that we can sort the output in the documentation by name or order)
  • Loading branch information
modery committed Jan 28, 2023
1 parent d887f6c commit 3d41168
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions PowerDocu.Common/ActionGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ActionNode
public Dictionary<ActionNode, string[]> nodeRunAfterConditions = new Dictionary<ActionNode, string[]>();
//list of children that are called as part of a switch
public Dictionary<ActionNode, string> switchRelationship = new Dictionary<ActionNode, string>();
public int Order;

public ActionNode(string name)
{
Expand Down
31 changes: 26 additions & 5 deletions PowerDocu.Common/FlowParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public enum PackageType
private readonly List<FlowEntity> flows = new List<FlowEntity>();
public PackageType packageType;

private int orderCounter = 1;

public FlowParser(string filename)
{
NotificationHelper.SendNotification(" - Processing " + filename);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -278,11 +281,8 @@ private void parseActions(FlowEntity flow, JEnumerable<JToken> 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
Expand Down Expand Up @@ -371,5 +371,26 @@ public List<FlowEntity> 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);
}
}
}
}
}

0 comments on commit 3d41168

Please sign in to comment.