Esempio n. 1
0
        private async Task DownloadPageAsync(Uri uri, Uri baseAddress, CancellationToken ct = default)
        {
            var content = await downloaderService.DownloadWebPageAsync(uri, ct);

            if (string.IsNullOrEmpty(content))
            {
                return;
            }

            var uris = UriHelper.GetAllUrisFromString(content, baseAddress);

            await readLock.WaitAsync(ct);

            try
            {
                downloadStatuses[uri] = DownloadStatus.Done;

                CheckIfAllUrisAreDone();

                foreach (var filteredUri in uris)
                {
                    SetStatusIfNotSet(filteredUri, DownloadStatus.NotStarted);
                }
            }
            finally
            {
                readLock.Release();
            }

            var args = new DownloadedWebPageEventArgs
            {
                Content = content,
                Uri     = uri,
            };

            OnDownloadedPage(args);
        }