public DownloadFilePathChangedEventArgs(DownloadInfo downloadInfo, string previousFilePath, string newFilePath) : base(downloadInfo) { new_file_path = newFilePath; previous_file_path = previousFilePath; }
protected virtual void OnDownloadTaskFinishedHandler(object sender, DownloadEventArgs args) { DownloadInfo dif = args.DownloadInfo; DownloadTask dt = sender as DownloadTask; Finished(dif, dt); OnStatusUpdated(); }
protected internal DownloadTask(DownloadInfo dif) { if (dif == null) { throw new ArgumentNullException("dif"); } this.dif = dif; totalLength = dif.Length; }
protected virtual void OnLengthChanged(DownloadInfo dif, long previousLength, long currentLength) { DownloadLengthChangedEventHandler handler = LengthChanged; if (handler != null) { handler(this, new DownloadLengthChangedEventArgs(dif, previousLength, currentLength)); } }
protected virtual void OnMimeTypeChanged(DownloadInfo downloadInfo, string previousMimeType, string newMimeType) { DownloadMimeTypeChangedEventHandler handler = MimeTypeChanged; if (handler != null) { handler(this, new DownloadMimeTypeChangedEventArgs(downloadInfo, previousMimeType, newMimeType)); } }
protected virtual void OnFilePathChanged(DownloadInfo downloadInfo, string previousFilePath, string newFilePath) { DownloadFilePathChangedEventHandler handler = FilePathChanged; if (handler != null) { handler(this, new DownloadFilePathChangedEventArgs(downloadInfo, previousFilePath, previousFilePath)); } }
public static DownloadInfo CreateDownloadInfo(string uri, string path, long length) { if (uri == null || uri == String.Empty) { throw new ArgumentException(Catalog.GetString("uri is empty")); } else if (path == null || path == String.Empty) { throw new ArgumentException(Catalog.GetString("path is empty")); } DownloadInfo dif = new DownloadInfo(uri, path, length); return(dif); }
public static void Pause(DownloadInfo dif) { if (dif == null) { throw new ArgumentNullException("dif"); } lock (download_queue.SyncRoot) { if (download_queue.Contains(dif)) { dif.State = DownloadState.Paused; } } }
protected virtual void OnDownloadCompleted(DownloadInfo dif) { DownloadCompletedEventHandler handler = DownloadCompleted; lock (syncRoot) { UpdateProgress(); } OnStatusUpdated(); if (handler != null) { handler(this, new DownloadCompletedEventArgs(dif, new Uri(dif.LocalPath))); } }
public void Dequeue(DownloadInfo dif) { if (dif == null) { throw new ArgumentNullException("dif"); } if (!downloadQueue.Contains(dif)) { throw new ArgumentException(Catalog.GetString("Item not in queue.")); } downloadQueue.Remove(dif); // emit QueueChangedEvent }
public int IndexOfFirstReady() { DownloadInfo dif = null; int firstReady; for (firstReady = 0; firstReady < downloadQueue.Count; ++firstReady) { dif = downloadQueue [firstReady] as DownloadInfo; if (dif.State == DownloadState.Ready) { return(firstReady); } } return(-1); }
private void PumpQueue() { Thread.CurrentThread.Name = "PumpQueue"; int index; DownloadInfo dif = null; while (true) { if (Enabled) { dif = null; lock (download_queue.SyncRoot) { lock (tsm.SyncRoot) { if (download_queue.Count > 0 && download_queue.Count != tsm.CurrentDownloads) { if (tsm.CurrentDownloads < tsm.MaximumDownloads) { index = download_queue.IndexOfFirstReady(); if (index >= 0) { dif = download_queue [index]; dif.State = DownloadState.Running; } } } } } if (dif != null) { StartDownloadTask(dif); } } else { Monitor.Enter(dispatchThreadMonitor); Monitor.Wait(dispatchThreadMonitor); Monitor.Exit(dispatchThreadMonitor); } Thread.Sleep(32); } }
private static void Drop(DownloadInfo dif, bool emitEvent) { if (dif == null) { throw new ArgumentNullException("dif"); } lock (register_drop_sync) { lock (downloads.SyncRoot) { downloads.Remove(dif.UniqueKey); } lock (dispatcher.SyncRoot) { dispatcher.Drop(dif); } lock (download_queue.SyncRoot) { download_queue.Dequeue(dif); } lock (downloads.SyncRoot) { if (downloads.Count == 0) { dispatcher.Enabled = false; DestroyUserEvent((dif.State == DownloadState.Canceled)); lock (tsm.SyncRoot) { tsm.Reset(); } } } } if (emitEvent) { EmitDownloadDropped(new DownloadEventArgs(dif)); } }
public int IndexOfLastRunning() { DownloadInfo dif = null; int maxIndex = (downloadQueue.Count - 1); int lastRunning; for (lastRunning = maxIndex; lastRunning >= 0; --lastRunning) { dif = downloadQueue [lastRunning] as DownloadInfo; if (dif.State == DownloadState.Running) { return(lastRunning); } } return(-1); }
private void SetMaxDownloads(int max) { if (max < 0) { throw new ArgumentOutOfRangeException(Catalog.GetString ("Maximum number of concurrent downloads cannot be less than 0.")); } int delta = 0; int lastRunning = -1; DownloadInfo dif = null; lock (download_queue.SyncRoot) { lock (tsm.SyncRoot) { if (tsm.MaximumDownloads == max) { return; } tsm.MaximumDownloads = max; if (tsm.CurrentDownloads > tsm.MaximumDownloads) { delta = tsm.CurrentDownloads - tsm.MaximumDownloads; } lastRunning = download_queue.IndexOfLastRunning(); for (int i = 0; i < delta && lastRunning >= 0; ++i, --lastRunning) { dif = download_queue [lastRunning]; lock (dif.SyncRoot) { if (dif.State == DownloadState.Running) { dif.State = DownloadState.Queued; } } } } } }
public void Enqueue(DownloadInfo dif) { if (dif.State != DownloadState.New) { throw new ArgumentException(Catalog.GetString("dif not in 'New' state.")); } else if (downloadQueue.Contains(dif)) { throw new ArgumentException(Catalog.GetString("Already queued, must be unique.")); } else { dif.State = DownloadState.Ready; downloadQueue.Add(dif); } // emit queue changed. // emit new Item Queued for Transfer Manager }
public static DownloadTask Create(DownloadInfo dif) { if (dif == null) { throw new ArgumentNullException("dif"); } DownloadTask dt = null; if (dif.RemoteUri.Scheme == Uri.UriSchemeHttp || dif.RemoteUri.Scheme == Uri.UriSchemeHttps) { dt = new HttpDownloadTask(dif); } else { throw new NotSupportedException(Catalog.GetString("Uri scheme not supported")); } return(dt); }
private void Finished(DownloadInfo dif, DownloadTask dt) { if (dif == null || dt == null) { return; } if (dif.State == DownloadState.Canceled || dif.State == DownloadState.Failed) { lock (syncRoot) { if (dif.State == DownloadState.Failed) { ++FailedDownloads; } else { --TotalDownloads; } DeductBytesDownloaded(dt.BytesReceived); UpdateProgress(); TotalLength -= dt.Length; } OnDownloadStateChanged(DownloadTaskFinished, new DownloadEventArgs(dif)); } else if (dif.State == DownloadState.Completed) { lock (syncRoot) { ++SuccessfulDownloads; } OnDownloadCompleted(dif); OnDownloadStateChanged(DownloadTaskFinished, new DownloadEventArgs(dif)); } }
public static bool QueueDownload(DownloadInfo dif) { if (Canceling) { return(false); } bool ret = false; try { Register(dif, true); ret = true; } catch (Exception e) { Console.WriteLine(e.Message); EmitRegistrationFailed(new DownloadEventArgs(dif)); } return(ret); }
public DownloadEventArgs(DownloadInfo downloadInfo) : this(downloadInfo, null) { }
protected virtual void OnLengthChanged(DownloadInfo dif, long previousLength, long currentLength) { DownloadLengthChangedEventHandler handler = LengthChanged; if (handler != null) { handler (this, new DownloadLengthChangedEventArgs (dif, previousLength, currentLength)); } }
public static DownloadTask Create(DownloadInfo dif) { if (dif == null) { throw new ArgumentNullException ("dif"); } DownloadTask dt = null; if (dif.RemoteUri.Scheme == Uri.UriSchemeHttp || dif.RemoteUri.Scheme == Uri.UriSchemeHttps) { dt = new HttpDownloadTask (dif); } else { throw new NotSupportedException (Catalog.GetString("Uri scheme not supported")); } return dt; }
public DownloadMimeTypeChangedEventArgs(DownloadInfo downloadInfo, string previousMimeType, string newMimeType) : base(downloadInfo) { new_mime_type = newMimeType; previous_mime_type = previousMimeType; }
public DownloadCompletedEventArgs(DownloadInfo downloadInfo, Uri localUri) { uri = localUri; dif = downloadInfo; }
private static void OnDownloadTaskFinishedHandler(object sender, DownloadEventArgs args) { DownloadInfo dif = args.DownloadInfo; DownloadInfo[] difs = null; if (dif == null) { return; } bool drop_queued = false; lock (mass_drop_sync) { if (mass_drop_queue.Contains(dif)) { dropped.Add(dif); drop_queued = true; } if (mass_drop_queue.Count > 0 && dropped.Count == mass_drop_queue.Count) { difs = dropped.ToArray(typeof(DownloadInfo)) as DownloadInfo[]; dropped.Clear(); mass_drop_queue.Clear(); } } if (difs != null) { ArrayList dropped_downloads = new ArrayList(difs.Length); foreach (DownloadInfo d in difs) { try { Drop(d, false); dropped_downloads.Add(d); } catch (Exception) { continue; } } if (dropped_downloads.Count == 1) { EmitDownloadDropped(new DownloadEventArgs( dropped_downloads [0] as DownloadInfo) ); } else if (dropped_downloads.Count > 1) { EmitDownloadDropped(new DownloadEventArgs(dropped_downloads)); } EmitDownloadDropped(new DownloadEventArgs(dropped_downloads)); } else if (!drop_queued) { try { Drop(dif, true); } catch {} } }
public static void Unpause(DownloadInfo dif) { if (dif == null) { throw new ArgumentNullException ("dif"); } lock (download_queue.SyncRoot) { if (download_queue.Contains (dif)) { lock (dif.SyncRoot) { if (dif.State == DownloadState.Paused) { dif.State = DownloadState.Ready; } } } } }
public static bool QueueDownload(DownloadInfo dif) { if (Canceling) { return false; } bool ret = false; try { Register (dif, true); ret = true; } catch (Exception e) { Console.WriteLine (e.Message); EmitRegistrationFailed (new DownloadEventArgs (dif)); } return ret; }
public static DownloadInfo CreateDownloadInfo(string uri, string path, long length) { if (uri == null || uri == String.Empty) { throw new ArgumentException (Catalog.GetString("uri is empty")); } else if (path == null || path == String.Empty) { throw new ArgumentException (Catalog.GetString("path is empty")); } DownloadInfo dif = new DownloadInfo (uri, path, length); return dif; }
public static void Cancel(DownloadInfo dif) { if (dif == null) { throw new ArgumentNullException ("dif"); } if (dif.State == DownloadState.Canceled || dif.State == DownloadState.CancelRequested) { return; } if (dif.State != DownloadState.Running) { DownloadTask dt = null; lock (downloads.SyncRoot) { if (downloads.ContainsKey (dif.UniqueKey)) { dif.State = DownloadState.Canceled; dt = downloads [dif.UniqueKey] as DownloadTask; } } if (dt != null) { tsm.IdleDownloadCanceled (dif, dt); } } else { dif.State = DownloadState.CancelRequested; } }
public void Dequeue(DownloadInfo dif) { if (dif == null) { throw new ArgumentNullException ("dif"); } if (!downloadQueue.Contains (dif)) { throw new ArgumentException(Catalog.GetString("Item not in queue.")); } downloadQueue.Remove (dif); // emit QueueChangedEvent }
public bool Contains(DownloadInfo dif) { return downloadQueue.Contains (dif); }
public void RepositionDownloads(DownloadInfo[] difs, int position) { // ArgumentException if difs not in queue // ArgumentNullException if difs null, // ArgumentOutOfRangeException if position out of range, etc. // emit QueueChanged event }
public DownloadEventArgs(DownloadInfo downloadInfo, ICollection downloads) { dif = downloadInfo; this.downloads = downloads; }
private static void Drop(DownloadInfo dif, bool emitEvent) { if (dif == null) { throw new ArgumentNullException ("dif"); } lock (register_drop_sync) { lock (downloads.SyncRoot) { downloads.Remove (dif.UniqueKey); } lock (dispatcher.SyncRoot) { dispatcher.Drop (dif); } lock (download_queue.SyncRoot) { download_queue.Dequeue (dif); } lock (downloads.SyncRoot) { if (downloads.Count == 0) { dispatcher.Enabled = false; DestroyUserEvent ((dif.State == DownloadState.Canceled)); lock (tsm.SyncRoot) { tsm.Reset (); } } } } if (emitEvent) { EmitDownloadDropped (new DownloadEventArgs (dif)); } }
private static void DownloadRegistrationFailed(DownloadInfo dif) { downloads.Remove (dif); }
public void Enqueue(DownloadInfo dif) { if (dif.State != DownloadState.New) { throw new ArgumentException(Catalog.GetString("dif not in 'New' state.")); } else if (downloadQueue.Contains (dif)) { throw new ArgumentException(Catalog.GetString("Already queued, must be unique.")); } else { dif.State = DownloadState.Ready; downloadQueue.Add (dif); } // emit queue changed. // emit new Item Queued for Transfer Manager }
public void Drop(DownloadInfo dif) { lock (registered_downloads.SyncRoot) { registered_downloads.Remove (dif); } }
protected virtual void OnDownloadCompleted(DownloadInfo dif) { DownloadCompletedEventHandler handler = DownloadCompleted; lock (syncRoot) { UpdateProgress (); } OnStatusUpdated (); if (handler != null) { handler (this, new DownloadCompletedEventArgs (dif, new Uri (dif.LocalPath))); } }
public DownloadLengthChangedEventArgs(DownloadInfo downloadInfo, long previousLength, long currentLength) : base(downloadInfo) { previous_length = previousLength; current_length = currentLength; }
private static void DownloadRegistered(DownloadInfo dif) { if (downloads.Contains (dif)) { PodcastInfo pi = downloads [dif] as PodcastInfo; if (pi == null) { return; } pi.IsQueued = true; } }
protected internal DownloadTask(DownloadInfo dif) { if (dif == null) { throw new ArgumentNullException ("dif"); } this.dif = dif; totalLength = dif.Length; }
private static void DownloadDropped(DownloadInfo dif) { if (downloads.Contains (dif)) { PodcastInfo pi = downloads [dif] as PodcastInfo; if (pi == null) { return; } pi.DownloadFailed = (dif.State == DownloadState.Failed); if (pi.DownloadFailed) { PodcastErrorsSource.Instance.AddError ( dif.RemoteUri.ToString (), Catalog.GetString ("Download Failed"), null ); } pi.DownloadInfo = null; pi.IsQueued = false; downloads.Remove (dif); } }
protected virtual void OnFilePathChanged( DownloadInfo downloadInfo, string previousFilePath, string newFilePath) { DownloadFilePathChangedEventHandler handler = FilePathChanged; if (handler != null) { handler (this, new DownloadFilePathChangedEventArgs (downloadInfo, previousFilePath, previousFilePath)); } }
private void StartDownloadTask(DownloadInfo dif) { if (dif == null) { return; } DownloadTask dt = null; lock (registered_downloads.SyncRoot) { if (registered_downloads.Contains (dif)) { dt = registered_downloads [dif] as DownloadTask; } else { return; } } if (dt != null) { dt.Execute (); } }
protected virtual void OnMimeTypeChanged( DownloadInfo downloadInfo, string previousMimeType, string newMimeType) { DownloadMimeTypeChangedEventHandler handler = MimeTypeChanged; if (handler != null) { handler (this, new DownloadMimeTypeChangedEventArgs (downloadInfo, previousMimeType, newMimeType)); } }
public void Register(DownloadInfo dif, DownloadTask dt) { lock (registered_downloads.SyncRoot) { registered_downloads.Add (dif, dt); } }
private static void Register(DownloadInfo dif, bool emitEvent) { if (dif == null) { throw new ArgumentNullException("dif"); } lock (register_drop_sync) { if (disposing || disposed) { throw new RegistrationException(Catalog.GetString("DownloadCore is shutting down.")); } else if (dif.State != DownloadState.New) { throw new RegistrationException(Catalog.GetString("dif not in 'New' state.")); } DownloadTask dt = null; lock (downloads.SyncRoot) { try { dt = DownloadTask.Create(dif); } catch (NotSupportedException) { throw new RegistrationException(Catalog.GetString("Uri scheme not supported.")); } catch (Exception e) { throw new RegistrationException(e.Message); } if (downloads.ContainsKey(dif.UniqueKey)) { throw new RegistrationException(Catalog.GetString("Download already queued.")); } if (downloads.Count == 0) { CreateUserEvent(); dispatcher.Enabled = true; } downloads.Add(dif.UniqueKey, dt); } lock (tsm.SyncRoot) { tsm.Register(dt); } lock (dispatcher.SyncRoot) { dispatcher.Register(dif, dt); } lock (download_queue.SyncRoot) { download_queue.Enqueue(dif); } } if (emitEvent) { EmitDownloadRegistered(new DownloadEventArgs(dif)); } }
public bool Contains(DownloadInfo dif) { return(downloadQueue.Contains(dif)); }
private void Finished(DownloadInfo dif, DownloadTask dt) { if (dif == null || dt == null) { return; } if (dif.State == DownloadState.Canceled || dif.State == DownloadState.Failed) { lock (syncRoot) { if (dif.State == DownloadState.Failed) { ++FailedDownloads; } else { --TotalDownloads; } DeductBytesDownloaded (dt.BytesReceived); UpdateProgress (); TotalLength -= dt.Length; } OnDownloadStateChanged (DownloadTaskFinished, new DownloadEventArgs (dif)); } else if (dif.State == DownloadState.Completed) { lock (syncRoot) { ++SuccessfulDownloads; } OnDownloadCompleted (dif); OnDownloadStateChanged (DownloadTaskFinished, new DownloadEventArgs (dif)); } }
internal void IdleDownloadCanceled(DownloadInfo dif, DownloadTask dt) { Finished(dif, dt); }
private static void Register(DownloadInfo dif, bool emitEvent) { if (dif == null) { throw new ArgumentNullException ("dif"); } lock (register_drop_sync) { if (disposing || disposed) { throw new RegistrationException (Catalog.GetString("DownloadCore is shutting down.")); } else if (dif.State != DownloadState.New) { throw new RegistrationException (Catalog.GetString("dif not in 'New' state.")); } DownloadTask dt = null; lock (downloads.SyncRoot) { try { dt = DownloadTask.Create (dif); } catch (NotSupportedException) { throw new RegistrationException (Catalog.GetString("Uri scheme not supported.")); } catch (Exception e) { throw new RegistrationException (e.Message); } if (downloads.ContainsKey (dif.UniqueKey)) { throw new RegistrationException (Catalog.GetString("Download already queued.")); } if (downloads.Count == 0) { CreateUserEvent(); dispatcher.Enabled = true; } downloads.Add (dif.UniqueKey, dt); } lock (tsm.SyncRoot) { tsm.Register (dt); } lock (dispatcher.SyncRoot) { dispatcher.Register (dif, dt); } lock (download_queue.SyncRoot) { download_queue.Enqueue (dif); } } if (emitEvent) { EmitDownloadRegistered (new DownloadEventArgs (dif)); } }
private static void DownloadTaskStartedOrStopped(DownloadInfo dif, bool started) { lock (downloads.SyncRoot) { if (downloads.Contains (dif)) { PodcastInfo pi = downloads [dif] as PodcastInfo; if (pi != null) { if (started) { pi.IsDownloading = true; } else { pi.IsDownloading = false; } } } } source.Update (); }
public HttpDownloadTask(DownloadInfo dif) : base(dif) { }