Пример #1
0
        public DVRcheckinfoModel GetDVRCheckInfoByDVR_ID(string DVR_ID)
        {
            var dvrurl  = _configuration.GetSection("DVRInfourl:url").Value;
            var dvrdata = _dVRAppService.GetListByCondition(null, null, null, DVR_ID).Result.Items.FirstOrDefault();
            List <DVRCheckInfoDto> listdVRCheckInfo = new List <DVRCheckInfoDto>();

            if (dvrdata != null)
            {
                string url      = $"{dvrurl}/api/DVRInfo/Get?IP={dvrdata.DVR_IP}&name={dvrdata.DVR_usre}&password={dvrdata.DVR_possword}";
                var    handler  = new HttpClientHandler();//{ AutomaticDecompression = DecompressionMethods.GZip };
                var    response = _httpClient.GetAsync(url).Result;
                var    dt       = response.Content.ReadAsStringAsync().Result;
                var    data     = Newtonsoft.Json.JsonConvert.DeserializeObject <DVRInfoDto>(dt);

                DVRcheckinfoModel dVRCheckInfo = new DVRcheckinfoModel();
                //时间检查验证
                var servertime = DateTime.Now;
                dVRCheckInfo.SystemTime = servertime.ToString("yyyy-MM-dd HH:mm:ss");
                DateTime dvrtime = Convert.ToDateTime(data.DVR_DateTine);
                dVRCheckInfo.DVRTime = data.DVR_DateTine;
                if (DateTime.Compare(servertime.AddSeconds(-10), dvrtime) < 0 && DateTime.Compare(servertime.AddSeconds(10), dvrtime) > 0)
                {
                    dVRCheckInfo.TimeInfoChenk = true;
                }
                else
                {
                    dVRCheckInfo.TimeInfoChenk = false;
                }
                //硬盘检查装配
                int            dvrhard     = (int)(dvrdata.Hard_drive * 0.91);
                List <DVRDisk> listdvrdisk = new List <DVRDisk>();

                //装配硬盘
                foreach (var item in data.DVRDisk)
                {
                    DVRDisk dVRDisk = new DVRDisk();
                    dVRDisk.Number = item.Number;
                    dVRDisk.Disk   = item.Disk / 1000;//四舍五入取值法
                    listdvrdisk.Add(dVRDisk);
                }


                dVRCheckInfo.DVRDISK       = listdvrdisk;
                dVRCheckInfo.DataDiskTotal = dvrhard;

                if (dvrhard == data.HardDrive)
                {
                    dVRCheckInfo.DiskTotal = data.HardDrive;
                    dVRCheckInfo.DiskChenk = true;
                }
                else
                {
                    dVRCheckInfo.DiskTotal = data.HardDrive;
                    dVRCheckInfo.DiskChenk = false;
                }
                //在线及sn检查
                dVRCheckInfo.DataDVR_SN = dvrdata.DVR_SN;
                dVRCheckInfo.DVR_ID     = dvrdata.DVR_ID;

                if (data.DVR_SN != null)
                {
                    dVRCheckInfo.DVR_SN           = data.DVR_SN;
                    dVRCheckInfo.DVR_ChannelTotal = data.ChannelTotal;
                    dVRCheckInfo.DVR_Online       = true;
                    if (dvrdata.DVR_SN == data.DVR_SN)
                    {
                        dVRCheckInfo.SNChenk = true;
                    }
                    else
                    {
                        dVRCheckInfo.SNChenk = false;
                    }
                }
                else
                {
                    dVRCheckInfo.DVR_Online = false;
                }


                //检查通道信息
                var cameraData = _cameraAppService.GetListByDVRID(dvrdata.DVR_ID).Result;
                dVRCheckInfo.DataChannelTotal = cameraData.Count();
                List <DVRChannelInfoModel> listdVRChannelInfo = new List <DVRChannelInfoModel>();
                foreach (var tem in data.Channelname)
                {
                    DVRChannelInfoModel dVRChannelInfo = new DVRChannelInfoModel();
                    var channldata = cameraData.Where(u => u.channel_ID == tem.Number).FirstOrDefault();
                    dVRChannelInfo.DVRChannelName = tem.Name;
                    dVRChannelInfo.Channelid      = tem.Number;
                    if (channldata != null)
                    {
                        string dataName = $"{channldata.Camera_ID} {channldata.Build}-{channldata.floor} {channldata.Direction}{channldata.Location}";
                        dVRChannelInfo.DataChannelName = dataName;
                        string DVRname = tem.Name.Replace(" ", "");
                        if (dataName.Replace(" ", "") == DVRname)
                        {
                            dVRChannelInfo.ChannelNameCheck = true;
                        }
                        else
                        {
                            dVRChannelInfo.ChannelNameCheck = false;
                        }
                    }
                    else
                    {
                        dVRChannelInfo.DataChannelName  = "无";
                        dVRChannelInfo.ChannelNameCheck = true;
                    }

                    listdVRChannelInfo.Add(dVRChannelInfo);
                }


                dVRCheckInfo.DVRChannelInfo = listdVRChannelInfo;

                return(dVRCheckInfo);
            }
            else
            {
                return(null);
            }
        }
        public async Task <List <UpdateDVRChannelInfoDto> > GetDVRCheckInfoByDVR_IDAsync(string DVR_ID)
        {
            var dvrurl  = _configuration.GetSection("DVRInfourl:url").Value;
            var dvrdata = _dVRAppService.GetListByCondition(null, null, null, DVR_ID).Result.Items.FirstOrDefault();
            List <DVRCheckInfoDto> listdVRCheckInfo = new List <DVRCheckInfoDto>();

            if (dvrdata != null)
            {
                string url      = $"{dvrurl}/api/DVRInfo/Get?IP={dvrdata.DVR_IP}&name={dvrdata.DVR_usre}&password={dvrdata.DVR_possword}";
                var    handler  = new HttpClientHandler();//{ AutomaticDecompression = DecompressionMethods.GZip };
                var    response = _httpClient.GetAsync(url).Result;
                var    dt       = response.Content.ReadAsStringAsync().Result;
                var    data     = Newtonsoft.Json.JsonConvert.DeserializeObject <DVRInfoDto>(dt);
                //检查通道信息
                var cameraData = _cameraAppService.GetListByDVRID(dvrdata.DVR_ID).Result;
                List <UpdateDVRChannelInfoDto> listdVRChannelInfo = new List <UpdateDVRChannelInfoDto>();
                //检查通道信息
                foreach (var tem in data.Channelname)
                {
                    UpdateDVRChannelInfoDto dVRChannelInfo = new UpdateDVRChannelInfoDto();
                    var channldata = cameraData.Where(u => u.channel_ID == tem.Number).FirstOrDefault();
                    dVRChannelInfo.DVRChannelName = tem.Name;
                    dVRChannelInfo.channel_ID     = tem.Number;
                    dVRChannelInfo.Camera_ID      = channldata.Camera_ID;
                    dVRChannelInfo.DVR_ID         = channldata.DVR_ID;
                    if (channldata != null)
                    {
                        string dataName = $"{channldata.Camera_ID} {channldata.Build}-{channldata.floor} {channldata.Direction}{channldata.Location}";
                        dVRChannelInfo.DataChannelName = dataName;
                        string DVRname = tem.Name.Replace(" ", "");
                        if (dataName.Replace(" ", "") == DVRname)
                        {
                            dVRChannelInfo.ChannelNameCheck = true;
                        }
                        else
                        {
                            dVRChannelInfo.ChannelNameCheck = false;
                        }
                    }
                    else
                    {
                        dVRChannelInfo.DataChannelName = "无";
                    }



                    //获取设备截图并比对结果
                    //string url2 = $"{dvrurl}/api/DVRClannel/GetChannelPicture?DVR_IP={dvrdata.DVR_IP}&DVR_Name={dvrdata.DVR_usre}&DVR_PassWord={dvrdata.DVR_possword}&ChannelID={tem.Number}";

                    //var handler2 = new HttpClientHandler();//{ AutomaticDecompression = DecompressionMethods.GZip };
                    //var response2 =await _httpClient.GetStreamAsync(url2);

                    //Image image = Image.FromStream(response2);
                    //image.Save("JFDKJ.JPG");



                    listdVRChannelInfo.Add(dVRChannelInfo);
                }



                return(listdVRChannelInfo);
            }
            else
            {
                return(null);
            }
        }