// 打包XML public string Pack() { string result = string.Empty; try { StringWriter sw = new StringWriter(); XmlWriter xw = XmlWriter.Create(sw); xw.WriteProcessingInstruction("xml", "version=\"1.0\" encoding=\"GBK\""); xw.WriteStartElement("Message"); xw.WriteStartElement("Scheme"); xw.WriteAttributeString("ID", _ID); xw.WriteAttributeString("Name", _Name); xw.WriteAttributeString("Priority", _Priority); xw.WriteStartElement("Note"); xw.WriteString(_Note); xw.WriteEndElement(); xw.WriteStartElement("ActionList"); // AlarmOut xw.WriteStartElement("AlarmOut"); foreach (AlarmOutInfo tmpinfo in _AlarmOut) { xw.WriteStartElement("Action"); xw.WriteAttributeString("ID", tmpinfo.Urid); xw.WriteAttributeString("Duration", tmpinfo.Time); xw.WriteAttributeString("AlarmOutNaming", tmpinfo.Naming); xw.WriteAttributeString("Status", "0"); xw.WriteEndElement(); } xw.WriteEndElement(); // Camera xw.WriteStartElement("Recorder"); foreach (CameraInfo cinfo in _CameraInfo) { xw.WriteStartElement("Action"); xw.WriteAttributeString("ID", cinfo.Urid); xw.WriteAttributeString("Duration", cinfo.Time); xw.WriteAttributeString("CameraNaming", cinfo.Naming); xw.WriteAttributeString("PlaceToStore", "0"); xw.WriteEndElement(); } xw.WriteEndElement(); // Monitors xw.WriteStartElement("Mapping"); foreach (MonitorsInfo minfo in _Monitors) { xw.WriteStartElement("Action"); xw.WriteAttributeString("ID", minfo.Urid); xw.WriteAttributeString("Duration", minfo.Time); xw.WriteAttributeString("MonitorNaming", minfo.Naming); foreach (CameraInfo cinfo in minfo.CameraList) { xw.WriteStartElement("Camera"); xw.WriteAttributeString("Naming", ""); xw.WriteAttributeString("TimeToGo", cinfo.Time); xw.WriteAttributeString("Sequence", ""); xw.WriteEndElement(); } xw.WriteEndElement(); } xw.WriteEndElement(); // IP xw.WriteStartElement("Rooms"); foreach (IPInfo iinfo in _IPInfo) { xw.WriteStartElement("Action"); xw.WriteAttributeString("IP", iinfo.IP); xw.WriteAttributeString("Name", iinfo.Name); xw.WriteEndElement(); } xw.WriteEndElement(); // MPhone xw.WriteStartElement("SMS"); foreach (MobilePhoneInfo mpinfo in _MobilePhoneInfo) { xw.WriteStartElement("Action"); xw.WriteAttributeString("Number", mpinfo.Number); xw.WriteAttributeString("Name", mpinfo.Name); xw.WriteEndElement(); } xw.WriteEndElement(); // Email xw.WriteStartElement("Emails"); foreach (EMailInfo eminfo in _EMailInfo) { xw.WriteStartElement("Action"); xw.WriteAttributeString("Email", eminfo.EMail); xw.WriteAttributeString("Name", eminfo.Name); xw.WriteEndElement(); } xw.WriteEndElement(); xw.WriteEndElement(); xw.WriteEndElement(); xw.WriteEndElement(); xw.Close(); result = sw.ToString(); sw.Close(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return result; }