private void timerProgress_Tick(object sender, EventArgs e) { DownloadProgressBar.Maximum = 100; DownloadProgressBar.Minimum = 0; int iPos = 0; //获取下载进度 iPos = CHCNetSDK.NET_DVR_GetDownloadPos(m_lDownHandle); if ((iPos > DownloadProgressBar.Minimum) && (iPos < DownloadProgressBar.Maximum)) { DownloadProgressBar.Value = iPos; } if (iPos == 100) //下载完成 { DownloadProgressBar.Value = iPos; if (!CHCNetSDK.NET_DVR_StopGetFile(m_lDownHandle)) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_StopGetFile failed, error code= " + iLastErr; //下载控制失败,输出错误号 MessageBox.Show(str); return; } m_lDownHandle = -1; timerDownload.Stop(); } if (iPos == 200) //网络异常,下载失败 { MessageBox.Show("The downloading is abnormal for the abnormal network!"); timerDownload.Stop(); } }
public int GetDownloadPos() { LastRunTime = DateTime.Now.Ticks / 10000; if (_downloadprogress == 100) { if (!_finsh) { _finsh = true; Console.WriteLine(this._download + "完成" + "." + CHCNetSDK.NET_DVR_GetLastError()); while (!CHCNetSDK.NET_DVR_StopGetFile(this._download)) { Console.WriteLine("停止下载"); _log.Info("停止下载"); Thread.Sleep(100); } GC.Collect(); } return(_downloadprogress); } else { _downloadprogress = CHCNetSDK.NET_DVR_GetDownloadPos(this._download); } return(_downloadprogress); }
private async Task <Boolean> DownloadRecording(Recording recording) { if (_mLDownHandle >= 0) { Console.WriteLine("Error, already downloading!"); return(false); } var sVideoFileName = _outputLocationPath + recording.GetFileName() + _videoExtension; Console.WriteLine("Downloading: " + recording.GetFileName()); // Download from nvr/camera by file name _mLDownHandle = CHCNetSDK.NET_DVR_GetFileByName(_mLUserId, recording.GetFileName(), sVideoFileName); if (_mLDownHandle < 0) { _iLastErr = CHCNetSDK.NET_DVR_GetLastError(); _errorMsg = "NET_DVR_GetFileByName failed, error code= " + _iLastErr; Console.WriteLine(_errorMsg); if (_iLastErr == 34) // Target folder does not exist, create it { System.IO.Directory.CreateDirectory(_outputLocationPath); } return(false); } uint iOutValue = 0; if (!CHCNetSDK.NET_DVR_PlayBackControl_V40(_mLDownHandle, CHCNetSDK.NET_DVR_PLAYSTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue)) { _iLastErr = CHCNetSDK.NET_DVR_GetLastError(); _errorMsg = "NET_DVR_PLAY_START failed, error code= " + _iLastErr; // Download controlling failed, print error code Console.WriteLine(_errorMsg); return(false); } var downloadProgress = 0; while (downloadProgress < 100) { // Get downloading process downloadProgress = CHCNetSDK.NET_DVR_GetDownloadPos(_mLDownHandle); Thread.Sleep(1 * 1000); Console.WriteLine("Download progress: " + downloadProgress + "%"); } _mLDownHandle = -1; return(true); }
public int GetDownloadProgress() { int iPos = 0; if ((iPos = CHCNetSDK.NET_DVR_GetDownloadPos(DownloadHandle)) < 0) { var iLastErr = NET_DVR_GetLastError(); throw new Exception("NET_DVR_GetDownloadPos failed, error code= " + iLastErr); } return(iPos); }
public async Task <OResult <Boolean> > DownloadByTimeAsync(DownloadFileByTimeRequest request, CancellationToken cancellationToken = default) { try { var now = DateTime.Now; if (request.From > now) { request.From = now; } if (request.To > now) { request.To = now; } if (request.From > request.To) { request.To = DateTime.Now; } CHCNetSDK.NET_DVR_PLAYCOND struDownPara = new CHCNetSDK.NET_DVR_PLAYCOND(); struDownPara.dwChannel = (UInt32)_loginRequest.ChannelNo; //设置下载的开始时间 struDownPara.struStartTime.dwYear = (UInt32)request.From.Year; struDownPara.struStartTime.dwMonth = (UInt32)request.From.Month; struDownPara.struStartTime.dwDay = (UInt32)request.From.Day; struDownPara.struStartTime.dwHour = (UInt32)request.From.Hour; struDownPara.struStartTime.dwMinute = (UInt32)request.From.Minute; struDownPara.struStartTime.dwSecond = (UInt32)request.From.Second; //设置下载的结束时间 struDownPara.struStopTime.dwYear = (UInt32)request.To.Year; struDownPara.struStopTime.dwMonth = (UInt32)request.To.Month; struDownPara.struStopTime.dwDay = (UInt32)request.To.Day; struDownPara.struStopTime.dwHour = (UInt32)request.To.Hour; struDownPara.struStopTime.dwMinute = (UInt32)request.To.Minute; struDownPara.struStopTime.dwSecond = (UInt32)request.To.Second; var m_lDownHandle = CHCNetSDK.NET_DVR_GetFileByTime_V40(_userId, request.FilePath, ref struDownPara); if (m_lDownHandle < 0) { return(new OResult <Boolean>(false, HkvsErrorCode.GetLastErrorCode(), $"按时间下载失败:{HkvsErrorCode.GetLastErrorMessage()}")); } UInt32 iOutValue = 0; var succ = CHCNetSDK.NET_DVR_PlayBackControl_V40(m_lDownHandle, CHCNetSDK.NET_DVR_PLAYSTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue); if (!succ) { return(new OResult <Boolean>(false, HkvsErrorCode.GetLastErrorCode(), $"按时间下载失败:{HkvsErrorCode.GetLastErrorMessage()}")); } var tcs = new TaskCompletionSource <Boolean>(); _ = Task.Run(async() => { var iPos = 0; while (!cancellationToken.IsCancellationRequested) { iPos = CHCNetSDK.NET_DVR_GetDownloadPos(m_lDownHandle); switch (iPos) { case 100: CHCNetSDK.NET_DVR_StopGetFile(m_lDownHandle); tcs.SetResult(true); return; case 200: tcs.SetException(new SystemException("网络中断")); CHCNetSDK.NET_DVR_StopGetFile(m_lDownHandle); return; } await Task.Delay(1000); } }, CancellationToken.None); succ = await tcs.Task; if (!succ) { return(new OResult <Boolean>(false, "按时间下载失败")); } return(new OResult <Boolean>(true)); } catch (Exception ex) { return(new OResult <Boolean>(false, ex)); } }
public int GetDownloadPosition(int downloadHandle) { int iPos = CHCNetSDK.NET_DVR_GetDownloadPos(downloadHandle); return(iPos); }