using System;
using System.IO;
using AnticipatingMinds.CodeInsight;
using AnticipatingMinds.Genesis.CodeDOM;
namespace AnticipatingMinds.Metrics{
public sealed class AccumulatedLinesCount : CodeAggregateMetric
{
internal AccumulatedLinesCount(CodeMetric aggregatedMetric):base(aggregatedMetric,MetricAggregationType.Sum)
{
}
public override string Id
{
get
{
return "AccumulatedLinesCount";
}
}
public override string Name
{
get
{
return "Lines";
}
}
public override string Description
{
get
{
return "Accumulated Lines Count.";
}
}
public override string HelpUrl
{
get
{
return String.Empty;
}
}
}
/// <summary>
/// Summary description for LinesCount.
/// </summary>
public class LinesCount : AssemblyFileMetric
{
private class MetricData
{
public decimal LinesCount = 0;
}
public override string Id
{
get
{
return "LinesCount";
}
}
public override string Name
{
get
{
return "Lines";
}
}
public override string Description
{
get
{
return "Number of Lines in the compile unit";
}
}
public override string HelpUrl
{
get
{
return string.Empty;
}
}
public override CodeAggregateMetric[] GetAggregateMetrics()
{
return new CodeAggregateMetric[1] { new AccumulatedLinesCount(this) };
}
public override decimal GetValue(CodeAssemblyFile assemblyFile)
{
decimal lineCount = 0;
try
{
if(!(assemblyFile is CodeCompileUnit))
return lineCount;
using (StreamReader sr = new StreamReader(assemblyFile.SourceFileName))
{
String line;
while ((line = sr.ReadLine()) != null)
{
lineCount++;
}
}
}
catch
{
}
return lineCount;
}
}
}
|