public static TemplateMetrics Compute(Template template)
        {
            TemplateMetrics metrics = new TemplateMetrics(template);

            foreach (TemplateOutputDefinitionFilenameResult outputFilename in template.GetOutputFilenames())
            {
                metrics.FileCount++;

                if (File.Exists(outputFilename.Value))
                {
                    FileInfo fileInfo = new FileInfo(outputFilename.Value);

                    metrics.TotalFileSize += fileInfo.Length;

                    using (StreamReader reader = File.OpenText(outputFilename.Value))
                    {
                        while (!reader.EndOfStream)
                        {
                            metrics.CharacterCount += reader.ReadLine().ValueOrDefault(s => s.Length);
                            metrics.LineCount++;
                        }
                    }
                }
            }

            return metrics;
        }
        public static TemplateMetrics Compute(Template template)
        {
            TemplateMetrics metrics = new TemplateMetrics(template);

            foreach (TemplateOutputDefinitionFilenameResult outputFilename in template.GetOutputFilenames())
            {
                metrics.FileCount++;

                if (File.Exists(outputFilename.Value))
                {
                    FileInfo fileInfo = new FileInfo(outputFilename.Value);

                    metrics.TotalFileSize += fileInfo.Length;

                    using (StreamReader reader = File.OpenText(outputFilename.Value))
                    {
                        while (!reader.EndOfStream)
                        {
                            metrics.CharacterCount += reader.ReadLine().ValueOrDefault(s => s.Length);
                            metrics.LineCount++;
                        }
                    }
                }
            }

            return(metrics);
        }
Example #3
0
        /// <summary>Reads through the output file(s) associated with each template and computes metrics for each one.</summary>
        /// <param name="templates">The templates whose metrics will be computed.</param>
        /// <returns>A list of TemplateMetrics.</returns>
        public static List <TemplateMetrics> GetMetricsForTemplates(params Template[] templates)
        {
            List <TemplateMetrics> templateMetrics = new List <TemplateMetrics>(templates.Length);

            foreach (Template template in templates)
            {
                templateMetrics.Add(TemplateMetrics.Compute(template));
            }

            return(templateMetrics);
        }