CSharpUML.ClassDiagram.DotCode C# (CSharp) Метод

DotCode() публичный Метод

public DotCode ( string param = "", string backgroundColor = "", int lineLength = 80 ) : IEnumerable
param string
backgroundColor string
lineLength int
Результат IEnumerable
        public IEnumerable<string> DotCode(string param = "", string backgroundColor = "", int lineLength = 80)
        {
            yield return "digraph \"MenuItem\"";
            yield return "{";
            yield return "  edge [fontname=\"Arial\",fontsize=\"8\",labelfontname=\"Lucida\",labelfontsize=\"8\"];";
            yield return "  node [fontname=\"Arial\",fontsize=\"8\",shape=record];";

            foreach (IUmlObject obj in objects) {
                string[] umlcode = obj.ToUmlCode ().Split ("\n").Where (
                    (l) => !l.Contains ("//") && !l.Contains ("Attributes") && !l.Contains ("Methods")
                ).ToArray ();
                string code = "Box_" + obj.Name.Clean () + " [label=\"{" + Escape (obj.Name) + "\\n|";
                for (int i = 1; i < umlcode.Length; ++i) {
                    if (UmlAttribute.Matches (new UmlBlock (name: umlcode [i], comments: new string[]{}))) {
                        code += EscapeLines (umlcode [i], lineLength);
                    }
                }
                //if (i > 1 && i + 1 < umlcode.Length) {
                code += "|";
                //}
                for (int i = 1; i < umlcode.Length; ++i) {
                    if (!UmlAttribute.Matches (new UmlBlock (name: umlcode [i], comments: new string[]{}))) {
                        code += EscapeLines (umlcode [i], lineLength);
                    }
                }
                string color = backgroundColor != "" ? backgroundColor
                    : obj is UmlClass && (obj as UmlClass).type == ClassType.Interface ? "dafcda"
                    : "fcfcda";
                code += "}\",height=0.2,width=0.4,color=\"black\", fillcolor=\"#" + color + "\"," + //
                    "style=\"filled\", fontcolor=\"black\"];\n";
                yield return code;
            }

            List<Inheritance> inheritances;
            List<string> unknownObjects;
            Inheritance.From (objects, out inheritances, out unknownObjects);

            foreach (string name in unknownObjects) {
                string code = "Box_" + name.Clean () + " [label=\"{" + Escape (name) + "\\n}\"";
                code += ",height=0.2,width=0.4,color=\"black\", fillcolor=\"#ffffff\"," +
                    "style=\"filled\" fontcolor=\"black\"];\n";
                yield return code;
            }

            foreach (Inheritance inh in inheritances) {
                yield return "Box_" + inh.Base.Name.Clean () + " -> Box_" + inh.Derived.Name.Clean () +
                    " [dir=\"back\",color=\"midnightblue\",fontsize=\"8\",style=\"solid\"," +
                    "arrowtail=\"onormal\",fontname=\"Helvetica\"];";
            }
            yield return param;
            yield return "}";
        }

Usage Example

Пример #1
0
        private static void Uml2Diagram(IEnumerable <string> paths, string target)
        {
            foreach (string path in paths)
            {
                Console.WriteLine(path);
                string graphdir = target.Length > 0 ? target + "/" : path + "/graphs/";

                List <IUmlObject> allObjects  = new List <IUmlObject> ();
                Action <string>   processFile = (filename) => {
                    if (!filename.Contains("graphs") && !filename.Contains("ModelDefinition"))
                    {
                        IParser parser = new UmlParser();
                        Console.WriteLine("Read: " + filename);
                        allObjects.AddRange(parser.Parse(filename));
                        //foreach (IUmlObject obj in objects) {
                        //	Console.WriteLine (obj);
                        //}
                    }
                };
                Files.SearchFiles(path, new string[] { ".uml" }, processFile);

                Console.WriteLine("Write: " + "classes.dot");
                ClassDiagram allDia = new ClassDiagram(allObjects);
                Files.WriteLines(graphdir + "classes.dot", allDia.DotCode());
                GraphViz.Dot("svg", graphdir + "classes.dot", graphdir + "classes.svg");
                GraphViz.Dot("png", graphdir + "classes.dot", graphdir + "classes.png");

                foreach (UmlClass obj in allObjects.OfType <UmlClass>())
                {
                    string filename = "class-" + obj.Name.Clean();
                    Console.WriteLine("Write: " + filename + ".svg");

                    IEnumerable <IUmlObject> relatedObjects = obj.FindRelated(allObjects);

                    // write class diagram
                    ClassDiagram dia = new ClassDiagram(relatedObjects);
                    Files.WriteLines(graphdir + filename + ".dot", dia.DotCode());
                    GraphViz.Dot("svg", graphdir + filename + ".dot", graphdir + filename + ".svg");

                    // write uml code
                    List <string> lines = new List <string> ();
                    foreach (IUmlObject relObj in relatedObjects)
                    {
                        lines.Add(relObj.ToUmlCode() + "\n");
                    }
                    Files.WriteLines(graphdir + filename + ".uml", lines);
                }
            }
        }
All Usage Examples Of CSharpUML.ClassDiagram::DotCode