private void SaveArchorInfoToXml(List <TModel.Location.AreaAndDev.Archor> archorList, LocationService service) { LocationDeviceList backUpList = new LocationDeviceList(); backUpList.DepList = new List <LocationDevices>(); foreach (var item in archorList) { if (item.DevInfo == null) { continue; } Area area = service.GetAreaById(item.ParentId); if (area == null) { Log.Info(string.Format("Error: Dev {0} area not find...", item.DevInfo.Id)); continue; } LocationDevices areaList = backUpList.DepList.Find(i => i.Name == area.Name); if (areaList == null) { areaList = new LocationDevices(); areaList.Name = area.Name; areaList.DevList = new List <LocationDevice>(); backUpList.DepList.Add(areaList); } if (areaList.DevList == null) { areaList.DevList = new List <LocationDevice>(); } LocationDevice dev = new LocationDevice(); dev.Name = item.Name; dev.Abutment_DevID = item.DevInfo.Abutment_DevID; dev.AnchorId = item.Code; dev.IP = item.Ip; dev.AbsolutePosX = item.X.ToString("f2"); dev.AbsolutePosY = item.Y.ToString("f2"); dev.AbsolutePosZ = item.Z.ToString("f2"); DevPos pos = item.DevInfo.Pos; if (pos != null) { dev.XPos = pos.PosX.ToString("f2"); dev.YPos = pos.PosY.ToString("f2"); dev.ZPos = pos.PosZ.ToString("f2"); } else { Log.Info("Error: dev.pos is null->" + item.DevInfo.Id); } areaList.DevList.Add(dev); } //string initFile = GetSaveDevDirectory() + "基站信息.xml"; //XmlSerializeHelper.Save(backUpList, initFile, Encoding.UTF8); SaveArchorDevXml("基站信息.xml", backUpList); }
private void MenuExportArchorData_Click(object sender, RoutedEventArgs e) { LocationDeviceList list = new LocationDeviceList(); list.DepList = new List <LocationDevices>(); Dictionary <int, List <Archor> > dict = new Dictionary <int, List <Archor> >(); Bll bll = new Bll(); var archorList = bll.Archors.ToList(); foreach (var item in archorList) { int pId = (int)item.ParentId; if (!dict.ContainsKey(pId)) { dict[pId] = new List <Archor>(); } dict[pId].Add(item); } foreach (var item in dict.Keys) { var area = bll.Areas.Find(item); var archors = dict[item]; LocationDevices devs = new LocationDevices(); devs.DevList = new List <LocationDevice>(); devs.Name = area.Name; list.DepList.Add(devs); foreach (var archor in archors) { var dev = new LocationDevice(); dev.AbsolutePosX = archor.X.ToString(); dev.AbsolutePosY = archor.Y.ToString(); dev.AbsolutePosZ = archor.Z.ToString(); dev.AnchorId = archor.Code; dev.IP = archor.Ip; dev.Name = archor.Name; dev.XPos = archor.DevInfo.PosX.ToString(); dev.YPos = archor.DevInfo.PosY.ToString(); dev.ZPos = archor.DevInfo.PosZ.ToString(); devs.DevList.Add(dev); } } string basePath = AppDomain.CurrentDomain.BaseDirectory; string filePath = basePath + "Data\\基站信息\\基站信息.xml"; XmlSerializeHelper.Save(list, filePath); FileInfo fi = new FileInfo(filePath); Process.Start(fi.Directory.FullName); }
private void SaveArchorDevXml(string fileWithExtension, LocationDeviceList 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="devBlls"></param> /// <param name="topoTree"></param> /// <returns></returns> public static bool ImportLocationDeviceFromFile(string filePath, ArchorBll archorBll, PhysicalTopologyBll topoTree) { if (!File.Exists(filePath) || archorBll == null || topoTree == null) { return(false); } LocationDeviceList initInfo = XmlSerializeHelper.LoadFromFile <LocationDeviceList>(filePath); foreach (var devArea in initInfo.DepList) { PhysicalTopology topo = topoTree.FindByName(devArea.Name); if (topo == null) { continue; } AddLocationDev(devArea.DevList, archorBll, topo.Id); } return(true); }