SearchFiles() публичный статический Метод

public static SearchFiles ( IEnumerable directories, IEnumerable extensions, Action add ) : void
directories IEnumerable
extensions IEnumerable
add Action
Результат void
Пример #1
0
 private static void Code2Uml(IEnumerable <string> paths, string target)
 {
     foreach (string path in paths)
     {
         Console.WriteLine(path);
         Action <string> processFile = (filename) => {
             if (!filename.Contains("gen"))
             {
                 IParser parser = new CSharpParser();
                 IEnumerable <IUmlObject> objects = parser.Parse(filename);
                 List <string>            lines   = new List <string> ();
                 foreach (IUmlObject obj in objects)
                 {
                     lines.Add(obj.ToUmlCode());
                 }
                 string umlfile = filename.Replace(".cs", ".uml");
                 if (target.Length > 0)
                 {
                     umlfile = umlfile.ReplaceFirst(path, target + "/");
                 }
                 Console.WriteLine("Write: " + umlfile);
                 Files.WriteLines(umlfile, lines);
             }
         };
         Files.SearchFiles(path, new string[] { ".cs" }, processFile);
     }
 }
Пример #2
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);
                }
            }
        }
Пример #3
0
        private static void VisualStudio2Uml(IEnumerable <string> paths, string target)
        {
            if (target.Length > 0)
            {
                try {
                    Console.WriteLine("Read: " + target);
                    IUmlObject[] readObjs = new UmlParser().Parse(target).ToArray();
                    Console.WriteLine("Read: " + target);
                } catch (FileNotFoundException ex) {
                    Console.WriteLine(ex.ToString());
                }

                List <IUmlObject> objects = new List <IUmlObject> ();
                for (int _try = 0; _try <= 3 && objects.Count == 0; ++_try)
                {
                    foreach (string _path in paths)
                    {
                        string path = _path;
                        for (int p = 0; p < _try; ++p)
                        {
                            path += "/../";
                        }
                        Console.WriteLine(path);
                        Action <string> processFile = (filename) => {
                            if (filename.Contains("ModelDefinition") && !filename.Contains("ModelingProject"))
                            {
                                Console.WriteLine("Read: " + filename);
                                IParser parser = new VSParser();
                                objects.AddRange(parser.Parse(filename));
                            }
                        };
                        Files.SearchFiles(path, new string[] { ".uml" }, processFile);
                    }
                }
                objects.Sort();
                Console.WriteLine("Write: " + target);
                List <string> lines = new List <string> ();
                foreach (IUmlObject obj in objects.Where((o) => !IsBlacklisted(o.Name)))
                {
                    lines.Add(obj.ToUmlCode());
                    lines.Add("");
                }
                Files.WriteLines(target, lines);
            }
            else
            {
                Console.WriteLine("Error! No target file specified!");
            }
        }
Пример #4
0
        private static void Uml2Code(IEnumerable <string> paths, string _target)
        {
            foreach (string path in paths)
            {
                string target = _target.Length > 0 ? _target + "/" : path + "/codegen/";

                Console.WriteLine(path);
                List <IUmlObject> objects     = new List <IUmlObject> ();
                Action <string>   processFile = (filename) => {
                    IParser parser = new UmlParser();
                    objects.AddRange(parser.Parse(filename));
                };
                Files.SearchFiles(path, new string[] { ".uml" }, processFile);

                foreach (IUmlObject obj in objects)
                {
                    List <string> lines = new List <string> ();
                    lines.Add(obj.ToCSharpCode() + "\n");
                    string genfile = target + Packages.GetPackage(obj.Name).Replace(".", "/") + "/" + obj.Name.Clean() + ".cs";
                    Console.WriteLine("Write: " + genfile);
                    Files.WriteLines(genfile, lines);
                }
            }
        }