private void StartDownload() { CrawlerQueueEntry crawlerQueueEntry = m_CrawlerQueue.Pop(); if (crawlerQueueEntry.IsNull() || !OnBeforeDownload(crawlerQueueEntry.CrawlStep)) { return; } IWebDownloader webDownloader = m_WebDownloaderFactory(); webDownloader.MaximumDownloadSizeInRam = MaximumDownloadSizeInRam; webDownloader.ConnectionTimeout = ConnectionTimeout; webDownloader.MaximumContentSize = MaximumContentSize; webDownloader.DownloadBufferSize = DownloadBufferSize; webDownloader.UserAgent = UserAgent; webDownloader.UseCookies = UseCookies; webDownloader.ReadTimeout = ConnectionReadTimeout; webDownloader.RetryCount = DownloadRetryCount; webDownloader.RetryWaitDuration = DownloadRetryWaitDuration; m_Logger.Verbose("Downloading {0}", crawlerQueueEntry.CrawlStep.Uri); ThreadSafeCounter.ThreadSafeCounterCookie threadSafeCounterCookie = m_ThreadInUse.EnterCounterScope(crawlerQueueEntry); Interlocked.Increment(ref m_VisitedCount); webDownloader.DownloadAsync(crawlerQueueEntry.CrawlStep, crawlerQueueEntry.Referrer, DownloadMethod.GET, EndDownload, OnDownloadProgress, threadSafeCounterCookie); }
public async Task RunAsync(string suggestedName, long totalSize, IWebDownloader downloader) { try { FlexibleLoader.RegisterPriority(this); ContentInstallationManager.Instance.InstallAsync(_url, AddInstallMode.ForceNewTask, ContentInstallationParams.DefaultWithExecutables).Forget(); FlexibleLoader.Unregister(this); var destinationCallback = _destinationCallback; var reportDestinationCallback = _reportDestinationCallback; var progress = _progress; var resultTask = _resultTask; if (destinationCallback == null) { return; } TotalSize = totalSize; FileName = suggestedName; _destinationCallback = null; _reportDestinationCallback = null; _progress = null; var destination = destinationCallback(_url, new FlexibleLoaderMetaInformation { CanPause = false, FileName = suggestedName, TotalSize = totalSize }); reportDestinationCallback?.Invoke(destination.Filename); try { if (SettingsHolder.WebBlocks.NotifyOnWebDownloads) { Toast.Show("New download started", suggestedName ?? _url); } resultTask.TrySetResult(await downloader.DownloadAsync(destination.Filename, progress, _cancellation)); } catch (Exception e) { Logging.Warning(e); resultTask.TrySetException(e); } } catch (Exception e) { Logging.Error(e); } }