Ejemplo n.º 1
0
        private IEnumerable <(string pathPostfix, string contents)> GetDotNotations(
            FileInfo projectFile,
            ImmutableDictionary <string, string> globalProperties,
            string[] targets,
            string[] endNodes)
        {
            Console.WriteLine("Loading graph...");

            var sw    = Stopwatch.StartNew();
            var graph = new ProjectGraph(new ProjectGraphEntryPoint(projectFile.FullName, globalProperties), ProjectCollection.GlobalProjectCollection);

            sw.Stop();

            Console.WriteLine($@"{projectFile} loaded {graph.ProjectNodes.Count} node(s) in {sw.ElapsedMilliseconds}ms.");

            var entryTargetsPerNode = graph.GetTargetLists(targets);

            if (endNodes != null)
            {
                var endGraphNodes = graph.ProjectNodes.Where(n => endNodes.Any(en => n.ProjectInstance.FullPath.Contains(en)));
                var paths         = GraphPaths.FindAllPathsBetween(graph.GraphRoots, endGraphNodes);

                var deduplicatedNodes = paths.SelectMany(p => p).ToHashSet();
                yield return($"_PathsEndingIn_{string.Join(",", endNodes)}", GraphVis.Create(deduplicatedNodes, entryTargetsPerNode));
            }

            yield return("", GraphVis.Create(graph, entryTargetsPerNode));
        }
Ejemplo n.º 2
0
        public void FindAllPathsBetween(Dictionary <int, int[]> graphEdges, int[] startNodeIds, int[] endNodeIds, List <int[]> expectedPaths)
        {
            var graph      = Graph.FromEdgeDictionary(graphEdges);
            var startNodes = IdsToNodes(startNodeIds, graph);
            var endNodes   = IdsToNodes(endNodeIds, graph);

            var paths = GraphPaths.FindAllPathsBetween(startNodes, endNodes).ToArray();

            var pathLists =
                paths.Select(p => p.NodeList)
                .Select(p => p.Select(n => ((Node)n).Value).ToArray())
                .ToList();

            pathLists.ShouldBe(expectedPaths, true);
        }