Example #1
0
 private void updateSpeed(long speed)
 {
     if (DownloadStatus == DownloadStatus.Downloading)
     {
         Speed = getByteLengthString(speed) + "/s";
     }
     else
     {
         Speed = DownloadStatusManager.ToHanZi(DownloadStatus);
     }
 }
 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);
 }
Example #3
0
        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);
            }
        }