public void ProcessUrls([ArgDescription("List of urls")] string urls) { Guard.ArgumentNotEmpty(urls, nameof(urls)); var source = urls.Split(ParserConfiguration.ListDelimiter, StringSplitOptions.RemoveEmptyEntries); if (source.Length == 0) { Console.WriteLine("List of urls is empty"); return; } var filePath = ParserConfiguration.ResultFilePath; if (string.IsNullOrWhiteSpace(Path.GetDirectoryName(filePath))) { filePath = Path.Combine(Environment.CurrentDirectory, filePath); } var streamWriter = File.AppendText(filePath); _client = new HttpClientCaller(new HttpClientPool(source.Length)); var tokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(ParserConfiguration.MaxExecutionTime)); Task.WhenAny( RunAsync( source, streamWriter, (index, url) => { return(UrlProcessorAsync(url, index)); }, tokenSource.Token), Task.Run( () => { Console.WriteLine("Please press any key to terminate..."); Console.ReadKey(true); tokenSource.Cancel(); }, tokenSource.Token)) .GetAwaiter() .GetResult(); streamWriter.Dispose(); }
public void Init() { hcc = new HttpClientCaller(); hns = new HackerNewsService(hcc); }