/// <summary> /// 反序列化站点数据xml /// </summary> public List <CEntityStation> Deserialize() { try { //return new List<CEntityRealTime>(); CEntityStationCollection result = null; if (Directory.Exists(m_path)) { System.Diagnostics.Debug.WriteLine(string.Format("找到文件, 文件名:\"{0}\"", m_path)); } using (Stream fileStream = new FileStream(m_path, FileMode.Open, FileAccess.Read)) { XmlSerializer serializer = new XmlSerializer(typeof(CEntityStationCollection)); result = (CEntityStationCollection)serializer.Deserialize(fileStream); } if (result != null) { System.Diagnostics.Debug.WriteLine(string.Format("读取站点数据表完成, 文件名:\"{0}\"", m_path)); return(result.Items); } } catch (Exception exp) { System.Diagnostics.Debug.WriteLine(string.Format("读取站点数据表异常, 文件名:\"{0}\"\r\n{1}", m_path, exp.ToString())); } return(null); }
private CDictionary <string, string> m_mapStationgprsID; //站点ID与gprsID /// <summary> /// 序列化站点数据xml /// </summary> public void Serialize(List <CEntityStation> lists) { try { //return; // 判断Config文件夹是否存在 if (!Directory.Exists("Config")) { // 创建文件夹 Directory.CreateDirectory("Config"); } var infos = new CEntityStationCollection() { Items = lists }; using (Stream fileStream = new FileStream(m_path, FileMode.Create, FileAccess.ReadWrite)) { XmlSerializer serializer = new XmlSerializer(typeof(CEntityStationCollection)); serializer.Serialize(fileStream, infos); } System.Diagnostics.Debug.WriteLine(string.Format("写入站点数据表完成, 文件名:\"{0}\"", m_path)); } catch (Exception exp) { System.Diagnostics.Debug.WriteLine(string.Format("写入站点数据表异常, 文件名:\"{0}\"\r\n{1}", m_path, exp.ToString())); } }