コード例 #1
0
        static async Task <int> ExecuteAsync(string path, int iterations, int maxConcurrency, bool noDependencies)
        {
            if (!Helper.TryFindRoot(out var rootDir))
            {
                return(1);
            }

            if (!path.EndsWith(GraphSerializer.FileExtension, StringComparison.OrdinalIgnoreCase))
            {
                Console.WriteLine($"The serialized graph must have the extension {GraphSerializer.FileExtension}");
                return(1);
            }

            Console.WriteLine("Parsing the file name...");
            if (!Helper.TryParseFileName(path, out var graphType, out var variantName, out var solutionName))
            {
                graphType    = null;
                variantName  = null;
                solutionName = null;
            }

            Console.WriteLine($"  Graph type:    {graphType ?? "(none)"}");
            Console.WriteLine($"  Variant name:  {variantName ?? "(none)"}");
            Console.WriteLine($"  Solution name: {solutionName ?? "(none)"}");

            if (graphType != RequestGraph.Type)
            {
                Console.WriteLine($"The input graph type must be {RequestGraph.Type}.");
                return(1);
            }

            Console.WriteLine($"Reading {path}...");
            var graph = RequestGraphSerializer.ReadFromFile(path);

            Console.WriteLine($"There are {graph.Nodes.Count} nodes in the graph.");
            Console.WriteLine($"There are {graph.Nodes.Sum(x => x.Dependencies.Count)} edges in the graph.");

            if (noDependencies)
            {
                Console.WriteLine("Clearing dependencies...");
                foreach (var node in graph.Nodes)
                {
                    node.Dependencies.Clear();
                }
            }

            var resultsPath = Path.Combine(rootDir, "out", ResultFileName);

            Console.WriteLine($"Results will be writen to {resultsPath}.");

            using (var handler = new HttpClientHandler {
                AutomaticDecompression = DecompressionMethods.GZip
            })
                using (var httpClient = new HttpClient(handler))
                {
                    Console.WriteLine("Sorting the requests in topological order...");
                    var topologicalOrder = GraphOperations.TopologicalSort(graph);
                    topologicalOrder.Reverse();

                    for (var iteration = 0; iteration <= iterations; iteration++)
                    {
                        await ExecuteIterationAsync(
                            rootDir,
                            resultsPath,
                            variantName,
                            solutionName,
                            httpClient,
                            iterations,
                            maxConcurrency,
                            topologicalOrder,
                            iteration,
                            noDependencies);
                    }
                }

            return(0);
        }