Пример #1
0
        public void Run()
        {
            var projectManager = new NDependServicesProvider().ProjectManager;
            var dotNetManager  = new NDependServicesProvider().DotNetManager;

            // Gather most recent .NET Fx + directories containing assemblies
            var mostRecentVersion = dotNetManager.GetDotNetProfileVersionsInstalled(DotNetProfile.DotNetFramework).First();
            var dirs = dotNetManager.GetDotNetProfileDirectories(DotNetProfile.DotNetFramework, mostRecentVersion);

            Console.WriteLine(".NET Fx v" + mostRecentVersion + " directories that contains assemblies to analyze:");
            foreach (var dir in dirs)
            {
                Console.WriteLine("  -> " + dir.ToString());
            }

            // Gather all .NET Fx assembly
            var dotNetFxAssemblies = (from dir in dirs
                                      from file in dir.ChildrenFilesPath
                                      where dotNetManager.IsAssembly(file)
                                      select file).ToList();

            Console.WriteLine(dotNetFxAssemblies.Count + " .NET Fx assemblies found");

            // Create temporary NDepend project and analyze it
            var project        = projectManager.CreateTemporaryProject(dotNetFxAssemblies, TemporaryProjectMode.Temporary);
            var analysisResult = ProjectAnalysisUtils.RunAnalysisShowProgressOnConsole(project);

            // Show results
            ProjectAnalysisUtils.ShowConsoleAnalysisResult(analysisResult.CodeBase);

            Console.WriteLine("The .NET Fx analysis result produced can now be consummed live from the NDepend project named \"" + project.Properties.Name + "\"");
        }
Пример #2
0
        public void Run()
        {
            var projectManager      = new NDependServicesProvider().ProjectManager;
            var visualStudioManager = new NDependServicesProvider().VisualStudioManager;

            //
            // Gather all Most Recent Used VS solutions and projects file path referenced in registry
            //
            var vsFilesPath = new List <IAbsoluteFilePath>();

            foreach (var vsVersion in new[] { VisualStudioVersion.V7_2003, VisualStudioVersion.V8_2005, VisualStudioVersion.V9_2008, VisualStudioVersion.V10_2010 })
            {
                if (!visualStudioManager.IsVisualStudioVersionIntalled(vsVersion))
                {
                    continue;
                }
                vsFilesPath.AddRange(visualStudioManager.GetMostRecentlyUsedVisualStudioSolutionOrProject(vsVersion));
            }
            Console.WriteLine(vsFilesPath.Count + " VS sln or proj files found");

            //
            // Gather all Debug projects built from these VS solutions and projects
            //
            var projectsPath = new List <IAbsoluteFilePath>();

            foreach (var vsFilePath in vsFilesPath)
            {
                projectsPath.Add(vsFilePath);
            }

            //
            // Create temporary project
            //
            var project = projectManager.CreateTemporaryProject(projectsPath, TemporaryProjectMode.Temporary);



            //
            // Run analysis
            //
            var analysisResult = ProjectAnalysisUtils.RunAnalysisShowProgressOnConsole(project);

            //
            // Show results
            //
            ProjectAnalysisUtils.ShowConsoleAnalysisResult(analysisResult.CodeBase);


            Console.WriteLine("The analysis result produced can now be consummed from the CppDepend project \"" + project.Properties.Name + "\"");
        }
