diff --git a/Sources2012/Usus.net.Core.UnitTests/AverageCumulativeComponentDependencyTest.cs b/Sources2012/Usus.net.Core.UnitTests/AverageCumulativeComponentDependencyTest.cs index 219edda..8099bb6 100644 --- a/Sources2012/Usus.net.Core.UnitTests/AverageCumulativeComponentDependencyTest.cs +++ b/Sources2012/Usus.net.Core.UnitTests/AverageCumulativeComponentDependencyTest.cs @@ -3,19 +3,19 @@ namespace Usus.net.Core.UnitTests { - [TestClass] - public class AverageCumulativeComponentDependencyTest - { - [TestMethod] - public void Rate_0CumulativeComponentDependencies_AverageRated0() - { - Assert.AreEqual(0.0, CreateAverage.CumulativeComponentDependency(), Constants.DELTA); - } - - [TestMethod] - public void Rate_4And3And3And3CumulativeComponentDependencies_RatedPoint8125() - { - Assert.AreEqual(0.8125, CreateAverage.CumulativeComponentDependency(4, 3, 3, 3), Constants.DELTA); - } - } + [TestClass] + public class AverageCumulativeComponentDependencyTest + { + [TestMethod] + public void Rate_0CumulativeComponentDependencies_AverageRated0() + { + Assert.IsTrue(double.IsNaN(CreateAverage.CumulativeComponentDependency())); + } + + [TestMethod] + public void Rate_4And3And3And3CumulativeComponentDependencies_RatedPoint8125() + { + Assert.AreEqual(0.8125, CreateAverage.CumulativeComponentDependency(4, 3, 3, 3), Constants.DELTA); + } + } } diff --git a/Sources2012/Usus.net.Core.UnitTests/AverageNumberOfNamespacesInCycleTest.cs b/Sources2012/Usus.net.Core.UnitTests/AverageNumberOfNamespacesInCycleTest.cs index 4dd838e..51f399a 100644 --- a/Sources2012/Usus.net.Core.UnitTests/AverageNumberOfNamespacesInCycleTest.cs +++ b/Sources2012/Usus.net.Core.UnitTests/AverageNumberOfNamespacesInCycleTest.cs @@ -3,19 +3,19 @@ namespace Usus.net.Core.UnitTests { - [TestClass] - public class AverageNumberOfNamespacesInCycleTest - { - [TestMethod] - public void Rate_0NumberOfNamespacesInCycle_AverageRated0() - { - Assert.AreEqual(0.0, CreateAverage.RatedNumberOfNamespacesInCycle(), Constants.DELTA); - } + [TestClass] + public class AverageNumberOfNamespacesInCycleTest + { + [TestMethod] + public void Rate_0NumberOfNamespacesInCycle_AverageRated0() + { + Assert.IsTrue(double.IsNaN(CreateAverage.RatedNumberOfNamespacesInCycle())); + } - [TestMethod] - public void Rate_3NumberOfNamespacesInCycle_AverageRated0() - { - Assert.AreEqual(0.6667, CreateAverage.RatedNumberOfNamespacesInCycle(2, 2, 1), Constants.DELTA); - } - } + [TestMethod] + public void Rate_3NumberOfNamespacesInCycle_AverageRated0() + { + Assert.AreEqual(0.6667, CreateAverage.RatedNumberOfNamespacesInCycle(2, 2, 1), Constants.DELTA); + } + } } diff --git a/Sources2012/Usus.net.Core.UnitTests/Factories/Metrics/Create.cs b/Sources2012/Usus.net.Core.UnitTests/Factories/Metrics/Create.cs index abcfe7e..5ce0492 100644 --- a/Sources2012/Usus.net.Core.UnitTests/Factories/Metrics/Create.cs +++ b/Sources2012/Usus.net.Core.UnitTests/Factories/Metrics/Create.cs @@ -26,7 +26,7 @@ internal static MetricsReport MetricsReport(params TypeMetricsWithMethodMetrics[ { var metricsReport = new MetricsReport(); foreach (var typeMetric in typeMetrics) - metricsReport.AddTypeReport(TypeMetrics(typeMetric.Itself, typeMetric.Methods)); + metricsReport.AddTypeReport(TypeMetrics(typeMetric.Type, typeMetric.Methods)); return metricsReport; } @@ -46,14 +46,14 @@ internal static TypeMetricsWithMethodMetrics TypeMetrics(Func methodMetrics) { - var typeWithMethods = new TypeMetricsWithMethodMetrics() { Itself = typeMetrics }; + var typeWithMethods = new TypeMetricsWithMethodMetrics() { Type = typeMetrics }; typeWithMethods.AddMethodReports(methodMetrics); return typeWithMethods; } private static NamespaceMetricsWithTypeMetrics NamespaceMetrics(NamespaceMetricsReport namespaceMetrics, IEnumerable typeMetrics) { - var namespaceWithTypes = new NamespaceMetricsWithTypeMetrics() { Itself = namespaceMetrics }; + var namespaceWithTypes = new NamespaceMetricsWithTypeMetrics() { Namespace = namespaceMetrics }; foreach (var typeMetric in typeMetrics) namespaceWithTypes.AddTypeReport(typeMetric); return namespaceWithTypes; } diff --git a/Sources2012/Usus.net.Core/AssemblyNavigation/TypeVisitor.cs b/Sources2012/Usus.net.Core/AssemblyNavigation/TypeVisitor.cs index 6d4f800..ccc7395 100644 --- a/Sources2012/Usus.net.Core/AssemblyNavigation/TypeVisitor.cs +++ b/Sources2012/Usus.net.Core/AssemblyNavigation/TypeVisitor.cs @@ -24,7 +24,7 @@ private TypeMetricsWithMethodMetrics TypeAndMethods(PdbReader pdb, IMetadataHost { var typeAndMethods = new TypeMetricsWithMethodMetrics(); typeAndMethods.AddMethodReports(AnalyzeMethods(type, pdb, host)); - typeAndMethods.Itself = AnalyzeType(type, pdb, typeAndMethods.Methods); + typeAndMethods.Type = AnalyzeType(type, pdb, typeAndMethods.Methods); return typeAndMethods; } diff --git a/Sources2012/Usus.net.Core/Graphs/GraphExtensions.cs b/Sources2012/Usus.net.Core/Graphs/GraphExtensions.cs index 7ea8056..7906b46 100644 --- a/Sources2012/Usus.net.Core/Graphs/GraphExtensions.cs +++ b/Sources2012/Usus.net.Core/Graphs/GraphExtensions.cs @@ -1,21 +1,13 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; namespace andrena.Usus.net.Core.Graphs { - public static class GraphExtensions - { - public static MutableGraph ToGraph(this IDictionary> graphDict) - where V : class - { - return new MutableGraph(graphDict); - } - - public static IGraph Select(this IGraph graph, Func vertexSelector) - where V : class - where R : class - { - return new GraphSurrogate(graph, vertexSelector); - } - } + public static class GraphExtensions + { + public static MutableGraph ToGraph(this IDictionary> graphDict) + where V : class + { + return new MutableGraph(graphDict); + } + } } diff --git a/Sources2012/Usus.net.Core/Graphs/GraphSurrogate.cs b/Sources2012/Usus.net.Core/Graphs/GraphSurrogate.cs deleted file mode 100644 index 66c4b76..0000000 --- a/Sources2012/Usus.net.Core/Graphs/GraphSurrogate.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace andrena.Usus.net.Core.Graphs -{ - internal class GraphSurrogate : IGraph - where V : class - where R : class - { - IGraph graph; - Func vertexSelector; - - internal GraphSurrogate(IGraph graph, Func vertexSelector) - { - this.graph = graph; - this.vertexSelector = vertexSelector; - } - - public IEnumerable Vertices - { - get { return graph.Vertices.Select(vertexSelector); } - } - - public IEnumerable> Edges - { - get { return graph.Edges.Select(e => Tuple.Create(vertexSelector(e.Item1), vertexSelector(e.Item2))); } - } - } -} diff --git a/Sources2012/Usus.net.Core/Graphs/IGraph.cs b/Sources2012/Usus.net.Core/Graphs/IGraph.cs index 4d0987e..441e098 100644 --- a/Sources2012/Usus.net.Core/Graphs/IGraph.cs +++ b/Sources2012/Usus.net.Core/Graphs/IGraph.cs @@ -3,9 +3,10 @@ namespace andrena.Usus.net.Core.Graphs { - public interface IGraph where V : class - { - IEnumerable Vertices { get; } - IEnumerable> Edges { get; } - } + public interface IGraph where V : class + { + IEnumerable Vertices { get; } + IEnumerable> Edges { get; } + StronglyConntectedComponents Cycles(); + } } diff --git a/Sources2012/Usus.net.Core/Graphs/MutableGraph.cs b/Sources2012/Usus.net.Core/Graphs/MutableGraph.cs index 33f0a3f..c814a54 100644 --- a/Sources2012/Usus.net.Core/Graphs/MutableGraph.cs +++ b/Sources2012/Usus.net.Core/Graphs/MutableGraph.cs @@ -1,48 +1,48 @@ +using QuickGraph; using System; using System.Collections.Generic; using System.Linq; -using QuickGraph; namespace andrena.Usus.net.Core.Graphs { - public class MutableGraph : IGraph where V : class - { - BidirectionalGraph> graph; - const bool PARALLEL_EDGES = false; - - public IEnumerable Vertices { get { return graph.Vertices; } } - public IEnumerable> Edges { get { return graph.Edges.Select(e => Tuple.Create(e.Source, e.Target)); } } - - public MutableGraph(IDictionary> graphDict) - { - graph = graphDict.Keys.ToBidirectionalGraph(v => graphDict[v].Select(e => new Edge(v, e)), PARALLEL_EDGES); - } - - internal MutableGraph(BidirectionalGraph> graph) - { - this.graph = graph; - } - - public void Reduce(V vertex, IEnumerable vertices) - { - graph.MergeVertices(vertex, vertices); - } - - public MutableGraph Reach(V start) - { - var reachGraph = start.ToNewGraph(PARALLEL_EDGES); - graph.Dfs(start, e => reachGraph.AddVerticesAndEdge(e)); - return new MutableGraph(reachGraph); - } - - public MutableGraph Cast(Func selector, Func condition) where R : class - { - return graph.Clone(selector, condition); - } - - public StronglyConntectedComponents Cycles() - { - return graph.Sccs(); - } - } + public class MutableGraph : IGraph where V : class + { + BidirectionalGraph> graph; + const bool PARALLEL_EDGES = false; + + public IEnumerable Vertices { get { return graph.Vertices; } } + public IEnumerable> Edges { get { return graph.Edges.Select(e => Tuple.Create(e.Source, e.Target)); } } + + public MutableGraph(IDictionary> graphDict) + { + graph = graphDict.Keys.ToBidirectionalGraph(v => graphDict[v].Select(e => new Edge(v, e)), PARALLEL_EDGES); + } + + internal MutableGraph(BidirectionalGraph> graph) + { + this.graph = graph; + } + + public void Reduce(V vertex, IEnumerable vertices) + { + graph.MergeVertices(vertex, vertices); + } + + public MutableGraph Reach(V start) + { + var reachGraph = start.ToNewGraph(PARALLEL_EDGES); + graph.Dfs(start, e => reachGraph.AddVerticesAndEdge(e)); + return new MutableGraph(reachGraph); + } + + public MutableGraph Cast(Func selector, Func condition) where R : class + { + return graph.Clone(selector, condition); + } + + public StronglyConntectedComponents Cycles() + { + return graph.Sccs(); + } + } } diff --git a/Sources2012/Usus.net.Core/Graphs/StronglyConntectedComponent.cs b/Sources2012/Usus.net.Core/Graphs/StronglyConntectedComponent.cs index b31e9c9..ea2752f 100644 --- a/Sources2012/Usus.net.Core/Graphs/StronglyConntectedComponent.cs +++ b/Sources2012/Usus.net.Core/Graphs/StronglyConntectedComponent.cs @@ -2,15 +2,15 @@ namespace andrena.Usus.net.Core.Graphs { - public class StronglyConntectedComponent - { - List vertexList; - public IEnumerable Vertices { get { return vertexList; } } - public int VertexCount { get { return vertexList.Count; } } + public class StronglyConntectedComponent + { + List vertexList; + public IEnumerable Vertices { get { return vertexList; } } + public int VertexCount { get { return vertexList.Count; } } - internal StronglyConntectedComponent(List vertices) - { - vertexList = vertices; - } - } + internal StronglyConntectedComponent(List vertices) + { + vertexList = vertices; + } + } } diff --git a/Sources2012/Usus.net.Core/Graphs/StronglyConntectedComponents.cs b/Sources2012/Usus.net.Core/Graphs/StronglyConntectedComponents.cs index 490a510..0219c3b 100644 --- a/Sources2012/Usus.net.Core/Graphs/StronglyConntectedComponents.cs +++ b/Sources2012/Usus.net.Core/Graphs/StronglyConntectedComponents.cs @@ -4,25 +4,36 @@ namespace andrena.Usus.net.Core.Graphs { - public class StronglyConntectedComponents - { - IDictionary> idToVertices; - IDictionary vertexToId; + public class StronglyConntectedComponents + { + IDictionary> idToVertices; + IDictionary vertexToId; - public StronglyConntectedComponents(IDictionary vertexToId, IDictionary> idToVertices) - { - this.vertexToId = vertexToId; - this.idToVertices = idToVertices; - } + public StronglyConntectedComponents(IDictionary vertexToId, IDictionary> idToVertices) + { + this.vertexToId = vertexToId; + this.idToVertices = idToVertices; + } - public StronglyConntectedComponent OfVertex(T vertex) - { - return new StronglyConntectedComponent(idToVertices[vertexToId[vertex]]); - } + public IEnumerable> All + { + get + { + foreach (var scc in idToVertices) + { + yield return new StronglyConntectedComponent(scc.Value); + } + } + } - public int Count(Func, bool> condition) - { - return idToVertices.Select(vs => new StronglyConntectedComponent(vs.Value)).Count(condition); - } - } + public StronglyConntectedComponent OfVertex(T vertex) + { + return new StronglyConntectedComponent(idToVertices[vertexToId[vertex]]); + } + + public int Count(Func, bool> condition) + { + return idToVertices.Select(vs => new StronglyConntectedComponent(vs.Value)).Count(condition); + } + } } diff --git a/Sources2012/Usus.net.Core/Metrics/CreateGraph.cs b/Sources2012/Usus.net.Core/Metrics/CreateGraph.cs index 665f0c9..87d7067 100644 --- a/Sources2012/Usus.net.Core/Metrics/CreateGraph.cs +++ b/Sources2012/Usus.net.Core/Metrics/CreateGraph.cs @@ -16,7 +16,7 @@ public static MutableGraph WithTypesOf(MetricsReport metrics) public static MutableGraph WithNamespacesOf(MetricsReport metrics) { var namespaceGraph = metrics.GraphOfTypes.Cast(t => t.AsNamespaceWithTypes(), n => n.HasName); - foreach (var namespaceGroup in namespaceGraph.Vertices.GroupBy(n => n.Itself.Name)) + foreach (var namespaceGroup in namespaceGraph.Vertices.GroupBy(n => n.Namespace.Name)) namespaceGraph.Reduce(namespaceGroup.AsNamespaceWithTypes(), namespaceGroup); return namespaceGraph; } @@ -24,7 +24,7 @@ public static MutableGraph WithNamespacesOf(Met private static NamespaceMetricsWithTypeMetrics AsNamespaceWithTypes(this IGrouping namespaceGroup) { var namespaceWithTypes = new NamespaceMetricsWithTypeMetrics(); - namespaceWithTypes.Itself = new NamespaceMetricsReport { Name = namespaceGroup.Key }; + namespaceWithTypes.Namespace = new NamespaceMetricsReport { Name = namespaceGroup.Key }; namespaceWithTypes.AddTypeReports(namespaceGroup); return namespaceWithTypes; } @@ -32,7 +32,7 @@ private static NamespaceMetricsWithTypeMetrics AsNamespaceWithTypes(this IGroupi private static NamespaceMetricsWithTypeMetrics AsNamespaceWithTypes(this TypeMetricsReport t) { var namespaceWithTypes = new NamespaceMetricsWithTypeMetrics(); - namespaceWithTypes.Itself = new NamespaceMetricsReport { Name = t.Namespaces.FirstOrDefault() }; + namespaceWithTypes.Namespace = new NamespaceMetricsReport { Name = t.Namespaces.FirstOrDefault() }; namespaceWithTypes.AddTypeReport(t); return namespaceWithTypes; } diff --git a/Sources2012/Usus.net.Core/Metrics/Namespaces/CyclicDependencies.cs b/Sources2012/Usus.net.Core/Metrics/Namespaces/CyclicDependencies.cs index c2de96e..7a3f46b 100644 --- a/Sources2012/Usus.net.Core/Metrics/Namespaces/CyclicDependencies.cs +++ b/Sources2012/Usus.net.Core/Metrics/Namespaces/CyclicDependencies.cs @@ -21,7 +21,7 @@ public static IEnumerable Of(NamespaceMetricsWithTypeMetrics namespaceWi private static IEnumerable GetOtherNamespacesInSameCycleIn(this NamespaceMetricsWithTypeMetrics namespaceWithTypes, StronglyConntectedComponents cycles) { return from n in cycles.OfVertex(namespaceWithTypes).Vertices - select n.Itself; + select n.Namespace; } } } \ No newline at end of file diff --git a/Sources2012/Usus.net.Core/Metrics/PostProcessNamespaceDependencies.cs b/Sources2012/Usus.net.Core/Metrics/PostProcessNamespaceDependencies.cs index 7a4d86a..abf0741 100644 --- a/Sources2012/Usus.net.Core/Metrics/PostProcessNamespaceDependencies.cs +++ b/Sources2012/Usus.net.Core/Metrics/PostProcessNamespaceDependencies.cs @@ -17,7 +17,7 @@ private static void SetNamespacesWithCyclicDependencies(this MetricsReport metri foreach (var namespaceWithTypes in metrics.GraphOfNamespaces.Vertices) { metrics.AddNamespaceReport(namespaceWithTypes); - namespaceWithTypes.Itself.CyclicDependencies = CyclicDependencies.Of(namespaceWithTypes, cycles); + namespaceWithTypes.Namespace.CyclicDependencies = CyclicDependencies.Of(namespaceWithTypes, cycles); } } } diff --git a/Sources2012/Usus.net.Core/Reports/MetricsReport.cs b/Sources2012/Usus.net.Core/Reports/MetricsReport.cs index 146df4d..dadd8ae 100644 --- a/Sources2012/Usus.net.Core/Reports/MetricsReport.cs +++ b/Sources2012/Usus.net.Core/Reports/MetricsReport.cs @@ -1,101 +1,101 @@ -using System.Collections.Generic; +using andrena.Usus.net.Core.Graphs; +using System.Collections.Generic; using System.Linq; -using andrena.Usus.net.Core.Graphs; namespace andrena.Usus.net.Core.Reports { - public class MetricsReport - { - internal static MetricsReport Of(params MetricsReport[] reports) - { - var combinedReport = new MetricsReport(); - combinedReport.Remember.WhenCreated = reports.FirstCreated(); - AddTypesOf(reports, combinedReport); - combinedReport.CommonKnowledge.SetAssemblies(reports.Length); - return combinedReport; - } - - private static void AddTypesOf(MetricsReport[] reports, MetricsReport combinedReport) - { - foreach (var typeMetrics in reports.SelectMany(r => r.typeReports.Values)) - combinedReport.AddTypeReport(typeMetrics); - } - - Dictionary typeReports; - Dictionary namespaceReports; - Dictionary methodToType; - - internal MutableGraph GraphOfTypes { get; set; } - internal MutableGraph GraphOfNamespaces { get; set; } - - public CommonReportKnowledge CommonKnowledge { get; private set; } - public MetricsReportInfo Remember { get; private set; } - - public IEnumerable Methods - { - get { return typeReports.Values.SelectMany(t => t.Methods); } - } - - public IGraph TypeGraph - { - get { return GraphOfTypes; } - } - - public IEnumerable Types - { - get { return typeReports.Values.Select(t => t.Itself); } - } - - public IGraph NamespaceGraph - { - get { return GraphOfNamespaces.Select(n => n.Itself); } - } - - public IEnumerable Namespaces - { - get { return namespaceReports.Values.Select(t => t.Itself); } - } - - internal MetricsReport() - { - Remember = new MetricsReportInfo(); - CommonKnowledge = new CommonReportKnowledge(); - typeReports = new Dictionary(); - namespaceReports = new Dictionary(); + public class MetricsReport + { + internal static MetricsReport Of(params MetricsReport[] reports) + { + var combinedReport = new MetricsReport(); + combinedReport.Remember.WhenCreated = reports.FirstCreated(); + AddTypesOf(reports, combinedReport); + combinedReport.CommonKnowledge.SetAssemblies(reports.Length); + return combinedReport; + } + + private static void AddTypesOf(MetricsReport[] reports, MetricsReport combinedReport) + { + foreach (var typeMetrics in reports.SelectMany(r => r.typeReports.Values)) + combinedReport.AddTypeReport(typeMetrics); + } + + Dictionary typeReports; + Dictionary namespaceReports; + Dictionary methodToType; + + internal MutableGraph GraphOfTypes { get; set; } + internal MutableGraph GraphOfNamespaces { get; set; } + + public CommonReportKnowledge CommonKnowledge { get; private set; } + public MetricsReportInfo Remember { get; private set; } + + public IEnumerable Methods + { + get { return typeReports.Values.SelectMany(t => t.Methods); } + } + + public IGraph TypeGraph + { + get { return GraphOfTypes; } + } + + public IEnumerable Types + { + get { return typeReports.Values.Select(t => t.Type); } + } + + public IGraph NamespaceGraph + { + get { return GraphOfNamespaces; } + } + + public IEnumerable Namespaces + { + get { return namespaceReports.Values.Select(t => t.Namespace); } + } + + internal MetricsReport() + { + Remember = new MetricsReportInfo(); + CommonKnowledge = new CommonReportKnowledge(); + typeReports = new Dictionary(); + namespaceReports = new Dictionary(); methodToType = new Dictionary(); - } - - internal void AddNamespaceReport(NamespaceMetricsWithTypeMetrics namespaceMertics) - { - namespaceReports.Add(namespaceMertics.Itself.Name, namespaceMertics); - namespaceMertics.Itself.CommonKnowledge = CommonKnowledge; - CommonKnowledge.UpdateFor(namespaceMertics); - } - - internal void AddTypeReport(TypeMetricsWithMethodMetrics typeMertics) - { - if (!typeReports.ContainsKey(typeMertics.Itself.FullName)) - { - typeReports.Add(typeMertics.Itself.FullName, typeMertics); - ShareTheKnowledgeWithMethodsOf(typeMertics); - CommonKnowledge.UpdateFor(typeMertics.Itself); - } - } - - internal TypeMetricsReport TypeForName(string fullName) - { - return typeReports[fullName].Itself; - } - - internal NamespaceMetricsReport NamespaceForName(string fullName) - { - return namespaceReports[fullName].Itself; - } - - internal IEnumerable MethodsOf(TypeMetricsReport type) - { - return typeReports[type.FullName].Methods; - } + } + + internal void AddNamespaceReport(NamespaceMetricsWithTypeMetrics namespaceMertics) + { + namespaceReports.Add(namespaceMertics.Namespace.Name, namespaceMertics); + namespaceMertics.Namespace.CommonKnowledge = CommonKnowledge; + CommonKnowledge.UpdateFor(namespaceMertics); + } + + internal void AddTypeReport(TypeMetricsWithMethodMetrics typeMertics) + { + if (!typeReports.ContainsKey(typeMertics.Type.FullName)) + { + typeReports.Add(typeMertics.Type.FullName, typeMertics); + ShareTheKnowledgeWithMethodsOf(typeMertics); + CommonKnowledge.UpdateFor(typeMertics.Type); + } + } + + internal TypeMetricsReport TypeForName(string fullName) + { + return typeReports[fullName].Type; + } + + internal NamespaceMetricsReport NamespaceForName(string fullName) + { + return namespaceReports[fullName].Namespace; + } + + internal IEnumerable MethodsOf(TypeMetricsReport type) + { + return typeReports[type.FullName].Methods; + } internal TypeMetricsReport TypeOf(MethodMetricsReport methodMetrics) { @@ -107,17 +107,17 @@ internal IEnumerable TypesOf(NamespaceMetricsReport namespace return namespaceReports[namespaceMetrics.Name].Types; } - private void ShareTheKnowledgeWithMethodsOf(TypeMetricsWithMethodMetrics typeMertics) - { - typeMertics.Itself.CommonKnowledge = CommonKnowledge; - foreach (var method in typeMertics.Methods) - { - CommonKnowledge.UpdateFor(method); - method.CommonKnowledge = CommonKnowledge; + private void ShareTheKnowledgeWithMethodsOf(TypeMetricsWithMethodMetrics typeMertics) + { + typeMertics.Type.CommonKnowledge = CommonKnowledge; + foreach (var method in typeMertics.Methods) + { + CommonKnowledge.UpdateFor(method); + method.CommonKnowledge = CommonKnowledge; if (!methodToType.ContainsKey(method)) - methodToType.Add(method, typeMertics.Itself); - } - } - } + methodToType.Add(method, typeMertics.Type); + } + } + } } diff --git a/Sources2012/Usus.net.Core/Reports/NamespaceMetricsReportSearch.cs b/Sources2012/Usus.net.Core/Reports/NamespaceMetricsReportSearch.cs index 3ed8a19..cdddded 100644 --- a/Sources2012/Usus.net.Core/Reports/NamespaceMetricsReportSearch.cs +++ b/Sources2012/Usus.net.Core/Reports/NamespaceMetricsReportSearch.cs @@ -1,11 +1,11 @@ namespace andrena.Usus.net.Core.Reports { - public static class NamespaceMetricsReportSearch - { - public static NamespaceMetricsReport ForNamespace(this MetricsReport metrics, string namespaceName) - { - return metrics.NamespaceForName(namespaceName); - } - } + public static class NamespaceMetricsReportSearch + { + public static NamespaceMetricsReport ForNamespace(this MetricsReport metrics, string namespaceName) + { + return metrics.NamespaceForName(namespaceName); + } + } } diff --git a/Sources2012/Usus.net.Core/Reports/NamespaceMetricsWithTypeMetrics.cs b/Sources2012/Usus.net.Core/Reports/NamespaceMetricsWithTypeMetrics.cs index 24b69e7..4605901 100644 --- a/Sources2012/Usus.net.Core/Reports/NamespaceMetricsWithTypeMetrics.cs +++ b/Sources2012/Usus.net.Core/Reports/NamespaceMetricsWithTypeMetrics.cs @@ -3,30 +3,32 @@ namespace andrena.Usus.net.Core.Reports { - internal class NamespaceMetricsWithTypeMetrics - { - public NamespaceMetricsReport Itself { get; internal set; } - public bool HasName { get { return !string.IsNullOrEmpty(Itself.Name); } } + public class NamespaceMetricsWithTypeMetrics + { + public NamespaceMetricsReport Namespace { get; internal set; } + public string Name { get { return Namespace.Name; } } - List TypeReports; - public IEnumerable Types - { - get { return TypeReports; } - } + internal bool HasName { get { return !string.IsNullOrEmpty(Namespace.Name); } } - internal NamespaceMetricsWithTypeMetrics() - { - TypeReports = new List(); - } + List TypeReports; + public IEnumerable Types + { + get { return TypeReports; } + } - internal void AddTypeReport(TypeMetricsReport typeReport) - { - TypeReports.Add(typeReport); - } + internal NamespaceMetricsWithTypeMetrics() + { + TypeReports = new List(); + } - internal void AddTypeReports(IEnumerable typeReports) - { - TypeReports.AddRange(typeReports.SelectMany(n => n.TypeReports)); - } - } + internal void AddTypeReport(TypeMetricsReport typeReport) + { + TypeReports.Add(typeReport); + } + + internal void AddTypeReports(IEnumerable typeReports) + { + TypeReports.AddRange(typeReports.SelectMany(n => n.TypeReports)); + } + } } diff --git a/Sources2012/Usus.net.Core/Reports/TypeMetricsWithMethodMetrics.cs b/Sources2012/Usus.net.Core/Reports/TypeMetricsWithMethodMetrics.cs index a762c98..dce8e30 100644 --- a/Sources2012/Usus.net.Core/Reports/TypeMetricsWithMethodMetrics.cs +++ b/Sources2012/Usus.net.Core/Reports/TypeMetricsWithMethodMetrics.cs @@ -2,24 +2,24 @@ namespace andrena.Usus.net.Core.Reports { - internal class TypeMetricsWithMethodMetrics - { - public TypeMetricsReport Itself { get; internal set; } - - List MethodReports; - public IEnumerable Methods - { - get { return MethodReports; } - } + internal class TypeMetricsWithMethodMetrics + { + public TypeMetricsReport Type { get; internal set; } - internal TypeMetricsWithMethodMetrics() - { - MethodReports = new List(); - } + List MethodReports; + public IEnumerable Methods + { + get { return MethodReports; } + } - internal void AddMethodReports(IEnumerable methodMertics) - { - MethodReports.AddRange(methodMertics); - } - } + internal TypeMetricsWithMethodMetrics() + { + MethodReports = new List(); + } + + internal void AddMethodReports(IEnumerable methodMertics) + { + MethodReports.AddRange(methodMertics); + } + } } diff --git a/Sources2012/Usus.net.View/Dialogs/ViewModels/OutOfNamespaceReference.cs b/Sources2012/Usus.net.Core/Reports/TypeReference.cs similarity index 76% rename from Sources2012/Usus.net.View/Dialogs/ViewModels/OutOfNamespaceReference.cs rename to Sources2012/Usus.net.Core/Reports/TypeReference.cs index c516a59..b0897df 100644 --- a/Sources2012/Usus.net.View/Dialogs/ViewModels/OutOfNamespaceReference.cs +++ b/Sources2012/Usus.net.Core/Reports/TypeReference.cs @@ -1,10 +1,9 @@ -using andrena.Usus.net.Core.Reports; using System.Collections.Generic; using System.Linq; -namespace andrena.Usus.net.View.Dialogs.ViewModels +namespace andrena.Usus.net.Core.Reports { - public class OutOfNamespaceReference + public class TypeReference { private readonly MetricsReport metrics; @@ -19,7 +18,7 @@ public NamespaceMetricsReport TargetNamespace get { return metrics.ForNamespace(Target.Namespaces.First()); } } - public OutOfNamespaceReference(MetricsReport metrics, TypeMetricsReport source, TypeMetricsReport target) + public TypeReference(MetricsReport metrics, TypeMetricsReport source, TypeMetricsReport target) { this.metrics = metrics; this.Source = source; diff --git a/Sources2012/Usus.net.Core/Usus.net.Core.csproj b/Sources2012/Usus.net.Core/Usus.net.Core.csproj index 6cd7d00..b4b3e4a 100644 --- a/Sources2012/Usus.net.Core/Usus.net.Core.csproj +++ b/Sources2012/Usus.net.Core/Usus.net.Core.csproj @@ -87,7 +87,6 @@ - @@ -160,6 +159,7 @@ + diff --git a/Sources2012/Usus.net.View/Cockpit.xaml.cs b/Sources2012/Usus.net.View/Cockpit.xaml.cs index f06c9fc..b2c8ece 100644 --- a/Sources2012/Usus.net.View/Cockpit.xaml.cs +++ b/Sources2012/Usus.net.View/Cockpit.xaml.cs @@ -1,32 +1,31 @@ using System.Windows.Controls; using andrena.Usus.net.Core.Reports; -using andrena.Usus.net.View.Dialogs; -using andrena.Usus.net.View.Dialogs.ViewModels; +using andrena.Usus.net.View.Dialogs.List; namespace andrena.Usus.net.View { - public partial class Cockpit : UserControl - { - public ViewModels.Cockpit.Cockpit ViewModel { get { return DataContext as ViewModels.Cockpit.Cockpit; } } + public partial class Cockpit : UserControl + { + public ViewModels.Cockpit.Cockpit ViewModel { get { return DataContext as ViewModels.Cockpit.Cockpit; } } - public Cockpit() - { - InitializeComponent(); - } + public Cockpit() + { + InitializeComponent(); + } - private void DataGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) - { - var listDisplay = new ListDisplay(); - listDisplay.ItemClicked += i => ViewModel.JumpToMethod(i as MethodMetricsReport); - listDisplay.DataContext = CreateChangedMethods(); - listDisplay.Show(); - } + private void DataGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) + { + var listDisplay = new ListDisplay(); + listDisplay.ItemClicked += i => ViewModel.JumpToMethod(i as MethodMetricsReport); + listDisplay.DataContext = CreateChangedMethods(); + listDisplay.Show(); + } - private ListDisplay CreateChangedMethods() - { - var methodChanges = new ListDisplay("Changed Methods since last build"); - methodChanges.AddAll(ViewModel.ChangedMethods); - return methodChanges; - } - } + private ListDisplay CreateChangedMethods() + { + var methodChanges = new ListDisplay("Changed Methods since last build"); + methodChanges.AddAll(ViewModel.ChangedMethods); + return methodChanges; + } + } } diff --git a/Sources2012/Usus.net.View/Dialogs/List/ListDisplay.cs b/Sources2012/Usus.net.View/Dialogs/List/ListDisplay.cs new file mode 100644 index 0000000..933772e --- /dev/null +++ b/Sources2012/Usus.net.View/Dialogs/List/ListDisplay.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace andrena.Usus.net.View.Dialogs.List +{ + public class ListDisplay + { + public string Header { get; private set; } + public ObservableCollection Entries { get; private set; } + + public ListDisplay(string header) + { + Header = header; + Entries = new ObservableCollection(); + } + + public void AddAll(IEnumerable entries) + { + if (entries != null) + foreach (var entry in entries) Entries.Add(entry); + } + } +} diff --git a/Sources2012/Usus.net.View/Dialogs/ListDisplay.xaml b/Sources2012/Usus.net.View/Dialogs/List/ListDisplay.xaml similarity index 85% rename from Sources2012/Usus.net.View/Dialogs/ListDisplay.xaml rename to Sources2012/Usus.net.View/Dialogs/List/ListDisplay.xaml index 7397201..174bc17 100644 --- a/Sources2012/Usus.net.View/Dialogs/ListDisplay.xaml +++ b/Sources2012/Usus.net.View/Dialogs/List/ListDisplay.xaml @@ -1,4 +1,4 @@ - diff --git a/Sources2012/Usus.net.View/Dialogs/List/ListDisplay.xaml.cs b/Sources2012/Usus.net.View/Dialogs/List/ListDisplay.xaml.cs new file mode 100644 index 0000000..d513c04 --- /dev/null +++ b/Sources2012/Usus.net.View/Dialogs/List/ListDisplay.xaml.cs @@ -0,0 +1,30 @@ +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; + +namespace andrena.Usus.net.View.Dialogs.List +{ + public partial class ListDisplay : Window + { + public event Action ItemClicked; + + public ListDisplay() + { + InitializeComponent(); + ItemClicked += i => { }; + } + + private void ListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) + { + var selectedItem = (sender as ListBox).SelectedItem; + if (selectedItem != null) TakeValue(selectedItem); + } + + private void TakeValue(object selectedItem) + { + ItemClicked(selectedItem); + this.Close(); + } + } +} diff --git a/Sources2012/Usus.net.View/Dialogs/ListDisplay.xaml.cs b/Sources2012/Usus.net.View/Dialogs/ListDisplay.xaml.cs deleted file mode 100644 index aed64ab..0000000 --- a/Sources2012/Usus.net.View/Dialogs/ListDisplay.xaml.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; - -namespace andrena.Usus.net.View.Dialogs -{ - public partial class ListDisplay : Window - { - public event Action ItemClicked; - - public ListDisplay() - { - InitializeComponent(); - ItemClicked += i => { }; - } - - private void ListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) - { - var selectedItem = (sender as ListBox).SelectedItem; - if (selectedItem != null) TakeValue(selectedItem); - } - - private void TakeValue(object selectedItem) - { - ItemClicked(selectedItem); - this.Close(); - } - } -} diff --git a/Sources2012/Usus.net.View/Dialogs/NamespaceCycleDisplay.xaml.cs b/Sources2012/Usus.net.View/Dialogs/NamespaceCycleDisplay.xaml.cs deleted file mode 100644 index eec8fdd..0000000 --- a/Sources2012/Usus.net.View/Dialogs/NamespaceCycleDisplay.xaml.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Windows; - -namespace andrena.Usus.net.View.Dialogs -{ - public partial class NamespaceCycleDisplay : Window - { - public NamespaceCycleDisplay() - { - InitializeComponent(); - } - } -} diff --git a/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycle.cs b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycle.cs new file mode 100644 index 0000000..d33e1de --- /dev/null +++ b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycle.cs @@ -0,0 +1,54 @@ +using andrena.Usus.net.Core.Helper; +using andrena.Usus.net.Core.Reports; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace andrena.Usus.net.View.Dialogs.NamespaceCycles +{ + public class NamespaceCycle + { + private readonly IEnumerable namespaces; + private readonly MetricsReport metrics; + + public NamespaceCycle(MetricsReport metrics, IEnumerable namespaces) + { + this.metrics = metrics; + this.namespaces = namespaces; + Jump += type => { }; + } + + public event Action Jump; + + public IEnumerable Namespaces + { + get { return namespaces.Select(n => n.Name); } + } + + public IEnumerable TypesReferencingOutOf(string namespaceName) + { + var currentNamespace = metrics.ForNamespace(namespaceName); + var otherNamespaceInCycle = namespaces.ExceptThis(currentNamespace).ToList(); + return from reference in ReferencesOutOf(currentNamespace, to: otherNamespaceInCycle) + select reference; + } + + private IEnumerable ReferencesOutOf(NamespaceMetricsReport currentNamespace, IEnumerable to) + { + return from typeReferences in AllTypesWithReferencesIn(currentNamespace) + from crossReference in typeReferences.Referencing(to) + select crossReference; + } + + private IEnumerable AllTypesWithReferencesIn(NamespaceMetricsReport currentNamespace) + { + return from type in metrics.TypesOfNamespace(currentNamespace) + select new OutgoingTypeReferences(metrics, type); + } + + public void JumpTo(string type) + { + Jump(metrics.ForType(type.Substring(0, type.IndexOf("\n")))); + } + } +} diff --git a/Sources2012/Usus.net.View/Dialogs/NamespaceCycleDisplay.xaml b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleDisplay.xaml similarity index 77% rename from Sources2012/Usus.net.View/Dialogs/NamespaceCycleDisplay.xaml rename to Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleDisplay.xaml index 3b534a1..750f407 100644 --- a/Sources2012/Usus.net.View/Dialogs/NamespaceCycleDisplay.xaml +++ b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleDisplay.xaml @@ -1,10 +1,10 @@ - - + diff --git a/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleDisplay.xaml.cs b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleDisplay.xaml.cs new file mode 100644 index 0000000..7d25474 --- /dev/null +++ b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleDisplay.xaml.cs @@ -0,0 +1,12 @@ +using System.Windows; + +namespace andrena.Usus.net.View.Dialogs.NamespaceCycles +{ + public partial class NamespaceCycleDisplay : Window + { + public NamespaceCycleDisplay() + { + InitializeComponent(); + } + } +} diff --git a/Sources2012/Usus.net.View/Dialogs/ViewModels/NamespaceCycleDisplayVM.cs b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleDisplayVM.cs similarity index 83% rename from Sources2012/Usus.net.View/Dialogs/ViewModels/NamespaceCycleDisplayVM.cs rename to Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleDisplayVM.cs index 1a32e7e..bd01359 100644 --- a/Sources2012/Usus.net.View/Dialogs/ViewModels/NamespaceCycleDisplayVM.cs +++ b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleDisplayVM.cs @@ -1,14 +1,15 @@ +using andrena.Usus.net.View.ViewModels; using QuickGraph; using System.Collections.ObjectModel; using System.Linq; -namespace andrena.Usus.net.View.Dialogs.ViewModels +namespace andrena.Usus.net.View.Dialogs.NamespaceCycles { public class NamespaceCycleDisplayVM : GraphViewModel { public string Header { get; private set; } public ObservableCollection MainEntries { get; private set; } - public ObservableCollection SubEntries { get; private set; } + public ObservableCollection SubEntries { get; private set; } public IBidirectionalGraph> Graph { get; private set; } private NamespaceCycle cycle; @@ -17,7 +18,7 @@ public NamespaceCycleDisplayVM(string header) { Header = header; MainEntries = new ObservableCollection(); - SubEntries = new ObservableCollection(); + SubEntries = new ObservableCollection(); } public void Display(NamespaceCycle namespaceCycle) @@ -49,7 +50,7 @@ public void SelectNamespace(string namespaceName) { SubEntries.Clear(); foreach (var type in cycle.TypesReferencingOutOf(namespaceName)) - SubEntries.Add(new OutOfNamespaceReferenceVM(type)); + SubEntries.Add(new TypeReferenceVM(type)); } public void SelectType(string type) diff --git a/Sources2012/Usus.net.View/Dialogs/NamespaceCycleGraphView.xaml b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleGraphView.xaml similarity index 96% rename from Sources2012/Usus.net.View/Dialogs/NamespaceCycleGraphView.xaml rename to Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleGraphView.xaml index e6dd22e..43074db 100644 --- a/Sources2012/Usus.net.View/Dialogs/NamespaceCycleGraphView.xaml +++ b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleGraphView.xaml @@ -1,38 +1,38 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + diff --git a/Sources2012/Usus.net.View/Dialogs/NamespaceCycleGraphView.xaml.cs b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleGraphView.xaml.cs similarity index 82% rename from Sources2012/Usus.net.View/Dialogs/NamespaceCycleGraphView.xaml.cs rename to Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleGraphView.xaml.cs index d38bf32..7b22957 100644 --- a/Sources2012/Usus.net.View/Dialogs/NamespaceCycleGraphView.xaml.cs +++ b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleGraphView.xaml.cs @@ -1,15 +1,15 @@ -using System.Windows.Controls; - -namespace andrena.Usus.net.View.Dialogs -{ - /// - /// Interaction logic for NamespaceCycleGraphView.xaml - /// - public partial class NamespaceCycleGraphView : UserControl - { - public NamespaceCycleGraphView() - { - InitializeComponent(); - } - } -} +using System.Windows.Controls; + +namespace andrena.Usus.net.View.Dialogs.NamespaceCycles +{ + /// + /// Interaction logic for NamespaceCycleGraphView.xaml + /// + public partial class NamespaceCycleGraphView : UserControl + { + public NamespaceCycleGraphView() + { + InitializeComponent(); + } + } +} diff --git a/Sources2012/Usus.net.View/Dialogs/NamespaceCycleListView.xaml b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleListView.xaml similarity index 97% rename from Sources2012/Usus.net.View/Dialogs/NamespaceCycleListView.xaml rename to Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleListView.xaml index 976b9f6..aa6b417 100644 --- a/Sources2012/Usus.net.View/Dialogs/NamespaceCycleListView.xaml +++ b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleListView.xaml @@ -1,42 +1,42 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sources2012/Usus.net.View/Dialogs/NamespaceCycleListView.xaml.cs b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleListView.xaml.cs similarity index 85% rename from Sources2012/Usus.net.View/Dialogs/NamespaceCycleListView.xaml.cs rename to Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleListView.xaml.cs index 2afec4a..641b091 100644 --- a/Sources2012/Usus.net.View/Dialogs/NamespaceCycleListView.xaml.cs +++ b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/NamespaceCycleListView.xaml.cs @@ -1,38 +1,37 @@ -using andrena.Usus.net.View.Dialogs.ViewModels; -using System; -using System.Windows.Controls; -using System.Windows.Input; - -namespace andrena.Usus.net.View.Dialogs -{ - /// - /// Interaction logic for NamespaceCycleList.xaml - /// - public partial class NamespaceCycleListView : UserControl - { - public NamespaceCycleListView() - { - InitializeComponent(); - } - - private void SelectNamespace(object sender, MouseButtonEventArgs e) - { - SelectionOf(sender, (vm, selected) => vm.SelectNamespace(selected)); - } - - private void SelectType(object sender, MouseButtonEventArgs e) - { - SelectionOf(sender, (vm, selected) => vm.SelectType(selected)); - } - - private void SelectionOf(object sender, Action select) - { - var selectedItem = (sender as ListBox).SelectedItem; - if (selectedItem != null) - { - var vm = DataContext as NamespaceCycleDisplayVM; - select(vm, selectedItem as string); - } - } - } -} +using System; +using System.Windows.Controls; +using System.Windows.Input; + +namespace andrena.Usus.net.View.Dialogs.NamespaceCycles +{ + /// + /// Interaction logic for NamespaceCycleList.xaml + /// + public partial class NamespaceCycleListView : UserControl + { + public NamespaceCycleListView() + { + InitializeComponent(); + } + + private void SelectNamespace(object sender, MouseButtonEventArgs e) + { + SelectionOf(sender, (vm, selected) => vm.SelectNamespace(selected)); + } + + private void SelectType(object sender, MouseButtonEventArgs e) + { + SelectionOf(sender, (vm, selected) => vm.SelectType(selected)); + } + + private void SelectionOf(object sender, Action select) + { + var selectedItem = (sender as ListBox).SelectedItem; + if (selectedItem != null) + { + var vm = DataContext as NamespaceCycleDisplayVM; + select(vm, selectedItem as string); + } + } + } +} diff --git a/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/OutgoingTypeReferences.cs b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/OutgoingTypeReferences.cs new file mode 100644 index 0000000..caf37a2 --- /dev/null +++ b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/OutgoingTypeReferences.cs @@ -0,0 +1,36 @@ +using andrena.Usus.net.Core.Reports; +using System.Collections.Generic; +using System.Linq; + +namespace andrena.Usus.net.View.Dialogs.NamespaceCycles +{ + public class OutgoingTypeReferences + { + private readonly TypeMetricsReport source; + private readonly MetricsReport metrics; + + public OutgoingTypeReferences(MetricsReport metrics, TypeMetricsReport source) + { + this.metrics = metrics; + this.source = source; + } + + public IEnumerable Referencing(IEnumerable namespaces) + { + return from type in DependenciesOf(source) + where namespaces.Contains(NamespaceOf(type)) + select new TypeReference(metrics, source, type); + } + + private IEnumerable DependenciesOf(TypeMetricsReport type) + { + return from reference in type.InterestingDirectDependencies + select metrics.ForType(reference); + } + + private NamespaceMetricsReport NamespaceOf(TypeMetricsReport type) + { + return metrics.ForNamespace(type.Namespaces.First()); + } + } +} \ No newline at end of file diff --git a/Sources2012/Usus.net.View/Dialogs/ViewModels/OutOfNamespaceReferenceVM.cs b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/TypeReferenceVM.cs similarity index 69% rename from Sources2012/Usus.net.View/Dialogs/ViewModels/OutOfNamespaceReferenceVM.cs rename to Sources2012/Usus.net.View/Dialogs/NamespaceCycles/TypeReferenceVM.cs index ec66799..a985507 100644 --- a/Sources2012/Usus.net.View/Dialogs/ViewModels/OutOfNamespaceReferenceVM.cs +++ b/Sources2012/Usus.net.View/Dialogs/NamespaceCycles/TypeReferenceVM.cs @@ -1,19 +1,20 @@ -using andrena.Usus.net.Core.Helper; -using System.Collections.Generic; - -namespace andrena.Usus.net.View.Dialogs.ViewModels -{ - public class OutOfNamespaceReferenceVM - { - public string Source { get; private set; } - public string Target { get; private set; } - public IEnumerable ResponsibleMethods { get; private set; } - - public OutOfNamespaceReferenceVM(OutOfNamespaceReference reference) - { - Source = reference.Source.FullName; - Target = reference.Target.FullName; - ResponsibleMethods = reference.ReferencingMethods().ToList(m => m.Name); - } - } -} +using andrena.Usus.net.Core.Helper; +using andrena.Usus.net.Core.Reports; +using System.Collections.Generic; + +namespace andrena.Usus.net.View.Dialogs.NamespaceCycles +{ + public class TypeReferenceVM + { + public string Source { get; private set; } + public string Target { get; private set; } + public IEnumerable ResponsibleMethods { get; private set; } + + public TypeReferenceVM(TypeReference reference) + { + Source = reference.Source.FullName; + Target = reference.Target.FullName; + ResponsibleMethods = reference.ReferencingMethods().ToList(m => m.Name); + } + } +} diff --git a/Sources2012/Usus.net.View/Dialogs/ViewModels/ListDisplay.cs b/Sources2012/Usus.net.View/Dialogs/ViewModels/ListDisplay.cs deleted file mode 100644 index 1e90784..0000000 --- a/Sources2012/Usus.net.View/Dialogs/ViewModels/ListDisplay.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections.Generic; -using System.Collections.ObjectModel; - -namespace andrena.Usus.net.View.Dialogs.ViewModels -{ - public class ListDisplay - { - public string Header { get; private set; } - public ObservableCollection Entries { get; private set; } - - public ListDisplay(string header) - { - Header = header; - Entries = new ObservableCollection(); - } - - public void AddAll(IEnumerable entries) - { - if (entries != null) - foreach (var entry in entries) Entries.Add(entry); - } - } -} diff --git a/Sources2012/Usus.net.View/Dialogs/ViewModels/NamespaceCycle.cs b/Sources2012/Usus.net.View/Dialogs/ViewModels/NamespaceCycle.cs deleted file mode 100644 index 2f469ba..0000000 --- a/Sources2012/Usus.net.View/Dialogs/ViewModels/NamespaceCycle.cs +++ /dev/null @@ -1,54 +0,0 @@ -using andrena.Usus.net.Core.Helper; -using andrena.Usus.net.Core.Reports; -using System; -using System.Collections.Generic; -using System.Linq; - -namespace andrena.Usus.net.View.Dialogs.ViewModels -{ - public class NamespaceCycle - { - private readonly IEnumerable namespaces; - private readonly MetricsReport metrics; - - public NamespaceCycle(MetricsReport metrics, IEnumerable namespaces) - { - this.metrics = metrics; - this.namespaces = namespaces; - Jump += type => { }; - } - - public event Action Jump; - - public IEnumerable Namespaces - { - get { return namespaces.Select(n => n.Name); } - } - - public IEnumerable TypesReferencingOutOf(string namespaceName) - { - var currentNamespace = metrics.ForNamespace(namespaceName); - var otherNamespaceInCycle = namespaces.ExceptThis(currentNamespace).ToList(); - return from reference in ReferencesOutOf(currentNamespace, to: otherNamespaceInCycle) - select reference; - } - - private IEnumerable ReferencesOutOf(NamespaceMetricsReport currentNamespace, IEnumerable to) - { - return from typeReferences in AllTypesWithReferencesIn(currentNamespace) - from crossReference in typeReferences.Referencing(to) - select crossReference; - } - - private IEnumerable AllTypesWithReferencesIn(NamespaceMetricsReport currentNamespace) - { - return from type in metrics.TypesOfNamespace(currentNamespace) - select new OutgoingTypeReferences(metrics, type); - } - - public void JumpTo(string type) - { - Jump(metrics.ForType(type.Substring(0, type.IndexOf("\n")))); - } - } -} diff --git a/Sources2012/Usus.net.View/Dialogs/ViewModels/OutgoingTypeReferences.cs b/Sources2012/Usus.net.View/Dialogs/ViewModels/OutgoingTypeReferences.cs deleted file mode 100644 index 939a85b..0000000 --- a/Sources2012/Usus.net.View/Dialogs/ViewModels/OutgoingTypeReferences.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using andrena.Usus.net.Core.Reports; - -namespace andrena.Usus.net.View.Dialogs.ViewModels -{ - public class OutgoingTypeReferences - { - private readonly TypeMetricsReport source; - private readonly MetricsReport metrics; - - public OutgoingTypeReferences(MetricsReport metrics, TypeMetricsReport source) - { - this.metrics = metrics; - this.source = source; - } - - public IEnumerable Referencing(IEnumerable namespaces) - { - return from type in DependenciesOf(source) - where namespaces.Contains(NamespaceOf(type)) - select new OutOfNamespaceReference(metrics, source, type); - } - - private IEnumerable DependenciesOf(TypeMetricsReport type) - { - return from reference in type.InterestingDirectDependencies - select metrics.ForType(reference); - } - - private NamespaceMetricsReport NamespaceOf(TypeMetricsReport type) - { - return metrics.ForNamespace(type.Namespaces.First()); - } - } -} \ No newline at end of file diff --git a/Sources2012/Usus.net.View/TypeCycles.xaml b/Sources2012/Usus.net.View/TypeCycles.xaml index 6354341..82b8e7d 100644 --- a/Sources2012/Usus.net.View/TypeCycles.xaml +++ b/Sources2012/Usus.net.View/TypeCycles.xaml @@ -24,11 +24,12 @@ - - + + - + diff --git a/Sources2012/Usus.net.View/Usus.net.View.csproj b/Sources2012/Usus.net.View/Usus.net.View.csproj index 3f82e00..72fde25 100644 --- a/Sources2012/Usus.net.View/Usus.net.View.csproj +++ b/Sources2012/Usus.net.View/Usus.net.View.csproj @@ -87,7 +87,7 @@ TypeCycleListView.xaml - + @@ -96,24 +96,23 @@ Current.xaml - + NamespaceCycleGraphView.xaml - + NamespaceCycleListView.xaml - - - - + + + NamespaceCycleDisplay.xaml - + Distributions.xaml - + ListDisplay.xaml @@ -154,7 +153,7 @@ - + @@ -163,6 +162,9 @@ + + + @@ -198,15 +200,15 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile @@ -218,7 +220,7 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile diff --git a/Sources2012/Usus.net.View/ViewModels/GraphViewModel.cs b/Sources2012/Usus.net.View/ViewModels/GraphViewModel.cs index 859d233..5a2e80f 100644 --- a/Sources2012/Usus.net.View/ViewModels/GraphViewModel.cs +++ b/Sources2012/Usus.net.View/ViewModels/GraphViewModel.cs @@ -1,8 +1,7 @@ -using andrena.Usus.net.View.ViewModels; using System.Collections.Generic; using System.Collections.ObjectModel; -namespace andrena.Usus.net.View.Dialogs.ViewModels +namespace andrena.Usus.net.View.ViewModels { public abstract class GraphViewModel : AnalysisAwareViewModel { diff --git a/Sources2012/Usus.net.View/ViewModels/Graphs/Graphs.cs b/Sources2012/Usus.net.View/ViewModels/Graphs/Graphs.cs index fb4fc48..9712472 100644 --- a/Sources2012/Usus.net.View/ViewModels/Graphs/Graphs.cs +++ b/Sources2012/Usus.net.View/ViewModels/Graphs/Graphs.cs @@ -1,5 +1,4 @@ using andrena.Usus.net.Core.Prepared; -using andrena.Usus.net.View.Dialogs.ViewModels; using QuickGraph; using System.Linq; diff --git a/Sources2012/Usus.net.View/ViewModels/Hotspots/NamespaceHotspot.cs b/Sources2012/Usus.net.View/ViewModels/Hotspots/NamespaceHotspot.cs index 92b5017..b56a1d1 100644 --- a/Sources2012/Usus.net.View/ViewModels/Hotspots/NamespaceHotspot.cs +++ b/Sources2012/Usus.net.View/ViewModels/Hotspots/NamespaceHotspot.cs @@ -1,47 +1,46 @@ using System.Collections.Generic; using System.Linq; using andrena.Usus.net.Core.Reports; -using andrena.Usus.net.View.Dialogs; -using andrena.Usus.net.View.Dialogs.ViewModels; using andrena.Usus.net.View.ExtensionPoints; +using andrena.Usus.net.View.Dialogs.NamespaceCycles; namespace andrena.Usus.net.View.ViewModels.Hotspots { - public class NamespaceHotspot : Hotspot - { - MetricsReport metrics; + public class NamespaceHotspot : Hotspot + { + MetricsReport metrics; - public NamespaceHotspot(NamespaceMetricsReport namespaceReport, MetricsReport metrics) - : base(namespaceReport) - { - this.metrics = metrics; - } + public NamespaceHotspot(NamespaceMetricsReport namespaceReport, MetricsReport metrics) + : base(namespaceReport) + { + this.metrics = metrics; + } - public override void OnDoubleClick(IJumpToSource jumper) - { - var cycleDisplay = new NamespaceCycleDisplay(); - cycleDisplay.DataContext = CreateViewModel(jumper); - cycleDisplay.Show(); - } + public override void OnDoubleClick(IJumpToSource jumper) + { + var cycleDisplay = new NamespaceCycleDisplay(); + cycleDisplay.DataContext = CreateViewModel(jumper); + cycleDisplay.Show(); + } - private NamespaceCycleDisplayVM CreateViewModel(IJumpToSource jumper) - { - var viewModel = new NamespaceCycleDisplayVM("Namespace cycle"); - viewModel.Display(NamespaceCycle(jumper)); - return viewModel; - } - - private NamespaceCycle NamespaceCycle(IJumpToSource jumper) - { - var namespaceCycle = new NamespaceCycle(metrics, NamespacesInCycle()); - namespaceCycle.Jump += type => TypeJump.To(metrics, type, jumper); - return namespaceCycle; - } + private NamespaceCycleDisplayVM CreateViewModel(IJumpToSource jumper) + { + var viewModel = new NamespaceCycleDisplayVM("Namespace cycle"); + viewModel.Display(NamespaceCycle(jumper)); + return viewModel; + } - private IEnumerable NamespacesInCycle() - { - return from ns in Report.CyclicDependencies - select metrics.ForNamespace(ns); - } - } + private NamespaceCycle NamespaceCycle(IJumpToSource jumper) + { + var namespaceCycle = new NamespaceCycle(metrics, NamespacesInCycle()); + namespaceCycle.Jump += type => TypeJump.To(metrics, type, jumper); + return namespaceCycle; + } + + private IEnumerable NamespacesInCycle() + { + return from ns in Report.CyclicDependencies + select metrics.ForNamespace(ns); + } + } } \ No newline at end of file diff --git a/Sources2012/Usus.net.View/ViewModels/TypeCycles/Type.cs b/Sources2012/Usus.net.View/ViewModels/TypeCycles/Type.cs new file mode 100644 index 0000000..f9af94f --- /dev/null +++ b/Sources2012/Usus.net.View/ViewModels/TypeCycles/Type.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace andrena.Usus.net.View.ViewModels.TypeCycles +{ + public class Type + { + public string DisplayName { get; set; } + public IEnumerable ReferencedTypes { get; set; } + + public Type() + { } + } +} diff --git a/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycle.cs b/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycle.cs new file mode 100644 index 0000000..a6e4362 --- /dev/null +++ b/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycle.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; + +namespace andrena.Usus.net.View.ViewModels.TypeCycles +{ + public class TypeCycle + { + public string DisplayName { get; set; } + public IEnumerable TypesInCycle { get; set; } + + public TypeCycle() + { } + } +} diff --git a/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycleListView.xaml b/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycleListView.xaml index 4801faa..05708f3 100644 --- a/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycleListView.xaml +++ b/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycleListView.xaml @@ -15,17 +15,18 @@ - - - + + + - + - + diff --git a/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycleListView.xaml.cs b/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycleListView.xaml.cs index 19c1add..388ffe3 100644 --- a/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycleListView.xaml.cs +++ b/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycleListView.xaml.cs @@ -1,7 +1,4 @@ -using andrena.Usus.net.View.Dialogs.ViewModels; -using System; -using System.Windows.Controls; -using System.Windows.Input; +using System.Windows.Controls; namespace andrena.Usus.net.View.ViewModels.TypeCycles { @@ -15,24 +12,11 @@ public TypeCycleListView() InitializeComponent(); } - private void SelectNamespace(object sender, MouseButtonEventArgs e) + private void SelectType(object sender, System.Windows.Input.MouseButtonEventArgs e) { - SelectionOf(sender, (vm, selected) => vm.SelectNamespace(selected)); - } + var vm = DataContext as TypeCycles; + vm.Jump(); - private void SelectType(object sender, MouseButtonEventArgs e) - { - SelectionOf(sender, (vm, selected) => vm.SelectType(selected)); - } - - private void SelectionOf(object sender, Action select) - { - var selectedItem = (sender as ListBox).SelectedItem; - if (selectedItem != null) - { - var vm = DataContext as NamespaceCycleDisplayVM; - select(vm, selectedItem as string); - } } } } diff --git a/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycles.cs b/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycles.cs index d977f13..7ce4ef4 100644 --- a/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycles.cs +++ b/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeCycles.cs @@ -1,5 +1,11 @@ -using andrena.Usus.net.Core.Prepared; -using andrena.Usus.net.View.Dialogs.ViewModels; +using andrena.Usus.net.Core.Graphs; +using andrena.Usus.net.Core.Prepared; +using andrena.Usus.net.Core.Reports; +using QuickGraph; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows; namespace andrena.Usus.net.View.ViewModels.TypeCycles { @@ -7,13 +13,102 @@ public class TypeCycles : GraphViewModel { public TypeCycles() { + AllCycles = new ObservableCollection(); + } + + public IBidirectionalGraph> Graph { get; private set; } + + public ObservableCollection AllCycles { get; private set; } + + private TypeCycle _SelectedCycle; + public TypeCycle SelectedCycle + { + get + { + return _SelectedCycle; + } + set + { + if (_SelectedCycle != value) + { + _SelectedCycle = value; + Changed(() => SelectedCycle); + if (_SelectedCycle != null) + UpdateGraph(_SelectedCycle); + } + } + } + + private Type _SelectedType; + public Type SelectedType + { + get + { + return _SelectedType; + } + set + { + if (_SelectedType != value) + { + _SelectedType = value; + Changed(() => SelectedType); + } + } } protected override void AnalysisFinished(PreparedMetricsReport metrics) { - System.Windows.MessageBox.Show( - string.Format("COMING SOON: cycles of {0} types...", metrics.CommonKnowledge.NumberOfTypes)); + var cycles = metrics.Report.TypeGraph.Cycles(); + var cycleVMs = GetViewModels(metrics, cycles); + Display(cycleVMs); + } + + private static IEnumerable GetViewModels(PreparedMetricsReport metrics, StronglyConntectedComponents cycles) + { + return from cycle in cycles.All + where cycle.VertexCount > 1 + select new TypeCycle + { + DisplayName = string.Format("{0} classes", cycle.VertexCount), + TypesInCycle = from type in cycle.Vertices + select new Type + { + DisplayName = type.FullName, + ReferencedTypes = from referencedType in type.InterestingDirectDependencies.Intersect(cycles.OfVertex(type).Vertices.Select(t => t.FullName)) + where type.FullName != referencedType + select new TypeReferenceVM(metrics, type, referencedType) + } + }; + } + + private void Display(IEnumerable cycleVMs) + { + Dispatch(() => + { + AllCycles.Clear(); + foreach (var cycleVM in cycleVMs) + { + AllCycles.Add(cycleVM); + } + }); + } + + private void UpdateGraph(TypeCycle cycle) + { + var graph = new BidirectionalGraph>(false); + graph.AddVertexRange(cycle.TypesInCycle.Select(t => t.DisplayName)); + graph.AddEdgeRange( + from type in cycle.TypesInCycle + from referencedType in type.ReferencedTypes + select new Edge(referencedType.Source, referencedType.Target)); + Graph = graph; + Changed(() => Graph); + } + + public void Jump() + { + MessageBox.Show("coming soon"); } } -} +} \ No newline at end of file diff --git a/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeReferenceVM.cs b/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeReferenceVM.cs new file mode 100644 index 0000000..2f9c538 --- /dev/null +++ b/Sources2012/Usus.net.View/ViewModels/TypeCycles/TypeReferenceVM.cs @@ -0,0 +1,25 @@ +using andrena.Usus.net.Core.Helper; +using andrena.Usus.net.Core.Prepared; +using andrena.Usus.net.Core.Reports; +using System.Collections.Generic; + +namespace andrena.Usus.net.View.ViewModels.TypeCycles +{ + public class TypeReferenceVM + { + public string Source { get; private set; } + public string Target { get; private set; } + public IEnumerable ResponsibleMethods { get; private set; } + + public TypeReferenceVM(PreparedMetricsReport metrics, TypeMetricsReport source, string target) + : this(new TypeReference(metrics.Report, source, metrics.Report.ForType(target))) + { } + + public TypeReferenceVM(TypeReference reference) + { + Source = reference.Source.FullName; + Target = reference.Target.FullName; + ResponsibleMethods = reference.ReferencingMethods().ToList(m => m.Name); + } + } +}