public void OnAllompleted() { DownloaderState = EDownloaderState.Completed; if(Settings.ShutDown) ShutDown(); }
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 async Task Stop() { if (DownloaderState != EDownloaderState.Running) return; DownloaderState = EDownloaderState.Stopping; await Task.Run(() => { var dl = RunningDownloads.ToArray(); foreach (var d in dl) { d.Stop(); } }); }