Exemplo n.º 1
0
 private static void BuildReportFromStandAloneProject(string file, string reportFile, bool ignoreGeneratedCode = false)
 {
     using (MSBuildWorkspace mSBuildWorkspace = MSBuildWorkspace.Create())
     {
         Task <Project> task = mSBuildWorkspace.OpenProjectAsync(file, new CancellationToken());
         task.Wait();
         Project[] result = new Project[] { task.Result };
         RoslynMetricsExe.BuildReport(result, reportFile, ignoreGeneratedCode);
     }
 }
Exemplo n.º 2
0
 private static void BuildReportFromSolution(string solutionFile, string reportFile, bool ignoreGeneratedCode = false)
 {
     using (MSBuildWorkspace mSBuildWorkspace = MSBuildWorkspace.Create())
     {
         mSBuildWorkspace.LoadMetadataForReferencedProjects = true;
         mSBuildWorkspace.WorkspaceFailed += MSBuildWorkspace_WorkspaceFailed;
         Task <Solution> task = mSBuildWorkspace.OpenSolutionAsync(solutionFile, new CancellationToken());
         task.Wait();
         IEnumerable <Project> list = task.Result.Projects.ToList <Project>();
         RoslynMetricsExe.BuildReport(list, reportFile, ignoreGeneratedCode);
     }
 }
Exemplo n.º 3
0
        private static void BuildReportFrom(IEnumerable <ModuleMetric> metrics, string reportFile)
        {
            CodeMetricsReport codeMetricsReport = (new MetricsReportBuilder()).Build(metrics);

            using (Stream stream = File.Open(reportFile, FileMode.OpenOrCreate, FileAccess.Write))
            {
                stream.SetLength((long)0);
                codeMetricsReport.WriteTo(stream);
                stream.Flush();
            }
            File.Create(RoslynMetricsExe.GetSuccessFileName(reportFile));
        }
Exemplo n.º 4
0
        private static int Main(string[] args)
        {
            int num;

            try
            {
                RoslynMetricsOptions roslynMetricsOption = new RoslynMetricsOptions(args);
                if (!string.IsNullOrWhiteSpace(roslynMetricsOption.File) && !string.IsNullOrWhiteSpace(roslynMetricsOption.Output))
                {
                    FileInfo fileInfo = new FileInfo(roslynMetricsOption.File);
                    if (fileInfo.Exists)
                    {
                        string lower = fileInfo.Extension.ToLower();
                        string str   = lower;
                        if (lower != null)
                        {
                            if (str == ".sln")
                            {
                                RoslynMetricsExe.BuildReportFromSolution(roslynMetricsOption.File, roslynMetricsOption.Output, roslynMetricsOption.IgnoreGeneratedCode);
                            }
                            else if (str == ".csproj")
                            {
                                RoslynMetricsExe.BuildReportFromStandAloneProject(roslynMetricsOption.File, roslynMetricsOption.Output, false);
                            }
                        }
                    }
                }
                num = 0;
            }
            catch (FileNotFoundException fileNotFoundException)
            {
                Console.Error.Write(fileNotFoundException.Message);
                num = 4098;
            }
            catch (Exception exception)
            {
                Console.Error.Write(exception.Message);
                num = 1;
            }
            return(num);
        }
Exemplo n.º 5
0
        private static void BuildReport(IEnumerable <Project> projects, string reportFile, bool ignoreGeneratedCode = false)
        {
            IEnumerable <ModuleMetric> list = RoslynMetricsExe.CalculateModuleMetrics(projects, ignoreGeneratedCode).ToList <ModuleMetric>();

            RoslynMetricsExe.BuildReportFrom(list, reportFile);
        }