private static EstadoDoProjeto CreateEstadoDoProjeto(TypeMetricWithNamespace[] types, List <MetodoRuim> metodosRuins, int totalDeMetodos, IEnumerable <INamespaceMetric> namespaceMetrics) { var resultadoGeral = new EstadoDoProjeto { Manutenibilidade = (int)types.Average(x => x.MaintainabilityIndex), LinhasDeCodigo = types.Sum(x => x.SourceLinesOfCode), ProfuDeHeranca = types.Average(x => x.DepthOfInheritance), MetodosRuins = metodosRuins, TotalDeMetodos = totalDeMetodos, TypesWithMetrics = GetClassesGroupedByRank(types) }; return(resultadoGeral); }
private static string GenerateReport(EstadoDoProjeto resultadoGeral, string solutionDirectory) { var reportDirectory = Combine(solutionDirectory, "CodeMetricsReport"); var reportPath = Combine(reportDirectory, "CodeMetricsReport.zip"); var rawReportPath = Combine(reportDirectory, "RawCodeMetricsReport.xml"); var reportTemplateFactory = new ReportTemplateFactory(); var report = reportTemplateFactory.GetReport(resultadoGeral); var list = new[] { "*.css", "*.js" }.SelectMany(ext => Directory.GetFiles(Combine(ApplicationPath, "ReportTemplate"), ext)).ToList(); Directory.CreateDirectory(reportDirectory); using (var zipArchive = new ZipArchive(OpenWrite(reportPath), ZipArchiveMode.Create)) { foreach (var item in list) { var fileName = GetFileName(item); zipArchive.CreateEntryFromFile(item, fileName); #if DEBUG Copy(item, Combine(reportDirectory, fileName), true); #endif } var archiveEntry = zipArchive.CreateEntry("Index.html"); using (var stream = archiveEntry.Open()) using (var streamWriter = new StreamWriter(stream, Encoding.UTF8)) streamWriter.Write(report); #if DEBUG reportPath = Combine(reportDirectory, "Index.html"); WriteAllText(reportPath, report, Encoding.UTF8); #endif zipArchive.Dispose(); } using (var fileStream = Open(rawReportPath, FileMode.Create)) { var xmlSerializer = new XmlSerializer(typeof(EstadoDoProjeto)); xmlSerializer.Serialize(fileStream, resultadoGeral); } return(reportPath); }
private static EstadoDoProjeto CreateEstadoDoProjeto(List<TypeMetricWithNamespace> types, List<MetodoRuim> metodosRuins, int totalDeMetodos, IEnumerable<INamespaceMetric> namespaceMetrics) { var resultadoGeral = new EstadoDoProjeto { Manutenibilidade = (int)types.Average(x => x.MaintainabilityIndex), LinhasDeCodigo = types.Sum(x => x.SourceLinesOfCode), ProfuDeHeranca = types.Average(x => x.DepthOfInheritance), MetodosRuins = metodosRuins, TotalDeMetodos = totalDeMetodos, TypesWithMetrics = GetClassesGroupedByRank(types) }; return resultadoGeral; }
private static string GenerateReport(EstadoDoProjeto resultadoGeral, string reportDirectory) { var reportPath = Path.Combine(reportDirectory, string.Format("{0}{1}.zip", "CodeMetricsReport", string.Format("-{0:yy-MM-dd-HH-mm}", DateTime.Now))); var reportTemplateFactory = new ReportTemplateFactory(); var report = reportTemplateFactory.GetReport(resultadoGeral); var list = new[] { "*.css", "*.js" }.SelectMany(ext => Directory.GetFiles(Path.Combine(ApplicationPath, "ReportTemplate"), ext)).ToList(); Directory.CreateDirectory(reportDirectory); using (var zipArchive = new ZipArchive(File.OpenWrite(reportPath), ZipArchiveMode.Create)) { foreach (var item in list) { var fileName = Path.GetFileName(item); zipArchive.CreateEntryFromFile(item, fileName); File.Copy(item, Path.Combine(reportDirectory, fileName), true); } var archiveEntry = zipArchive.CreateEntry("Index.html"); using (var stream = archiveEntry.Open()) using (var streamWriter = new StreamWriter(stream, Encoding.UTF8)) streamWriter.Write(report); reportPath = Path.Combine(reportDirectory, "Index.html"); File.WriteAllText(reportPath, report, Encoding.UTF8); zipArchive.Dispose(); } return reportPath; }