Пример #3
0
        public void Run()
        {
            var      projectManager = new NDependServicesProvider().ProjectManager;
            IProject project;

            if (!projectManager.ShowDialogChooseAnExistingProject(ConsoleUtils.MainWindowHandle, out project))
            {
                return;
            }

            // Fetch analysis results reference for the choosen project
            var analysisResultRefs = project.GetAvailableAnalysisResultsRefs();

            // Need at least 2 analysis results
            if (analysisResultRefs.Count < 2)
            {
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Cannot find at least 2 historic analysis results for the project {" + project.Properties.Name + "}");

                return;
            }


            bool showAll = false;

            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.White;

            // Sort by analysis date ascending
            analysisResultRefs = analysisResultRefs.OrderBy(analysisResultRef => analysisResultRef.Date).ToReadOnlyClonedList();

// TODO --> use .NET 4 System.Windows.Forms.DataVisualization.dll (if available), to plot chart??

            //
            // For each analysisResultRef found for this project
            //
            foreach (var analysisResultRef in analysisResultRefs)
            {
                var analysisResult = ProjectAnalysisUtils.LoadAnalysisShowProgressOnConsole(analysisResultRef);

                Console.WriteLine();
                Console.WriteLine("Analysis result produced on " + analysisResultRef.Date);

                //
                // -->If you wish to follow the evolution of a particular code element (a type for example)
                //    just retrieve the IType in each code base by type.FullName
                //      var type = codeBase.Types.WithFullName("Namespace.TypeName").
                //
                //    You can also build a ICompareContext for each 2 consecutive analysis result loaded.
                //      analysisResultNext.CodeBase.CreateCompareContextWithOlder(analysisResultPrevious.CodeBase)
                //    and use the methods
                //      ICompareContext.OlderVersion(ICodeElement):ICodeElement
                //      ICompareContext.NewerVersion(ICodeElement):ICodeElement
                //    to retrieve the newer versions of the particular code element, from its older version.
                ProjectAnalysisUtils.ShowConsoleAnalysisResult(analysisResult.CodeBase);

                // Ask all/next/quit?
                if (showAll)
                {
                    continue;
                }
                switch (ConsoleUtils.ConsoleAskShowNextAllStop())
                {
                case AllNextQuit.Next:
                    continue;

                case AllNextQuit.All:
                    showAll = true;
                    continue;

                default:
                    // Quit
                    return;
                }
            }
        }
        public void Run()
        {
            //
            // Get dir
            //


            var folderBrowserDialog = new FolderBrowserDialog {
                ShowNewFolderButton = false
            };

            if (folderBrowserDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var dir = folderBrowserDialog.SelectedPath.ToAbsoluteDirectoryPath();

            //
            // Get recursive
            //
            bool recursive = false;

            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Search assemblies recursive under {" + dir.ToString() + "} ?");
            Console.WriteLine("Yes?  y    or No? (another key)");
            var consoleKeyInfo = Console.ReadKey();

            if (consoleKeyInfo.KeyChar == 'y')
            {
                recursive = true;
            }
            Console.ForegroundColor = ConsoleColor.White;


            //
            // Get assembliesPath
            //
            var dotNetManager  = new NDependServicesProvider().DotNetManager;
            var assembliesPath = new List <IAbsoluteFilePath>();
            var cursorTop      = Console.CursorTop;

            if (!recursive)
            {
                ScanDir(dir, assembliesPath, dotNetManager, cursorTop);
            }
            else
            {
                ScanDirRecursive(dir, assembliesPath, dotNetManager, Console.CursorTop);
            }
            Console.CursorTop  = cursorTop;
            Console.CursorLeft = 0;
            ConsoleUtils.ShowNLinesOnConsole(10, ConsoleColor.Black);
            Console.CursorTop  = cursorTop;
            Console.CursorLeft = 0;

            //
            // Get project
            //
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(assembliesPath.Count + " assemblies found");
            Console.WriteLine(assembliesPath.Select(path => path.FileNameWithoutExtension).Distinct(StringComparer.InvariantCultureIgnoreCase).Count() + " assemblies with distint names found");
            Console.WriteLine("Create the NDepend temporary project.");
            var projectManager = new NDependServicesProvider().ProjectManager;
            var project        = projectManager.CreateTemporaryProject(assembliesPath, TemporaryProjectMode.Temporary);

            //
            // Run analysis
            //
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Run Analysis!");
            var analysisResult = ProjectAnalysisUtils.RunAnalysisShowProgressOnConsole(project);

            //
            // Show results
            //
            ProjectAnalysisUtils.ShowConsoleAnalysisResult(analysisResult.CodeBase);
        }
        public void Run()
        {
            var projectManager      = new NDependServicesProvider().ProjectManager;
            var visualStudioManager = new NDependServicesProvider().VisualStudioManager;

            //
            // Gather all Most Recent Used VS solutions and projects file path referenced in registry
            //
            var vsFilesPath = new List <IAbsoluteFilePath>();

            foreach (var vsVersion in new[] { VisualStudioVersion.V7_2003, VisualStudioVersion.V8_2005, VisualStudioVersion.V9_2008, VisualStudioVersion.V10_2010 })
            {
                if (!visualStudioManager.IsVisualStudioVersionIntalled(vsVersion))
                {
                    continue;
                }
                vsFilesPath.AddRange(visualStudioManager.GetMostRecentlyUsedVisualStudioSolutionOrProject(vsVersion));
            }
            Console.WriteLine(vsFilesPath.Count + " VS sln or proj files found");

            //
            // Gather all Debug assemblies built from these VS solutions and projects
            //
            var assembliesPath = new List <IAbsoluteFilePath>();

            foreach (var vsFilePath in vsFilesPath)
            {
                assembliesPath.AddRange(visualStudioManager.GetAssembliesFromVisualStudioSolutionOrProject(vsFilePath));
            }

            //
            // Create temporary project
            //
            var project = projectManager.CreateTemporaryProject(assembliesPath, TemporaryProjectMode.Temporary);

            //
            // Inform about potential assembly resolving error
            //
            IReadOnlyList <IAbsoluteFilePath>       applicationAssemblies, thirdPartyAssemblies;
            IReadOnlyList <IAssemblyResolvingError> applicationAssembliesError, thirdPartyAssembliesError;

            project.CodeToAnalyze.Resolve(out applicationAssemblies, out thirdPartyAssemblies, out applicationAssembliesError, out thirdPartyAssembliesError);
            if (applicationAssembliesError.Count > 0)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(applicationAssembliesError.Count + " assembly resolving error, assemblies with following names won't be analyzed:");
                foreach (var assemblyResolvingError in applicationAssembliesError)
                {
                    // You can use assemblyResolvingError.ErrorDescription to show error in plain english
                    // most of the time it'll be several different assemblies with the same name found.
                    Console.Write(assemblyResolvingError.AssemblyName + " ; ");
                }
                Console.ForegroundColor = ConsoleColor.White;
            }

            //
            // Run analysis
            //
            var analysisResult = ProjectAnalysisUtils.RunAnalysisShowProgressOnConsole(project);

            //
            // Show results
            //
            ProjectAnalysisUtils.ShowConsoleAnalysisResult(analysisResult.CodeBase);


            Console.WriteLine("The analysis result produced can now be consummed from the NDepend project \"" + project.Properties.Name + "\"");
        }