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; }
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); }
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); } } }
void OnDownloadProgress(CDownload downloader, int progress) { if (Downloader != downloader) { return; } Progress = progress; OnStateChanged(ESourceState.Downloading); }
public void ProgressChanged(CDownload sender) { lock (this) { if (DownloadListener != null) { DownloadListener.ProgressChanged(sender); } } }
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; } }
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); } }