/// <summary> /// 保存通用设备 /// </summary> private void SaveNormalDev(List <Location.TModel.Location.AreaAndDev.DevInfo> devInfoList, LocationService service) { DevInfoBackupList backUpList = new DevInfoBackupList(); backUpList.DevList = new List <DevInfoBackup>(); foreach (var item in devInfoList) { string typeCodeT = item.TypeCode.ToString(); if (TypeCodeHelper.IsLocationDev(typeCodeT) || TypeCodeHelper.IsCamera(typeCodeT) || TypeCodeHelper.IsDoorAccess(item.ModelName) || TypeCodeHelper.IsFireFightDevType(typeCodeT)) { continue; } DevInfoBackup dev = new DevInfoBackup(); dev.DevId = item.DevID; dev.KKSCode = item.KKSCode; dev.Abutment_DevID = item.Abutment_DevID; dev.ModelName = item.ModelName; dev.Name = item.Name; dev.ParentName = GetAreaPath((int)item.ParentId, service); dev.TypeCode = item.TypeCode.ToString(); DevPos pos = item.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(); backUpList.DevList.Add(dev); } List <DevInfoBackup> deleteDevs = AddDeleteDev(devInfoList); if (devInfoList != null && devInfoList.Count != 0) { backUpList.DevList.AddRange(deleteDevs); } //string dirctory = GetSaveDevDirectory(); //string initFile = dirctory+"DevInfoBackup.xml"; //XmlSerializeHelper.Save(backUpList, initFile, Encoding.UTF8); SaveNormalDevXml("DevInfoBackup.xml", backUpList); }
private void SaveNormalDevXml(string fileWithExtension, DevInfoBackupList backUpList) { //拷贝到Bin目录下 string dirctory = GetSaveDevDirectory(); string initFile = dirctory + fileWithExtension; XmlSerializeHelper.Save(backUpList, initFile, Encoding.UTF8); //直接保存到Vs目录 string vsDirctory = GetVsSaveDirctory(); if (Directory.Exists(vsDirctory)) { string vsSaveFile = vsDirctory + fileWithExtension; XmlSerializeHelper.Save(backUpList, vsSaveFile, Encoding.UTF8); } }
/// <summary> /// 通过文件导入设备信息 /// </summary> /// <param name="filePath"></param> /// <param name="devBll"></param> /// <returns></returns> public static bool ImportDevInfoFromFile(string filePath, DevInfoBll devBll) { if (!File.Exists(filePath) || devBll == null) { return(false); } DevInfoBackupList initInfo = XmlSerializeHelper.LoadFromFile <DevInfoBackupList>(filePath); foreach (var devInfo in initInfo.DevList) { if (devInfo.TypeCode == LocationDeviceHelper.LocationDevTypeCode) { continue; } AddDevInfo(devInfo, devBll); } return(true); }
/// <summary> /// 记录删除的设备(如果有设备被删除,备份时会被记录下来,TypeCode="DeleteDev",还原时这些设备不会被还原) /// 作用(当出现错误删除时,可以利用这些删除记录还原) /// </summary> /// <param name="devInfoList"></param> /// <returns></returns> private List <DevInfoBackup> AddDeleteDev(List <Location.TModel.Location.AreaAndDev.DevInfo> devInfoList) { //1.加载上一次的设备备份信息 string filePath = GetSaveDevDirectory() + "DevInfoBackup.xml"; var initInfo = XmlSerializeHelper.LoadFromFile <DevInfoBackupList>(filePath); List <DevInfoBackup> devInfos = initInfo.DevList; List <DevInfoBackup> deleteInfos = new List <DevInfoBackup>(); Dictionary <string, string> devDic = TryGetDevDic(devInfoList); if (devInfos != null) { foreach (var item in devInfos) { if (item.TypeCode == DeleteTypeCode) { continue; } //2.如果上一次备份的设备,在现在的数据库找不到。说明被删除了,记录下来。 if (!string.IsNullOrEmpty(item.DevId) && !devDic.ContainsKey(item.DevId)) { deleteInfos.Add(item); } } } string deleteInfoPath = GetSaveDevDirectory() + "DeleteInfoBackup.xml"; if (deleteInfos.Count != 0) { var deleteBackup = XmlSerializeHelper.LoadFromFile <DevInfoBackupList>(filePath); if (deleteBackup == null) { deleteBackup = new DevInfoBackupList(); deleteBackup.DevList = new List <DevInfoBackup>(); } deleteBackup.DevList.AddRange(deleteInfos); XmlSerializeHelper.Save(deleteBackup, deleteInfoPath, Encoding.UTF8); foreach (var item in deleteInfos) { item.TypeCode = DeleteTypeCode; } } return(deleteInfos); }
/// <summary> /// 保存通用设备 /// </summary> private void SaveNormalDev(List <Location.TModel.Location.AreaAndDev.DevInfo> devInfoList, LocationService service) { DevInfoBackupList backUpList = new DevInfoBackupList(); backUpList.DevList = new List <DevInfoBackup>(); foreach (var item in devInfoList) { string typeCodeT = item.TypeCode.ToString(); if (TypeCodeHelper.IsLocationDev(typeCodeT) || TypeCodeHelper.IsCamera(typeCodeT) || TypeCodeHelper.IsDoorAccess(item.ModelName)) { continue; } DevInfoBackup dev = new DevInfoBackup(); dev.DevId = item.DevID; dev.KKSCode = item.KKSCode; dev.ModelName = item.ModelName; dev.Name = item.Name; dev.ParentName = GetAreaPath((int)item.ParentId, service); dev.TypeCode = item.TypeCode.ToString(); DevPos pos = item.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(); backUpList.DevList.Add(dev); } string initFile = AppDomain.CurrentDomain.BaseDirectory + "Data\\设备信息\\DevInfoBackup.xml"; XmlSerializeHelper.Save(backUpList, initFile, Encoding.UTF8); }