예제 #1
0
        private void SingleIteration(string url, LinkService linkService)
        {
            string filename = url.GetHashCode() + ".html";

            this.downloadService.DownloadHtml(url, filename);
            var linksToAdd = this.parserService.GetLinksFromHtml(filename, url).ToList();
            int iteration  = linkService.GetCurrentIteration();

            if (linksToAdd != null)
            {
                linkService.AddParsedLinksToDB(linksToAdd, iteration);
            }
        }
예제 #2
0
        public async Task RunRecursively(int deep, string url)
        {
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                LinkService linkService = new LinkService(unitOfWork);
                await Task.Run(() =>
                {
                    Thread.Sleep(500);

                    if (deep <= 0)
                    {
                        return;
                    }
                    if (deep == 1)
                    {
                        this.SingleIteration(url, linkService);
                    }
                    else
                    {
                        this.SingleIteration(url, linkService);
                        var linksFromPreviousIteration = linkService.GetAllLinksByIteration(linkService.GetCurrentIteration() - 1).ToList();
                        if (linksFromPreviousIteration.Count() != 0)
                        {
                            Parallel.ForEach <string>(linksFromPreviousIteration, (link) =>
                            {
                                Task t = RunRecursively(deep - 1, link);
                                t.Wait();
                            });
                        }
                    }
                });
            }
        }