public void OnStatusChenged(Download d, EDownloadStatus oldstatus, EDownloadStatus newstatus) { if (Deserializing) return; if (MainForm != null && !MainForm.Disposing && !MainForm.IsDisposed && MainForm.InvokeRequired) { try { MainForm.Invoke((Action<Download, EDownloadStatus, EDownloadStatus>)OnStatusChengedA, new object[] { d, oldstatus, newstatus }); } catch (Exception) { } } else OnStatusChengedA(d, oldstatus, newstatus); }
public void OnStatusChengedA(Download d, EDownloadStatus oldstatus, EDownloadStatus newstatus) { if (Deserializing) return; if (newstatus == EDownloadStatus.Running) { if (RunningDownloads.Contains(d)) return; RunningDownloads.Add(d); DownloaderState = EDownloaderState.Running; } else if (newstatus == EDownloadStatus.Completed) { if (!RunningDownloads.Contains(d)) return; RunningDownloads.Remove(d); if (IsCompleted()) OnAllompleted(); else if (RunningDownloads.Count < MaxParalelDownloads) StartNext(); } else if (newstatus == EDownloadStatus.Stopped) { if (!RunningDownloads.Contains(d)) return; RunningDownloads.Remove(d); if (d.Reseting) d.ResetA(); if (d.Removing) d.RemoveA(); if(DownloaderState == EDownloaderState.Stopping) { if(RunningDownloads.Count == 0) DownloaderState = EDownloaderState.Stopped; } else if (DownloaderState == EDownloaderState.Running) { if (IsCompleted()) OnAllompleted(); else if (RunningDownloads.Count < MaxParalelDownloads) StartNext(); } } else if (newstatus == EDownloadStatus.Error) { if (!RunningDownloads.Contains(d)) return; RunningDownloads.Remove(d); if (DownloaderState == EDownloaderState.Stopping) { if (RunningDownloads.Count == 0) DownloaderState = EDownloaderState.Stopped; } else if (DownloaderState == EDownloaderState.Running) { if (IsCompleted()) OnAllompleted(); else if (RunningDownloads.Count < MaxParalelDownloads) StartNext(); } } }
public void AddLinksToPreQueue(List<string> links) { if (links == null || links.Count == 0) return; List<Download> dl = new List<Download>(); foreach(var s in links) { if (PreQueue.Where(pd => pd.Url == s).FirstOrDefault() != null) continue; var d = new Download() { Url = s, Folder = Settings.DownloadTo }; dl.Add(d); PreQueue.Add(d); } CheckStatus(dl); }
public Download Copy() { var cp = new Download() { _Status = this._Status, _Url = this._Url, _FileName = this._FileName, _Folder = this._Folder, _FullFileName = this._FullFileName, _StatusText = this._StatusText, _FileSize = this._FileSize, _FileSizeText = this._FileSizeText, _BytesRead = this._BytesRead, _Speed = this._Speed, _Enabled = this._Enabled, _ErrorText = this._ErrorText }; return cp; }