예제 #1
0
        private void StartDownloadA()
        {
            NeedGoodGonfigData();

            string url            = URL;
            string GzFileName     = "";
            string GzFullFileName = "";

            GzFileName = Utils.GetFileNameFromURL(url);
            if (GzFileName == url)
            {
                OnDownloadEvent(null, ESimpleEvent.finished, "");
                return;
            }
            GzFullFileName = TopManager.DownloadFolder + "\\" + GzFileName;
            if (File.Exists(GzFullFileName))
            {
                File.Delete(GzFullFileName);
            }
            Downloader = TopManager.St.DownloaderManager.AddDownload(OnDownloadEvent, url, GzFullFileName, OnDownloadProgress);
            if (Downloader == null)
            {
                DoError("Allready downloading the file");
                return;
            }
            return;
        }
예제 #2
0
        void OnDownloadEvent(CDownload downloader, ESimpleEvent downloadEvent, string msg)
        {
            lock (this)
            {
                switch (downloadEvent)
                {
                case ESimpleEvent.started:
                    OnStateChanged(ESourceState.DownloadStarted);
                    break;

                case ESimpleEvent.canceled:
                    LogError("download canceled");
                    OnStateChanged(ESourceState.DownloadFailed);
                    break;

                case ESimpleEvent.failed:
                    OnStateChanged(ESourceState.DownloadFailed);
                    break;

                case ESimpleEvent.finished:
                    OnStateChanged(ESourceState.DownloadFinished);
                    break;
                }
            }
            OnSubTaskEvent(downloadEvent);
        }
예제 #3
0
        public void DownloadStateChanged(CDownload sender, EDownloadStatus state)
        {
            lock (this)
            {
                if (!AllDownloads.Contains(sender))
                {
                    return;
                }
                switch (state)
                {
                case EDownloadStatus.started:
                    if (!RunningDownloads.Contains(sender))
                    {
                        RunningDownloads.Add(sender);
                    }
                    break;

                case EDownloadStatus.failed:
                case EDownloadStatus.canceled:
                case EDownloadStatus.timeout:
                case EDownloadStatus.finished:
                    RunningDownloads.Remove(sender);
                    AllDownloads.Remove(sender);
                    AllDownloadsByFileName.Remove(sender.FullFileName);
                    StartNextDownload();
                    break;
                }
                if (DownloadListener != null)
                {
                    DownloadListener.DownloadStateChanged(sender, state);
                }
            }
        }
예제 #4
0
 void OnDownloadProgress(CDownload downloader, int progress)
 {
     if (Downloader != downloader)
     {
         return;
     }
     Progress = progress;
     OnStateChanged(ESourceState.Downloading);
 }
예제 #5
0
 public void ProgressChanged(CDownload sender)
 {
     lock (this)
     {
         if (DownloadListener != null)
         {
             DownloadListener.ProgressChanged(sender);
         }
     }
 }
예제 #6
0
 public void ClearState()
 {
     lock (this)
     {
         if (TaskState == ESimpleEvent.started)
         {
             DoError("busy");
         }
         ScheduledTasks.Clear();
         CancelToken  = false;
         State        = ESourceState.None;
         TaskState    = ESimpleEvent.none;
         SubTaskState = ESimpleEvent.none;
         Downloader   = null;
         GzipExtract  = null;
         Progress     = 0;
     }
 }
예제 #7
0
 public CDownload AddDownload(DDownloadEventListener downloadEventListener
                              , string url, string targetfilename, DDownloadProgressListener progresseventlistener)
 {
     //url = url.ToLower();
     //targetfilename = targetfilename.ToLower();
     lock (this)
     {
         CDownload download = GetDownloadByFileName(targetfilename);
         if (download != null)
         {
             return(null);
         }
         download = new CDownload(this, downloadEventListener, url
                                  , targetfilename, progresseventlistener);
         AllDownloads.Add(download);
         AllDownloadsByFileName[targetfilename] = download;
         if (RunningDownloads.Count == 0)
         {
             download.StartDownload();
         }
         return(download);
     }
 }