Example #1
0
        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);
        }
Example #2
0
        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));
            }
        }
        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));
            }
        }
Example #4
0
 internal void IdleDownloadCanceled(DownloadInfo dif, DownloadTask dt)
 {
     Finished(dif, dt);
 }
 public void Register(DownloadInfo dif, DownloadTask dt)
 {
     lock (registered_downloads.SyncRoot)
     {
         registered_downloads.Add (dif, 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));
            }
        }
 internal void IdleDownloadCanceled(DownloadInfo dif, DownloadTask dt)
 {
     Finished (dif, dt);
 }
        public void Register(DownloadTask dt)
        {
            dt.Started += OnDownloadTaskStartedHandler;
            dt.Stopped += OnDownloadTaskStoppedHandler;
            dt.Finished += OnDownloadTaskFinishedHandler;

            dt.LengthChanged += OnDownloadLengthChangedHandler;
            dt.ProgressChanged += OnDiscreteDownloadProgressChangedHandler;

            ++TotalDownloads;
            TotalLength += dt.Length;

            UpdateProgress ();
            OnStatusUpdated ();
        }