예제 #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;
         IProject project;
         if (!projectManager.ShowDialogChooseAnExistingProject(ConsoleUtils.MainWindowHandle, out project)) {
            return;
         }
         Debug.Assert(project != null);

         var analysisResult = ProjectAnalysisUtils.RunAnalysisShowProgressOnConsole(project);
         Console.WriteLine("Begin Compute and Store Trend Metrics Values");

         // LogTrendMetrics() is an extension method declared by NDepend.Analysis.ExtensionMethodsProjectAnalysis
         // Two overloads are available:
         //   void LogTrendMetrics(this IAnalysisResult analysisResult, DateTime logDateTime)
         //   void LogTrendMetrics(this IAnalysisResult analysisResult, ICompareContext compareContext, DateTime logDateTime)
         analysisResult.LogTrendMetrics(DateTime.Now);  // <- Here any past or future date can be used!

         Console.WriteLine("End Compute and Store Trend Metrics Values");

         

         // 
         //   Also, from trendStore, any metric value can be persisted, with any date.
         //
         //var trendStore = project.Trend.TrendStoreDirectory.GetTrendStoreFromDirectory();
         //trendStore.SaveMetricValues(DateTime.Now, new [] {
         //   new MetricValue(new Metric("Metric1", "Unit1"), 1.0f),
         //   new MetricValue(new Metric("Metric2", "Unit2"), 2.0f),
         //});
         //
         //   The method RemoveMetricValues() can also be used to remove all metric values logged at a certain date.
         //   The date equality is defined by the same dated second, no matter the number of miliseconds.
         //trendStore.RemoveMetricValues(DateTime.Now);
      }
예제 #3
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 + "\"");
        }
        private static ICodeBase DoAnalysisGetCodeBase(
            Version version,
            ICollection <IAbsoluteFilePath> assembliesPaths,
            TemporaryProjectMode temporaryProjectMode,
            IProjectManager projectManager)
        {
            Debug.Assert(version != null);
            Debug.Assert(assembliesPaths != null);
            Debug.Assert(projectManager != null);
            Console.WriteLine("Analyze .NET fx v" + version.ToString() + " core assemblies");
            var project        = projectManager.CreateTemporaryProject(assembliesPaths, temporaryProjectMode);
            var analysisResult = ProjectAnalysisUtils.RunAnalysisShowProgressOnConsole(project);

            return(analysisResult.CodeBase);
        }
        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 + "\"");
        }