/// <summary> /// 添加摄像头信息 /// </summary> /// <param name="cameraDev"></param> /// <param name="bll"></param> private static void AddCameraInfo(CameraInfoBackup cameraDev, Bll bll) { try { DevInfoBackup dev = CameraToDevInfo(cameraDev); DevInfo devInfo = GetDevInfo(dev); DevPos devPos = GetDevPos(dev); devInfo.SetPos(devPos); DevInfo infoTemp = bll.DevInfos.Find(i => i.Local_DevID == devInfo.Local_DevID); //Devinfo中,能通过Devid找到的就更新。找不到就新增 if (infoTemp == null) { bll.DevInfos.Add(devInfo); Dev_CameraInfo cameraBackup = GetCameraInfo(cameraDev, devInfo); cameraBackup.RtspUrl = cameraDev.RtspURL; bll.Dev_CameraInfos.Add(cameraBackup); } else { UpgradeDevInfo(infoTemp, devInfo); bool value = bll.DevInfos.Edit(infoTemp); if (!value) { Log.Info("Error: EditDevinfo Error"); } Dev_CameraInfo cameraBackup = GetCameraInfo(cameraDev, infoTemp); if (!string.IsNullOrEmpty(cameraDev.RtspURL)) { cameraBackup.RtspUrl = cameraDev.RtspURL; } Dev_CameraInfo cameraDatabase = bll.Dev_CameraInfos.Find(cameraT => cameraT.Local_DevID == infoTemp.Local_DevID); if (cameraDatabase == null) { bll.Dev_CameraInfos.Add(cameraBackup); } else { UpgradeCameraInfo(cameraBackup, cameraDatabase); bool valueT = bll.Dev_CameraInfos.Edit(cameraDatabase); if (!valueT) { Log.Info("Error: EditDevinfo Error"); } } } } catch (Exception e) { Log.Info("Error in DevInfoHelper.AddDevInfo:" + e.ToString()); } }
/// <summary> /// 获取摄像头数据 /// </summary> /// <param name="camDev"></param> /// <param name="dev"></param> /// <returns></returns> private static Dev_CameraInfo GetCameraInfo(CameraInfoBackup camDev, DevInfo dev) { Dev_CameraInfo info = new Dev_CameraInfo(); info.Ip = camDev.IP; info.UserName = camDev.UserName; info.PassWord = camDev.PassWord; info.CameraIndex = TryParseInt(camDev.CameraIndex); info.Port = TryParseInt(camDev.Port); info.DevInfoId = dev.Id; info.ParentId = dev.ParentId; info.Local_DevID = dev.Local_DevID; return(info); }
/// <summary> /// 保存设备信息至Xml文件 /// </summary> private void SaveCameraInfoToXml(List <TModel.Location.AreaAndDev.Dev_CameraInfo> cameraList, LocationService service) { CameraInfoBackUpList backUpList = new CameraInfoBackUpList(); backUpList.DevList = new List <CameraInfoBackup>(); foreach (var item in cameraList) { if (item.DevInfo == null) { continue; } CameraInfoBackup dev = new CameraInfoBackup(); dev.DevId = item.DevInfo.DevID; dev.KKSCode = item.DevInfo.KKSCode; dev.Abutment_DevID = item.DevInfo.Abutment_DevID; dev.ModelName = item.DevInfo.ModelName; dev.Name = item.DevInfo.Name; dev.ParentName = GetAreaPath((int)item.ParentId, service); dev.TypeCode = item.DevInfo.TypeCode.ToString(); DevPos pos = item.DevInfo.Pos; dev.RotationX = pos.RotationX.ToString(); dev.RotationY = pos.RotationY.ToString(); dev.RotationZ = pos.RotationZ.ToString(); dev.XPos = pos.PosX.ToString(); dev.YPos = pos.PosY.ToString(); dev.ZPos = pos.PosZ.ToString(); dev.ScaleX = pos.ScaleX.ToString(); dev.ScaleY = pos.ScaleY.ToString(); dev.ScaleZ = pos.ScaleZ.ToString(); dev.IP = item.Ip; dev.UserName = item.UserName; dev.PassWord = item.PassWord; dev.CameraIndex = item.CameraIndex.ToString(); dev.Port = item.Port.ToString(); dev.RtspURL = item.RtspUrl; backUpList.DevList.Add(dev); } //string initFile = GetSaveDevDirectory()+"CameraInfoBackup.xml"; //XmlSerializeHelper.Save(backUpList, initFile, Encoding.UTF8); SaveCameraDevXml("CameraInfoBackup.xml", backUpList); }
/// <summary> /// 添加摄像头信息 /// </summary> /// <param name="cameraDev"></param> /// <param name="bll"></param> private static void AddCameraInfo(CameraInfoBackup cameraDev, Bll bll) { try { DevInfoBackup dev = CameraToDevInfo(cameraDev); DevInfo devInfo = GetDevInfo(dev); DevPos devPos = GetDevPos(dev); devInfo.SetPos(devPos); bll.DevInfos.Add(devInfo); Dev_CameraInfo camera = GetCameraInfo(cameraDev, devInfo); bll.Dev_CameraInfos.Add(camera); } catch (Exception e) { Console.WriteLine("Error in DevInfoHelper.AddDevInfo:" + e.ToString()); } }
/// <summary> /// 摄像头转设备信息(相同部分) /// </summary> /// <param name="camera"></param> /// <returns></returns> private static DevInfoBackup CameraToDevInfo(CameraInfoBackup camera) { DevInfoBackup dev = new DevInfoBackup(); dev.DevId = camera.DevId; dev.TypeCode = camera.TypeCode; dev.Name = camera.Name; dev.ParentName = camera.ParentName; dev.ParentId = camera.ParentId; dev.ModelName = camera.ModelName; dev.KKSCode = camera.KKSCode; dev.XPos = camera.XPos; dev.YPos = camera.YPos; dev.ZPos = camera.ZPos; dev.RotationX = camera.RotationX; dev.RotationY = camera.RotationY; dev.RotationZ = camera.RotationZ; dev.ScaleX = camera.ScaleX; dev.ScaleY = camera.ScaleY; dev.ScaleZ = camera.ScaleZ; return(dev); }