diff --git a/Common/src/ArmoniK.Core.Common.csproj b/Common/src/ArmoniK.Core.Common.csproj index ac2f1f83b..cb6a00a33 100644 --- a/Common/src/ArmoniK.Core.Common.csproj +++ b/Common/src/ArmoniK.Core.Common.csproj @@ -31,7 +31,7 @@ - + diff --git a/Common/src/StateMachines/ProcessReplyCreateLargeTaskStateMachine.cs b/Common/src/StateMachines/ProcessReplyCreateLargeTaskStateMachine.cs index 7503a0bd0..f78aa605b 100644 --- a/Common/src/StateMachines/ProcessReplyCreateLargeTaskStateMachine.cs +++ b/Common/src/StateMachines/ProcessReplyCreateLargeTaskStateMachine.cs @@ -16,8 +16,6 @@ // along with this program. If not, see . using System; -using System.Linq; -using System.Text; using ArmoniK.Api.gRPC.V1; using ArmoniK.Api.gRPC.V1.Submitter; @@ -199,35 +197,6 @@ public bool IsComplete() public string GenerateGraph() => UmlDotGraph.Format(machine_.GetInfo()); - /// - /// Generate a Mermaid graph representing the Final State Machine - /// - /// - /// A string containing the graph in Mermaid format - /// - public string GenerateMermaidGraph() - { - var str = UmlMermaidGraph.Format(machine_.GetInfo()); - - // Manually fix the footer; the last - // 3 lines should be disposed - var lines = str.Split(new[] - { - Environment.NewLine, - }, - StringSplitOptions.None); - str = string.Join(Environment.NewLine, - lines.Take(lines.Length - 3)); - - // Enclose in markers for markdown - var bld = new StringBuilder(str); - bld.Insert(0, - "```mermaid\n"); - bld.Append("\n```\n"); - - return bld.ToString(); - } - /// /// Get the current state of the Final State Machine /// diff --git a/Common/src/StateMachines/UmlMermaidGraph.cs b/Common/src/StateMachines/UmlMermaidGraph.cs deleted file mode 100644 index f3b30f0c1..000000000 --- a/Common/src/StateMachines/UmlMermaidGraph.cs +++ /dev/null @@ -1,45 +0,0 @@ -// This file is part of the ArmoniK project -// -// Copyright (C) ANEO, 2021-2024. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY, without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -using Stateless.Graph; -using Stateless.Reflection; - -namespace ArmoniK.Core.Common.StateMachines; - -/// -/// Class to generate a UML graph in mermaid format -/// -// -public static class UmlMermaidGraph -{ - /// - /// Generate a UML Mermaid graph from the state machine info - /// The current implementation will output a string whose last - /// three lines do not correspond to mermaid code and have to be - /// taken out explicitly. If the output string (OutputString) is to be used in - /// a markdown document, it's also necessary to enclose it in - /// proper mermaid markers. e.g., ```mermaid OutputString ``` - /// - /// - /// - public static string Format(StateMachineInfo machineInfo) - { - var graph = new StateGraph(machineInfo); - - return graph.ToGraph(new UmlMermaidGraphStyle()); - } -} diff --git a/Common/src/StateMachines/UmlMermaidGraphStyle.cs b/Common/src/StateMachines/UmlMermaidGraphStyle.cs deleted file mode 100644 index e9a626614..000000000 --- a/Common/src/StateMachines/UmlMermaidGraphStyle.cs +++ /dev/null @@ -1,109 +0,0 @@ -// This file is part of the ArmoniK project -// -// Copyright (C) ANEO, 2021-2024. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY, without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -using System.Collections.Generic; -using System.Linq; -using System.Text; - -using Stateless.Graph; - -namespace ArmoniK.Core.Common.StateMachines; - -/// -public class UmlMermaidGraphStyle : GraphStyleBase -{ - /// - public override string GetPrefix() - => "stateDiagram-v2\ndirection TB\n"; - - /// - public override string FormatOneCluster(SuperState stateInfo) - { - var bld = new StringBuilder("\n" + $"state {stateInfo.NodeName} {{ \n)"); - - foreach (var subState in stateInfo.SubStates) - { - bld.Append(FormatOneState(subState)); - } - - return $"{bld}}}"; - } - - /// - public override string FormatOneState(State state) - { - if (state.EntryActions.Count == 0 && state.ExitActions.Count == 0) - { - return $"{state.StateName}\n"; - } - - var bld = new StringBuilder($"\nstate {state.StateName}{{\n"); - - var es = new List(); - es.AddRange(state.EntryActions.Select(act => "entry:" + act)); - es.AddRange(state.ExitActions.Select(act => "exit:" + act)); - - bld.Append(string.Join("\n", - es)); - bld.Append("\n}\n"); - - return bld.ToString(); - } - - /// - public override string FormatOneTransition(string sourceNodeName, - string trigger, - IEnumerable actions, - string destinationNodeName, - IEnumerable guards) - { - var bld = new StringBuilder(trigger ?? ""); - - if (actions?.Count() > 0) - { - bld.Append(" / " + string.Join(", ", - actions)); - } - - if (guards.Any()) - { - foreach (var info in guards) - { - if (bld.Length > 0) - { - bld.Append(' '); - } - - bld.Append(info); - } - } - - return FormatOneLine(sourceNodeName, - destinationNodeName, - bld.ToString()); - } - - /// - public override string FormatOneDecisionNode(string nodeName, - string label) - => $"{nodeName}:{label}\n"; - - private static string FormatOneLine(string fromNodeName, - string toNodeName, - string label) - => $"{fromNodeName} --> {toNodeName}:{label}\n"; -} diff --git a/Common/tests/StateMachines/ProcessReplyCreateLargeTaskStateMachineTest.cs b/Common/tests/StateMachines/ProcessReplyCreateLargeTaskStateMachineTest.cs index f5b4e5d69..c4591fa82 100644 --- a/Common/tests/StateMachines/ProcessReplyCreateLargeTaskStateMachineTest.cs +++ b/Common/tests/StateMachines/ProcessReplyCreateLargeTaskStateMachineTest.cs @@ -171,12 +171,4 @@ public void GenerateGraphShouldSucceed() Console.WriteLine(str); Assert.IsFalse(string.IsNullOrEmpty(str)); } - - [Test] - public void GenerateMermaidGraphShouldSucceed() - { - var str = sm_!.GenerateMermaidGraph(); - Console.WriteLine(str); - Assert.IsFalse(string.IsNullOrEmpty(str)); - } }