private static async Task Crawl(ConcurrentBag <CrawlingTask> bag, string crawlerName) { CrawlingTask task; while (bag.TryTake(out task)) { IEnumerable <string> urls = await GetLinksFromContent(task); if (urls != null) { foreach (var url in urls) { var t = new CrawlingTask { UrlToCraw = url, ProducerName = crawlerName }; bag.Add(t); } } Console.WriteLine($"Indexing url {task.UrlToCraw} posted by {task.ProducerName} is completed by {crawlerName}"); } }
private static async Task <IEnumerable <string> > GetLinksFromContent(CrawlingTask task) { await GetRandomDelay(); if (_contentEmulation.ContainsKey(task.UrlToCraw)) { return(_contentEmulation[task.UrlToCraw]); } return(null); }