public static graphml ToGraphML(DiagramArrowGraphModel diagramArrowGraph)
        {
            if (diagramArrowGraph == null)
            {
                throw new ArgumentNullException(nameof(diagramArrowGraph));
            }
            IList <DiagramNodeModel> diagramNodes = diagramArrowGraph.Nodes.ToList();
            IList <DiagramEdgeModel> diagramEdges = diagramArrowGraph.Edges.ToList();
            var graph = new graphmlGraph
            {
                id          = "G",
                edgedefault = "directed",
                node        = diagramNodes.Select(BuildArrowGraphNode).ToArray(),
                edge        = diagramEdges.Select(BuildArrowGraphEdge).ToArray()
            };

            return(new graphml
            {
                Items = new object[]
                {
                    new graphmlKey {
                        @for = "node", id = "d6", yfilestype = "nodegraphics"
                    },
                    new graphmlKey {
                        @for = "edge", id = "d10", yfilestype = "edgegraphics"
                    },
                    graph
                }
            });
        }
        public graphml Build()
        {
            var graph = new graphmlGraph();
            graph.id = "G";
            graph.edgedefault = "directed";
            graph.node = nodes.ToArray();
            graph.edge = edges.ToArray();

            return BuildGraphmlInternal(graph);
        }
Example #3
0
        public graphml Build()
        {
            var graph = new graphmlGraph();

            graph.id          = "G";
            graph.edgedefault = "directed";
            graph.node        = nodes.ToArray();
            graph.edge        = edges.ToArray();

            return(BuildGraphmlInternal(graph));
        }
Example #4
0
 private graphml BuildGraphmlInternal(graphmlGraph graph)
 {
     return(new graphml()
     {
         Items = new object[]
         {
             new graphmlKey()
             {
                 @for = "node", id = "d6", yfilestype = "nodegraphics"
             },
             new graphmlKey()
             {
                 @for = "edge", id = "d10", yfilestype = "edgegraphics"
             },
             graph
         }
     });
 }
Example #5
0
        private void ModelStatesEnum(
            graphmlGraph graph,
            ref Dictionary <string, string> states,
            ref string endStateID)
        {
            codeModel.AppendLine("    /// <summary>");
            codeModel.AppendLine("    /// Model States:");
            codeModel.AppendLine("    /// <summary>");
            codeModel.Append("    public enum ModelStates {");

            foreach (graphmlGraphNode state in graph.node)
            {
                foreach (data dt in state.data)
                {
                    foreach (ShapeNodeNodeLabel nodeLabel in dt.ShapeNode.NodeLabel)
                    {
                        string[] strState  = nodeLabel.Value.Split('\n'); // Remove the 'INDEX'
                        string   stateName = strState[0].ToLower();
                        if ((!stateName.Equals("start")) &&
                            (!stateName.Equals("end")) &&
                            (!stateName.Equals("model_configured")))
                        {
                            if (states.Count > 0)
                            {
                                codeModel.Append(", ");
                            }
                            codeModel.Append(stateName);
                            states.Add(state.id, stateName);
                        }
                        else if (stateName.Equals("end"))
                        {
                            endStateID = state.id;
                        }
                    }
                }
            }
            codeModel.Append("}");
            codeModel.AppendLine("");
            codeModel.AppendLine("");
        }
