Ejemplo n.º 1
0
        public static async Task Main(string[] args)
        {
            var cfgCtx = new ConfigContext(InterfaceResolverType.ProjectLevel);

            try
            {
                var options = new ProgramOptions(args);

                if (!string.IsNullOrEmpty(options.DemoCase))
                {
                    options.CreateDemoCase();
                }

                IDoLog logger      = new ConsoleLogger(verbose: options.VerboseLogging, debug: options.DebugLogging);
                var    msBuildPath = options.PathToMSBuild;
                if (string.IsNullOrEmpty(msBuildPath))
                {
                    msBuildPath = @"C:\Program Files\dotnet\sdk\2.2.103";
                    logger.Warning("No Path to MSBuild given falling back to " + msBuildPath);
                }
                using (var solutionAnalyzer = new SolutionAnalyzer(options.PathToSolution, msBuildPath, logger))
                {
                    await solutionAnalyzer.LoadSolution(options.ExcludingAssemblies);

                    var projectAnalyzer = new ProjectAnalyzer(solutionAnalyzer.ParsedSolution, solutionAnalyzer.OutputFiles, logger);
                    await projectAnalyzer.LoadProject(options.ProjectName);

                    var interfaceResolver = InterfaceResolverFactory.GetInterfaceResolver(solutionAnalyzer, projectAnalyzer, logger, cfgCtx);

                    var    sequenceDiagram = new SequenceDiagramGenerator(projectAnalyzer.AnalyzedClasses, interfaceResolver, logger);
                    string diagramText     = await sequenceDiagram.GetSequenceDiagramForMethod(options.ClassName, options.MethodName);

                    await WriteDiagramToFile(diagramText, options.OutputFile);

                    Console.WriteLine("Wrote to " + options.OutputFile);
                }
            }
            catch (InvalidOperationException ex)
            {
                Console.WriteLine(ex.Message);
            }

            Console.WriteLine("Finished...");
        }
Ejemplo n.º 2
0
        public async Task <string> CreateDiagram(string msBuildPath, string className, string methodName, string excludingAssemblies)
        {
            var solutionDir = Path.Combine(GetTestDataPath(), _testDir, _solutionName);

            var    cfgCtx = new ConfigContext(InterfaceResolverType.ProjectLevel);
            IDoLog logger = new NullLogger();

            using (var solutionAnalyzer = new SolutionAnalyzer(solutionDir, msBuildPath, logger))
            {
                await solutionAnalyzer.LoadSolution(excludingAssemblies);

                var projectAnalyzer = new ProjectAnalyzer(solutionAnalyzer.ParsedSolution, solutionAnalyzer.OutputFiles, logger);
                await projectAnalyzer.LoadProject(_projectName);

                var interfaceResolver = InterfaceResolverFactory.GetInterfaceResolver(solutionAnalyzer, projectAnalyzer, logger, cfgCtx);

                var sequenceDiagram = new SequenceDiagramGenerator(projectAnalyzer.AnalyzedClasses, interfaceResolver, logger);
                return(await sequenceDiagram.GetSequenceDiagramForMethod(className, methodName));
            }
        }
        public DrawerTestFixture(string sourceCode, string className, string methodName)
        {
            var syntaxTree = CSharpSyntaxTree.ParseText(sourceCode);
            var syntaxRoot = syntaxTree.GetCompilationUnitRoot();
            var ns         = syntaxRoot.Members.OfType <NamespaceDeclarationSyntax>().FirstOrDefault();
            var classes    = ns.Members.OfType <ClassDeclarationSyntax>().FirstOrDefault();
            var usings     = syntaxRoot.Members.OfType <UsingDirectiveSyntax>().ToArray();
            var references = Mock.Of <List <MetadataReference> >();

            var classStructure = new ClassStructure(classes, ns, references, usings, "test", "memory");

            classStructure.ParseClass();
            MethodDeclaration = classes.Members.OfType <MethodDeclarationSyntax>()
                                .Where(m => m.Identifier.ToString().Contains(methodName)).FirstOrDefault();
            var methodStructure = new MethodStructure(classStructure, MethodDeclaration);

            var analyzedClasses = Mock.Of <IDictionary <string, IClassStructure> >();

            Mock.Get(analyzedClasses).Setup(d => d[It.IsAny <string>()]).Returns(classStructure);
            var interfaceResolver = Mock.Of <IInterfaceResolver>();

            DiagramGenerator = new SequenceDiagramGenerator(analyzedClasses, interfaceResolver, null);
        }