Esempio n. 1
0
        public static void Main(string[] args)
        {
            var p = new GraphVizProgram(args);

            try
            {
                p.StartConsole();

                if (p.PrintHelp())
                {
                    return;
                }

                p.ParseProgramArgs();

                ValidateBinDir();

                switch (p.DiagramType)
                {
                case Settings.FLATTENED_DIAGRAM:

                    var ft =
                        Flatten.FlattenType(new FlattenTypeArgs
                    {
                        Assembly        = p.Assembly,
                        Depth           = p.MaxDepth,
                        Separator       = "-",
                        UseTypeNames    = false,
                        TypeFullName    = p.TypeName,
                        LimitOnThisType = p.LimitOn?.ToString(),
                        DisplayEnums    = p.DisplayEnums
                    });
                    p.GraphText      = ft.ToGraphVizString();
                    p.OutputFileName = $"{p.TypeName.Replace(".", "")}Flattened.gv";
                    break;

                case Settings.CLASS_DIAGRAM:
                    p.GraphText      = Etc.GetClassDiagram(p.Assembly, p.TypeName);
                    p.OutputFileName = $"{p.TypeName.Replace(".", "")}ClassDiagram.gv";
                    break;

                case Settings.ASM_OBJ_GRAPH_DIAGRAM:
                    var asmDia = p.WithNamespaceOutlines
                            ? new AsmDiagram(p.Assembly, true)
                            : new AsmDiagram(p.Assembly);
                    p.GraphText      = asmDia.ToGraphVizString();
                    p.OutputFileName = $"{p.Assembly.GetName().Name}AsmDiagram.gv";
                    break;

                case Settings.ASM_ADJ_GRAPH:
                    var asmAdj = new AsmDiagram(p.Assembly);
                    p.OutputFileName = $"{p.Assembly.GetName().Name}AsmAdj.json";
                    p.GraphText      = asmAdj.GetAdjacencyMatrixJson();
                    break;
                }

                p.OutputFileName = Path.Combine(NfConfig.TempDirectories.Graph, p.OutputFileName);
                File.WriteAllText(p.OutputFileName, p.GraphText);

                using (var sw = new StreamWriter(Console.OpenStandardOutput(), Encoding.UTF8))
                {
                    sw.Write(p.OutputFileName);
                    sw.Flush();
                    sw.Close();
                }
            }
            catch (Exception ex)
            {
                p.PrintToConsole(ex);
            }
            Thread.Sleep(20); //slight pause
        }