Example #6
0
        private StringBuilder ParseModel(string model, string className)
        {
            Dictionary<string, string> states = new Dictionary<string, string>();
            ArrayList acceptingState = new ArrayList();
            string endStateID = null;

            string modifier = "static";
            string modelType = "model";

            StringReader strModel = new StringReader(model);
            // Get the graph tab of the xml into the graphmlGraph object 
            XmlSerializer graphmlSerializer = new XmlSerializer(typeof(graphml));
            graphml Model = (graphml)graphmlSerializer.Deserialize(strModel);
            graphmlGraph graph = null;
            foreach (object item in Model.Items)
            {
                if (item.GetType().Name.Equals("graphmlGraph"))
                {
                    graph = (graphmlGraph)item;
                    break;
                }
            }

            // Start creating the C# code in a StringBuilder object
            codeModel = new StringBuilder();

            codeModel.AppendLine("using System;");
            codeModel.AppendLine("using System.Collections;");
            codeModel.AppendLine("using System.Collections.Generic;");
            codeModel.AppendLine("using NModel.Attributes;");
            codeModel.AppendLine("using NModel;");
            codeModel.AppendLine("using NModel.Execution;");
            codeModel.AppendLine("");
            codeModel.AppendLine("namespace " + _namespace);
            codeModel.AppendLine("{");

            codeModel.AppendLine("");
            
            // Make sure that Model_Config is parsed first
            foreach (graphmlGraphEdge edge in graph.edge)
            {
                foreach (data dt in edge.data)
                {
                    if ((dt.PolyLineEdge != null) && (dt.PolyLineEdge.EdgeLabel != null))
                    {
                        foreach (PolyLineEdgeEdgeLabel edgeLabel in dt.PolyLineEdge.EdgeLabel)
                        {
                            if (edgeLabel.Value != null)
                            {
                                string[] strCode = edgeLabel.Value.Split('\n');

                                string methodName = getBlock(strCode, "name")[0].ToLower();

                                if (methodName.Equals("model_config"))
                                {
                                    string[] configBlock = getBlock(strCode, "config");
                                    for (int curLine = 0; curLine < configBlock.Length; ++curLine)
                                    {
                                        if (configBlock[curLine].Trim().StartsWith("modifier"))
                                            modifier = (configBlock[curLine].Split(':')[1].Trim());
                                        if(configBlock[curLine].Trim().StartsWith("model_type"))
                                            modelType = (configBlock[curLine].Split(':')[1].Trim());
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (modelType == "model")
                ModelStatesEnum(graph, ref states, ref endStateID);

            if (modelType == "feature")
                codeModel.AppendLine("    [Feature]");

            // Class modifier and name:
            codeModel.AppendLine("    " + modifier + " class " + className);
            codeModel.AppendLine("    {");

            // Make sure that Model_Init is parsed second
            foreach (graphmlGraphEdge edge in graph.edge)
            {
                foreach (data dt in edge.data)
                {
                    if ((dt.PolyLineEdge != null) && (dt.PolyLineEdge.EdgeLabel != null))
                    {
                        foreach (PolyLineEdgeEdgeLabel edgeLabel in dt.PolyLineEdge.EdgeLabel)
                        {
                            if (edgeLabel.Value != null)
                            {
                                string[] strCode = edgeLabel.Value.Split('\n');
                                string methodName = getBlock(strCode, "name")[0].ToLower();
                                if (methodName.Equals("model_init"))
                                {
                                    if (modelType == "model")
                                        codeModel.AppendLine("        " + modifier + " ModelStates _curState = ModelStates." + states[edge.target].Trim() + ";");
                                    string[] initBlock = getBlock(strCode, "init");
                                    for (int curLine = 0; curLine < initBlock.Length; ++curLine)
                                    {
                                        if (initBlock[curLine].Trim() != "")
                                            codeModel.AppendLine("        " + initBlock[curLine].Trim());
                                    }
                                    codeModel.AppendLine("");                                    
                                }
                            }
                        }
                    }
                }
            }


            foreach (graphmlGraphEdge edge in graph.edge)
            {
                foreach (data dt in edge.data)
                {
                    if ((dt.PolyLineEdge != null) && (dt.PolyLineEdge.EdgeLabel != null))
                    {
                        foreach (PolyLineEdgeEdgeLabel edgeLabel in dt.PolyLineEdge.EdgeLabel)
                        {
                            if (edgeLabel.Value != null)
                            {                                
                                string[] strCode = edgeLabel.Value.Split('\n');

                                string methodName = getBlock(strCode, "name")[0].ToLower();
                                string[] parametersBlock = getBlock(strCode, "parameters");
                                string[] reqBlock = getBlock(strCode, "req");
                                string[] guardBlock = getBlock(strCode, "guard");
                                string[] actionBlock = getBlock(strCode, "action");

                                if ((!methodName.Equals("model_config")) && (!methodName.Equals("model_init")))
                                {
                                    codeModel.AppendLine("        [Action]");
                                    for (int curLine = 0; curLine < reqBlock.Length; ++curLine)
                                    {
                                        if (reqBlock[curLine].Trim() != "")
                                            codeModel.AppendLine("        [Requirement(" + reqBlock[curLine].Trim() + ")]");
                                    }                                    

                                    codeModel.AppendLine("        " + modifier + " void " + methodName + "(");
                                    for (int curLine = 0; curLine < parametersBlock.Length; ++curLine)
                                    {
                                        if (parametersBlock[curLine].Trim() != "")
                                            codeModel.AppendLine("                " + parametersBlock[curLine].Trim());
                                    }
                                    codeModel.AppendLine("        )");

                                    codeModel.AppendLine("        {");

                                    for (int curLine = 0; curLine < actionBlock.Length; ++curLine)
                                    {
                                        if (actionBlock[curLine].Trim() != "")
                                            codeModel.AppendLine("            " + actionBlock[curLine].Trim());
                                    }

                                    if (states.ContainsKey(edge.target))
                                        codeModel.AppendLine("            _curState = ModelStates." + states[edge.target].Trim() + ";");

                                    codeModel.AppendLine("        }");

                                    codeModel.AppendLine("        " + modifier + " bool " + methodName.Trim() + "Enabled" + "(");
                                    for (int curLine = 0; curLine < parametersBlock.Length; ++curLine)
                                    {
                                        if (parametersBlock[curLine].Trim() != "")
                                            codeModel.AppendLine("                " + parametersBlock[curLine].Trim());
                                    }
                                    codeModel.AppendLine("        )");

                                    codeModel.AppendLine("        {");
                                    AppendCommentsInBlock(guardBlock);
                                    SetBooleanBlock(guardBlock);
                                    if ( (modelType == "model") && (states.ContainsKey(edge.source)) ) // No key for Start and Model_Configured
                                        codeModel.AppendLine("            (_curState == ModelStates." + states[edge.source].Trim() + ")");
                                    else if (modelType == "feature")
                                        codeModel.AppendLine("            true");
                                    codeModel.AppendLine("            );");
                                    codeModel.AppendLine("        }");
                                    codeModel.AppendLine("");
                                }                                
                            }
                            else if ( (modelType == "model") && edge.target.Equals(endStateID) )
                            {
                                acceptingState.Add("_curState == ModelStates." + states[edge.source].Trim());
                            }
                        }
                    }
                }
            }

            // Set the accepting state
            if ( (modelType == "model") && (acceptingState.Count > 0) )
            {
                codeModel.AppendLine("        [AcceptingStateCondition]");
                codeModel.AppendLine("        " + modifier + " bool IsAcceptingState()");
                codeModel.AppendLine("        {");
                codeModel.AppendLine("            return(");

                string[] acceptingStateArray = new string[acceptingState.Count];
                acceptingState.CopyTo(acceptingStateArray, 0);
                for (int curLine = 0; curLine < acceptingStateArray.Length; ++curLine)
                {                    
                    codeModel.AppendLine("            (" + acceptingStateArray[curLine].Trim() + ") ||");
                }
                codeModel.AppendLine("            false);");
                codeModel.AppendLine("        }");
                codeModel.AppendLine("");
            }


            codeModel.AppendLine("    }");
            codeModel.AppendLine("}");
            return (codeModel);
        }
 private graphml BuildGraphmlInternal(graphmlGraph graph)
 {
     return new graphml()
     {
         Items = new object[]
         {
             new graphmlKey() { @for = "node", id = "d6", yfilestype = "nodegraphics" },
             new graphmlKey() { @for = "edge", id = "d10", yfilestype = "edgegraphics" },
             graph
         }
     };
 }
Example #8
0
        private void ModelStatesEnum(
            graphmlGraph graph,
            ref Dictionary<string, string> states,
            ref string endStateID)
        {
            codeModel.AppendLine("    /// <summary>");
            codeModel.AppendLine("    /// Model States:");
            codeModel.AppendLine("    /// <summary>");
            codeModel.Append("    public enum ModelStates {");

            foreach (graphmlGraphNode state in graph.node)
            {

                foreach (data dt in state.data)
                {
                    foreach (ShapeNodeNodeLabel nodeLabel in dt.ShapeNode.NodeLabel)
                    {
                        string[] strState = nodeLabel.Value.Split('\n'); // Remove the 'INDEX'
                        string stateName = strState[0].ToLower();
                        if ((!stateName.Equals("start")) &&
                            (!stateName.Equals("end")) &&
                            (!stateName.Equals("model_configured")))
                        {
                            if (states.Count > 0)
                                codeModel.Append(", ");
                            codeModel.Append(stateName);
                            states.Add(state.id, stateName);
                        }
                        else if (stateName.Equals("end"))
                            endStateID = state.id;
                    }
                }
            }
            codeModel.Append("}");
            codeModel.AppendLine("");
            codeModel.AppendLine("");
        }