예제 #1
0
        public void DownloadTime(object req)
        {
            LastRunTime = DateTime.Now.Ticks / 10000;
            _obj        = req;
            _finsh      = false;
            RunParam parm    = (RunParam)req;
            Channel  request = parm.Channel;

            _channel = request;
            int userId = request.UserId; int index = request.Index; DateTime start = request.StartTime; DateTime end = request.EndTime;

            //  Console.WriteLine("下载" + userId + "." + index);
            _userId = userId;
            CHCNetSDK.NET_DVR_PLAYCOND struDownPara = new CHCNetSDK.NET_DVR_PLAYCOND();
            struDownPara.dwChannel = (uint)index;
            //设置下载的开始时间 Set the starting time
            struDownPara.struStartTime.dwYear   = (uint)start.Year;
            struDownPara.struStartTime.dwMonth  = (uint)start.Month;
            struDownPara.struStartTime.dwDay    = (uint)start.Day;
            struDownPara.struStartTime.dwHour   = (uint)start.Hour;
            struDownPara.struStartTime.dwMinute = (uint)start.Minute;
            struDownPara.struStartTime.dwSecond = (uint)start.Second;

            //设置下载的结束时间 Set the stopping time
            struDownPara.struStopTime.dwYear   = (uint)end.Year;
            struDownPara.struStopTime.dwMonth  = (uint)end.Month;
            struDownPara.struStopTime.dwDay    = (uint)end.Day;
            struDownPara.struStopTime.dwHour   = (uint)end.Hour;
            struDownPara.struStopTime.dwMinute = (uint)end.Minute;
            struDownPara.struStopTime.dwSecond = (uint)end.Second;
            string sVideoFileName;  //录像文件保存路径和文件名 the path and file name to save

            sVideoFileName = parm.SavePath + "\\" + parm.FileName + "." + request.No + ".mp4";
            _log.Error(sVideoFileName);
            if (File.Exists(sVideoFileName))
            {
                _log.Info(sVideoFileName + "文件已存在");
                _downloadprogress = 100;
                _finsh            = true;
            }
            else
            {
                //按时间下载 Download by time
                this._download = CHCNetSDK.NET_DVR_GetFileByTime_V40(userId, sVideoFileName, ref struDownPara);
                int t = 0;
                while (this._download < 0 && t < 10)
                {
                    Console.WriteLine(_channel.ChannelIp + "." + _download + ":重试" + CHCNetSDK.NET_DVR_GetLastError());
                    _log.Info(_channel.ChannelIp + "." + _download + ":重试" + CHCNetSDK.NET_DVR_GetLastError());
                    _download = CHCNetSDK.NET_DVR_GetFileByTime_V40(userId, sVideoFileName, ref struDownPara);
                    t++;
                    Thread.Sleep(300);
                }
                uint iOutValue = 0;
                if (!CHCNetSDK.NET_DVR_PlayBackControl_V40(_download, CHCNetSDK.NET_DVR_PLAYSTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue))
                {
                    _log.Info(_download + "." + CHCNetSDK.NET_DVR_GetLastError());
                    Console.WriteLine(CHCNetSDK.NET_DVR_GetLastError());
                }
            }
        }
예제 #2
0
        public bool RequestGobal(List <Channel> channels, string fileName)
        {
            Dictionary <int, NVRDownloadTime> status = new Dictionary <int, NVRDownloadTime>();
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < channels.Count; i++)
            {
                NVRInfo nvr = NVRInfos.FirstOrDefault(o => o.Host.DVRIPAddress == channels[i].NvrIp);
                if (nvr == null)
                {
                    return(false);
                }
                channels[i].NvrIp  = nvr.Host.DVRIPAddress;
                channels[i].UserId = nvr.Host.LUserId;
                channels[i].No     = i;

                IPC ipc = nvr.IPCs.FirstOrDefault(o => o.ChannelIp == channels[i].ChannelIp);
                if (ipc != null)
                {
                    channels[i].Index = ipc.ChannelIndex;
                    RunParam param = new RunParam {
                        FileName = fileName, Channel = channels[i], SavePath = Temp.Replace("\\", "\\\\")
                    };
                    if (ipc.Status == 1)
                    {
                        NVRDownloadTime down = new NVRDownloadTime();
                        Device.LastRunTime = down.LastRunTime;
                        status.Add(i, down);
                        down.DownloadTime(param);
                        // Thread t = new Thread(new ParameterizedThreadStart(down.DownloadTime));
                        // t.Start(param);
                    }
                }
                Thread.Sleep(10);
            }
            int  times  = 0;
            int  error  = 0;
            bool result = false;

            while (true)
            {
                bool flag = true;
                foreach (KeyValuePair <int, NVRDownloadTime> kv in status)
                {
                    Device.LastRunTime = kv.Value.LastRunTime;
                    if (kv.Value.GetDownloadPos() < 100 && kv.Value.Error == 0)
                    {
                        flag = false;
                    }
                    if (kv.Value.GetDownloadPos() == 100 && !kv.Value.Write)
                    {
                        kv.Value.Write = true;
                    }
                    Console.WriteLine(kv.Key + "." + kv.Value.GetDownloadPos() + "." + kv.Value.Error);
                    Thread.Sleep(20);
                }
                if (times > 10000)
                {
                    foreach (KeyValuePair <int, NVRDownloadTime> kv in status)
                    {
                        kv.Value.CancelDownload();
                    }
                    result = false;
                    break;
                }
                if (flag)
                {
                    result = true;
                    break;
                }
                Thread.Sleep(30);
                times++;
            }
            if (result)
            {
                foreach (KeyValuePair <int, NVRDownloadTime> kv in status)
                {
                    if (kv.Value.Write)
                    {
                        sb.AppendLine("file " + Temp.Replace("\\", "\\\\") + fileName + "." + kv.Value.GetChannel.No + ".mp4" + "");
                    }
                }
                System.IO.File.WriteAllText(Temp + fileName + "_gobal.txt", sb.ToString(), Encoding.ASCII);
            }
            return(result);
        }