Exemplo n.º 1
0
        public static string Export(ConfigurationSummary <TState, TTrigger> summary)
        {
            var dotGraph = new StringBuilder();

            dotGraph.AppendLine("digraph NStateManagerGraph {");
            if (summary.HasSubStates)
            {
                dotGraph.AppendLine("\tcompound=true;");
            }

            // ReSharper disable once StringLiteralTypo
            dotGraph.AppendLine("\trankdir=LR;");
            dotGraph.AppendLine();

            exportNonSuperStates(summary.StateDetails.Where(s => s.StateLevel == 0), dotGraph, level: 0);
            exportSuperStates(summary.StateDetails.Where(s => s.StateLevel == 1), dotGraph, level: 0);

            //List all the transitions.
            if (summary.Transitions.Any())
            {
                dotGraph.AppendLine();

                foreach (var transition in summary.Transitions)
                {
                    dotGraph.Append($"\t{transition.FromState.State} -> {transition.ToState.State}");
                    dotGraph.Append(" [label=\"");

                    if (!string.IsNullOrWhiteSpace(transition.Name))
                    {
                        dotGraph.Append(transition.Trigger);
                    }

                    if (transition.HasCondition)
                    {
                        dotGraph.Append("(*)");
                    }
                    dotGraph.Append("\"");

                    if (transition.FromState.IsSuperState)
                    {
                        dotGraph.Append($" ltail=cluster_{transition.FromState.State}");
                    }

                    if (transition.ToState.IsSuperState)
                    {
                        dotGraph.Append($" lhead=cluster_{transition.ToState.State}");
                    }

                    dotGraph.AppendLine("];");
                }
            }

            dotGraph.AppendLine("}");

            return(dotGraph.ToString());
        }
Exemplo n.º 2
0
        public static string Export(ConfigurationSummary <TState, TTrigger> summary)
        {
            var csv = new StringBuilder();

            csv.AppendLine($"FromState, TriggerEvent, ToState, Condition");

            foreach (var transition in summary.Transitions.OrderByDescending(t => t.FromState.IsStartingState).ThenByDescending(t => t.ToState.IsFinalState))
            {
                csv.AppendLine($"{transition.FromState.State}, {transition.Trigger}, {transition.ToState.State}{(transition.HasCondition ? ", *" : string.Empty)}");
            }

            return(csv.ToString());
        }
Exemplo n.º 3
0
        public static string Export(ConfigurationSummary <TState, TTrigger> summary)
        {
            var dotGraph = new StringBuilder();

            dotGraph.AppendLine("digraph NStateManagerGraph {");
            dotGraph.AppendLine("\trankdir=LR");

            //List all the nodes. Note sure this is needed, but do want to show nodes that aren't included in transitions.
            foreach (var state in summary.StateDetails.OrderBy(s => s.IsStartingState))
            {
                dotGraph.AppendLine($"\t{state.State};");
            }

            //List all the transitions.
            foreach (var transition in summary.Transitions)
            {
                dotGraph.Append($"\t{transition.FromState.State} -> {transition.ToState.State}");

                dotGraph.Append($" [label=\"");

                if (!string.IsNullOrWhiteSpace(transition.Name))
                {
                    dotGraph.Append(transition.Trigger);
                }

                if (transition.HasCondition)
                {
                    dotGraph.Append("(*)");
                }

                dotGraph.Append("\"]");

                dotGraph.AppendLine(";");
            }

            //Starting states should all be at same level
            if (summary.StartingStates.Any())
            {
                dotGraph.Append("\t{ rank=same;");
                foreach (var state in summary.StartingStates)
                {
                    dotGraph.Append(" " + state.State);
                }
                dotGraph.AppendLine(" }");
            }

            //Final states should all be at same level
            if (summary.FinalStates.Any())
            {
                dotGraph.Append("\t{ rank=same;");
                foreach (var state in summary.FinalStates)
                {
                    dotGraph.Append(" " + state.State);
                }
                dotGraph.AppendLine(" }");
            }

            dotGraph.AppendLine("}");

            return(dotGraph.ToString());
        }