public void Pause() { removeInvalidDownloadingNum(); if (!DownloadStatusManager.IsPauseOrEnd(DownloadStatus)) { _downloader.Stop(); } }
private void updateSpeed(long speed) { if (DownloadStatus == DownloadStatus.Downloading) { Speed = getByteLengthString(speed) + "/s"; } else { Speed = DownloadStatusManager.ToHanZi(DownloadStatus); } }
private void run() { while (true) { updateDynamicInfo(); if (!DownloadStatusManager.IsDownloadingOrWaiting(DownloadStatus)) { break; } Thread.Sleep(1000); } }
public void TestDownloadStatusManager() { foreach (var status in Enum.GetValues(typeof(DownloadStatus))) { Assert.IsFalse(string.IsNullOrEmpty(DownloadStatusManager.ToHanZi((DownloadStatus)status))); } string.IsNullOrEmpty(DownloadStatusManager.ToHanZi((DownloadStatus)10)); statusCheck(DownloadStatusManager.IsWaitingOrPause, DownloadStatus.Waiting, DownloadStatus.Paused); statusCheck(DownloadStatusManager.IsDownloading, DownloadStatus.Downloading, DownloadStatus.Ready); statusCheck(DownloadStatusManager.IsDownloadingOrWaiting, DownloadStatus.Waiting, DownloadStatus.Downloading, DownloadStatus.Ready); statusCheck(DownloadStatusManager.IsPauseOrEnd, DownloadStatus.Completed, DownloadStatus.Error, DownloadStatus.Deleted, DownloadStatus.Paused); statusCheck(DownloadStatusManager.IsEndOfDownload, DownloadStatus.Completed, DownloadStatus.Error, DownloadStatus.Deleted); }
private void onStatus() { DownloadStatus status = _downloader.DownloadingStatus; if (!DownloadStatusManager.IsDownloadingOrWaiting(status)) { Pause(); } if (status == DownloadStatus.Completed) { onChanged(nameof(UpdatedLastestTime)); } onChanged(nameof(ErrorInfo)); onChanged(nameof(DownloadStatus)); updateDynamicInfo(); }
public Downloader(IDownloadInfo info, DownloadStatus status, string errorInfo, string name) { DownloadInfo = info; ErrorInfom = errorInfo; Path = System.IO.Path.Combine(DownloadInfo.DownloadPath, name); load(); if (DownloadingStatus == DownloadStatus.Waiting) { if (DownloadStatusManager.IsDownloadingOrWaiting(status)) { status = DownloadStatus.Waiting; } onStatus(status); updateFromDownloadedStatus(); } }
private void updateDownloading() { if (!_isUpdateDowningIfChanged || !_needDowning) { return; } _needDowning = false; while (DownloadingLimitManager.Instance.IsDownloadingLess()) { Console.WriteLine("{0} - {1}", DownloadingLimitManager.Instance.DownloadingNum, DownloadingLimitManager.Instance.DownloadingSup); lock (_downloads) { var down = _downloads.FirstOrDefault(_ => _.DownloadStatus == DownloadStatus.Waiting); if (down != null) { down.Start(); } else { break; } } } while (DownloadingLimitManager.Instance.IsDownloadingMore()) { Console.WriteLine("{0} - {1}", DownloadingLimitManager.Instance.DownloadingNum, DownloadingLimitManager.Instance.DownloadingSup); lock (_downloads) { var down = _downloads.LastOrDefault(_ => DownloadStatusManager.IsDownloading(_.DownloadStatus) && !_.IsPrior); if (down != null) { down.Waiting(); } else { break; } } } }
public void Start() { if (DownloadStatus == DownloadStatus.Completed) { return; } if (DownloadStatusManager.IsDownloading(DownloadStatus)) { return; } if (IsPrior || DownloadingLimitManager.Instance.IsDownloadingLess()) { removeInvalidDownloadingNum(); _downloading = true; DownloadingLimitManager.Instance.DownloadingNum++; updateThread(); _downloader.Start(); } else { Waiting(); } }
private void run() { try { //时间段分布 while (!_disposeEvent.WaitOne(1)) { VideoTimePeriodsPacket valid = _download.GetVideoTimePeriods(); if (valid != null) { send(ParamCode.TimePeriods, VideoTimePeriodsPacket.Encode(valid)); break; } } //视频包头 while (!_disposeEvent.WaitOne(1)) { VideoBasePacket vbp = _download.GetVideoBasePacket(); if (vbp != null) { send(ParamCode.VideoBaseInfo, VideoBasePacket.Encode(vbp)); break; } } //实时下载进度 while (!_disposeEvent.WaitOne(1)) { Thread.Sleep(1000); bool canStopFeedback = canStopFeedbackProcess(); VideoTimePeriodsPacket down = _download.GetCompletedTimePeriods(); if (down != null) { send(ParamCode.DownloadProgress, VideoTimePeriodsPacket.Encode(down)); } if (canStopFeedback) { Console.WriteLine("Stop Feedback RealTime Process! "); if (_download is OnlineDownloadManager) { var downStatus = (_download as OnlineDownloadManager).DownloadStatus; if (downStatus != DownloadStatus.Completed) { var name = _download.GetVideoTimePeriods().VideoName; string status = DownloadStatusManager.ToHanZi(downStatus); string message = name + status + "!"; if (downStatus == DownloadStatus.Error) { message += "\n" + (_download as OnlineDownloadManager).ErrorInfo; } if (downStatus != DownloadStatus.Deleted) { sendMessage(MessageType.Warn, message, "停止更新下载进度!"); } } } break; } } } catch (Exception ex) { Exception e = ex.InnerException == null? ex : ex.InnerException; sendMessage(MessageType.Error, e.Message, "停止更新下载进度!"); Console.WriteLine(ex); } }
bool isNeedStartDownload() { return(IsPrior && (DownloadStatusManager.IsWaitingOrPause(DownloadStatus))); }
public bool IsEndOfDownload() { return(DownloadStatusManager.IsEndOfDownload(DownloadStatus)); }
void updateIsDownloading() { _changedDownloadingFromService = true; IsDownloading = DownloadStatusManager.IsDownloadingOrWaiting(DownloadStatus); _changedDownloadingFromService = false; }