private async Task<IProjectMetric> InnerCalculate(Project project, Task<Compilation> compilationTask, Solution solution)
{
if (project == null)
{
return null;
}
var compilation = await compilationTask.ConfigureAwait(false);
var metricsTask = _metricsCalculator.Calculate(project, solution);
IEnumerable<string> dependencies;
if (solution != null)
{
var dependencyGraph = solution.GetProjectDependencyGraph();
dependencies = dependencyGraph.GetProjectsThatThisProjectTransitivelyDependsOn(project.Id)
.Select<ProjectId, Project>(id => solution.GetProject(id))
.SelectMany(x => x.MetadataReferences.Select(y => y.Display).Concat(new[] { x.AssemblyName }));
}
else
{
dependencies = project.AllProjectReferences.SelectMany(x => x.Aliases)
.Concat(project.MetadataReferences.Select(y => y.Display));
}
var assemblyTypes = compilation.Assembly.TypeNames;
var metrics = (await metricsTask.ConfigureAwait(false)).AsArray();
var internalTypesUsed = from metric in metrics
from coupling in metric.ClassCouplings
where coupling.Assembly == project.AssemblyName
select coupling;
var relationalCohesion = (internalTypesUsed.Count() + 1.0) / assemblyTypes.Count;
return new ProjectMetric(project.Name, metrics, dependencies, relationalCohesion);
}
}