/
HotspotsCollection.cs
96 lines (84 loc) · 4.68 KB
/
HotspotsCollection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections.ObjectModel;
using andrena.Usus.net.Core.Prepared;
using andrena.Usus.net.View.Hub;
using andrena.Usus.net.Core.Reports;
namespace andrena.Usus.net.View.ViewModels.Hotspots
{
public class HotspotsCollection : AnalysisAwareViewModel
{
public ObservableCollection<HotspotClassSize> ClassSizes { get; private set; }
public ObservableCollection<HotspotCumulativeComponentDependency> CumulativeComponentDependencies { get; private set; }
public ObservableCollection<HotspotCyclomaticComplexity> CyclomaticComplexities { get; set; }
public ObservableCollection<HotspotMethodLength> MethodLengths { get; private set; }
public ObservableCollection<HotspotNamespaceInCycle> NamespacesInCycle { get; set; }
public ObservableCollection<HotspotNonStaticPublicFields> NonStaticPublicFields { get; set; }
public HotspotsCollection()
{
ClassSizes = new ObservableCollection<HotspotClassSize>();
CumulativeComponentDependencies = new ObservableCollection<HotspotCumulativeComponentDependency>();
CyclomaticComplexities = new ObservableCollection<HotspotCyclomaticComplexity>();
MethodLengths = new ObservableCollection<HotspotMethodLength>();
NamespacesInCycle = new ObservableCollection<HotspotNamespaceInCycle>();
NonStaticPublicFields = new ObservableCollection<HotspotNonStaticPublicFields>();
}
protected override void AnalysisStarted()
{
}
private void ClearLists()
{
ClassSizes.Clear();
CumulativeComponentDependencies.Clear();
CyclomaticComplexities.Clear();
MethodLengths.Clear();
NamespacesInCycle.Clear();
NonStaticPublicFields.Clear();
}
protected override void AnalysisFinished(PreparedMetricsReport metrics)
{
Dispatch(ClearLists);
Dispatch(() => SetClassSizes(metrics.ClassSizeHotspots, metrics.Report));
Dispatch(() => SetCumulativeComponentDependencies(metrics.CumulativeComponentDependencyHotspots, metrics.Report));
Dispatch(() => SetCyclomaticComplexities(metrics.CyclomaticComplexityHotspots, metrics.Report));
Dispatch(() => SetMethodLengths(metrics.MethodLengthHotspots, metrics.Report));
Dispatch(() => SetNamespacesInCycle(metrics.NumberOfNamespacesInCycleHotspots, metrics.Report));
Dispatch(() => SetNonStaticPublicFields(metrics.NumberOfNonStaticPublicFieldsHotspots, metrics.Report));
}
private void SetClassSizes(IEnumerable<TypeMetricsReport> classSizes, MetricsReport metrics)
{
SetHotspots(ClassSizes, classSizes.OrderByDescending(c => c.ClassSize),
m => new HotspotClassSize(m, metrics));
}
private void SetCumulativeComponentDependencies(IEnumerable<TypeMetricsReport> cumulativeComponentDependencies, MetricsReport metrics)
{
SetHotspots(CumulativeComponentDependencies, cumulativeComponentDependencies.OrderByDescending(c => c.CumulativeComponentDependency),
m => new HotspotCumulativeComponentDependency(m, metrics));
}
private void SetCyclomaticComplexities(IEnumerable<MethodMetricsReport> cyclomaticComplexities, MetricsReport metrics)
{
SetHotspots(CyclomaticComplexities, cyclomaticComplexities.OrderByDescending(m => m.CyclomaticComplexity),
m => new HotspotCyclomaticComplexity(m, metrics));
}
private void SetMethodLengths(IEnumerable<MethodMetricsReport> methodLengths, MetricsReport metrics)
{
SetHotspots(MethodLengths, methodLengths.OrderByDescending(m => m.MethodLength),
m => new HotspotMethodLength(m, metrics));
}
private void SetNamespacesInCycle(IEnumerable<NamespaceMetricsReport> namespacesInCycle, MetricsReport metrics)
{
SetHotspots(NamespacesInCycle, namespacesInCycle.OrderByDescending(n => n.NumberOfNamespacesInCycle),
m => new HotspotNamespaceInCycle(m, metrics));
}
private void SetNonStaticPublicFields(IEnumerable<TypeMetricsReport> nonStaticPublicFields, MetricsReport metrics)
{
SetHotspots(NonStaticPublicFields, nonStaticPublicFields.OrderByDescending(c => c.NumberOfNonStaticPublicFields),
m => new HotspotNonStaticPublicFields(m, metrics));
}
private void SetHotspots<T, S>(ObservableCollection<T> target, IEnumerable<S> source, Func<S, T> constructor)
{
foreach (var metrics in source) target.Add(constructor(metrics));
}
}
}