예제 #1
0
        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();
                }
            }
        }