BiliRanking.Core.Download.MultiThreadedWebDownloader.OnStatusChanged C# (CSharp) Method

OnStatusChanged() protected method

Raise StatusChanged event.
protected OnStatusChanged ( EventArgs e ) : void
e System.EventArgs
return void
        protected virtual void OnStatusChanged(EventArgs e)
        {
            switch (this.Status)
            {
                case DownloadStatus.Waiting:
                case DownloadStatus.Downloading:
                case DownloadStatus.Paused:
                case DownloadStatus.Canceled:
                case DownloadStatus.Completed:
                    if (this.StatusChanged != null)
                    {
                        this.StatusChanged(this, e);
                    }
                    break;
                default:
                    break;
            }

            if (this.Status == DownloadStatus.Paused
                || this.Status == DownloadStatus.Canceled
                || this.Status == DownloadStatus.Completed)
            {
                this.usedTime += DateTime.Now - lastStartTime;
            }

            if (this.Status == DownloadStatus.Canceled)
            {
                Exception ex = new Exception("Downloading is canceled by user's request. ");
                this.OnDownloadCompleted(
                    new DownloadCompletedEventArgs(
                        null,
                        this.DownloadedSize,
                        this.TotalSize,
                        this.TotalUsedTime,
                        ex));
            }

            if (this.Status == DownloadStatus.Completed)
            {
                this.OnDownloadCompleted(
                    new DownloadCompletedEventArgs(
                        new FileInfo(this.DownloadPath),
                        this.DownloadedSize,
                        this.TotalSize,
                        this.TotalUsedTime,
                        null));
            }
        }