/// <summary> /// Initializes a new instance of <see cref="DownloadProgressEventArgs"/>. /// </summary> /// <param name="task">The affected download task.</param> /// <param name="loadedBytes">The number of already downloaded bytes.</param> /// <param name="totalBytes">The total number of bytes, this HTTP(S) resource encompasses.</param> /// <param name="percentage">The percentage of the progress.</param> public DownloadProgressEventArgs(DownloadTask task, long loadedBytes, long totalBytes, int percentage) : base(task) { LoadedBytes = loadedBytes; TotalBytes = totalBytes; Percentage = percentage; }
private void ResolveUrl(DownloadTask task, WebClient wc) { bool foundResolver; var resolvedUrl = ResolveUrl(task.Url, out foundResolver, wc); if (foundResolver) { if (resolvedUrl != null) { task.ResolvedUrl = resolvedUrl; } else { task.UrlResolutionFailed = true; } } }
private void OnDownloadStarted(DownloadTask task) { Debug.WriteLine("Raising event DownloadStarted for " + task.Id + ", Url=" + task.Url); var handler = DownloadStarted; if (handler != null) { handler(this, new DownloadEventArgs(task)); } }
private void OnDownloadProgress(DownloadTask task, long bytesDownloaded, long totalBytes, int percentage) { var handler = DownloadProgress; if (handler != null) { handler(this, new DownloadProgressEventArgs(task, bytesDownloaded, totalBytes, percentage)); } }
private void OnDownloadEnded(DownloadTask task) { Debug.WriteLine("Raising event DownloadEnded for " + task.Id + ", Error=" + task.ErrorMessage ?? "None"); var handler = DownloadEnded; if (handler != null) { handler(this, new DownloadEventArgs(task)); } }
/// <summary> /// Enqueues a new download task. /// </summary> /// <param name="task">The download task.</param> public void Enqueue(DownloadTask task) { Debug.WriteLine("Queuing " + task.Id + ", TargetFile=" + task.TargetFile + ", URL=" + task.Url); var notify = false; lock (queueLock) { if (IsDisposed) { throw new ObjectDisposedException(GetType().Name); } queue.Enqueue(task); if (!working) { working = true; notify = true; } } availableTasks.Release(); if (notify) { OnIsWorkingChanged(); } }
/// <summary> /// Initializes a new instance of <see cref="DownloadEventArgs"/>. /// </summary> /// <param name="task">The download task, affected by this event.</param> public DownloadEventArgs(DownloadTask task) { Task = task; }