public static async Task Main(string[] args) { var commandLine = new CommandLine(args); contextFilePath = commandLine.ContextPath; if (commandLine.QuantifierInputFile != null) { // quantifier input is specified as a file // run once and exit var quantifierInput = new QuantifierInput(); var changes = JsonSerializer.Deserialize <List <GitFilePatch> >( await File.ReadAllTextAsync(commandLine.QuantifierInputFile)); changes?.ForEach(c => quantifierInput.Changes.Add(c)); quantifyClient = new QuantifyClient(contextFilePath); PrintResult( await quantifyClient.Compute(quantifierInput), commandLine.Output); } else { var gitRepoPath = commandLine.GitRepoPath ?? Environment.CurrentDirectory; var repoRootPath = Repository.Discover(gitRepoPath); // if no repo was found to this path then exit, don't crash if (string.IsNullOrWhiteSpace(repoRootPath)) { Console.WriteLine("GitRepoPath couldn't be found!"); return; } contextFilePath ??= Path.Combine( new DirectoryInfo(repoRootPath).Parent?.FullName, "prquantifier.yaml"); // run this as a service in case is configured otherwise only run once if (commandLine.Service) { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Factory.StartNew(() => QuantifyLoop(repoRootPath, commandLine.Output)); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed await Run(repoRootPath); } // in case service is not set or false then run once and exit quantifyClient = new QuantifyClient(contextFilePath); PrintResult( await quantifyClient.Compute(repoRootPath), commandLine.Output); } }
private static void QuantifyLoop( string gitRepoPath, ClientOutputType clientOutputType) { while (true) { if ((DateTimeOffset.Now - changedEventDateTime).TotalSeconds < 1) { Thread.Sleep(TimeSpan.FromMilliseconds(100)); continue; } quantifyClient = new QuantifyClient(contextFilePath); PrintResult( quantifyClient.Compute(gitRepoPath).Result, clientOutputType); changedEventDateTime = DateTimeOffset.MaxValue; } }