/// <summary> /// Load XML commands from the file. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="settings">Additional settings.</param> /// <returns></returns> public List <GXDLMSXmlPdu> Load(string fileName, GXXmlLoadSettings settings) { XmlDocument doc = new XmlDocument(); doc.Load(fileName); return(Load(doc, settings)); }
/// <summary> /// Load XML commands from xml string. /// </summary> /// <param name="xml"></param> /// <returns></returns> public List <GXDLMSXmlPdu> LoadXml(string xml, GXXmlLoadSettings settings) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); return(Load(doc, settings)); }
/// <summary> /// Load XML commands from the file. /// </summary> /// <param name="stream">Stream.</param> /// <returns></returns> public List <GXDLMSXmlPdu> Load(StreamReader stream, GXXmlLoadSettings settings) { XmlDocument doc = new XmlDocument(); doc.Load(stream); return(Load(doc, settings)); }
private List <GXDLMSXmlPdu> Load(XmlDocument doc, GXXmlLoadSettings settings) { //Remove comments. List <XmlNode> comments = new List <XmlNode>(); foreach (XmlNode node in doc.SelectNodes("//comment()")) { comments.Add(node); } foreach (XmlNode node in comments) { node.ParentNode.RemoveChild(node); } List <GXDLMSXmlPdu> actions = new List <GXDLMSXmlPdu>(); string description = null, error = null, errorUrl = null, sleep = null; foreach (XmlNode m1 in doc.ChildNodes) { if (m1.NodeType == XmlNodeType.Element) { if (m1.Name == "AssociationRequest") { GXDLMSXmlSettings s = new GXDLMSXmlSettings(translator.OutputType, translator.Hex, translator.ShowStringAsHex, translator.tagsByName); s.settings.ClientAddress = Settings.ClientAddress; s.settings.ServerAddress = Settings.ServerAddress; ((GXCiphering)s.settings.Cipher).TestMode = this.Ciphering.TestMode; byte[] reply = translator.XmlToPdu(m1.OuterXml, s); GXDLMSXmlPdu p = new GXDLMSXmlPdu(s.command, m1, reply); actions.Add(p); return(actions); } foreach (XmlNode node in m1.ChildNodes) { if (node.NodeType == XmlNodeType.Element) { if (node.Name == "Description") { description = node.Value; continue; } if (node.Name == "Error") { error = node.Value; continue; } if (node.Name == "ErrorUrl") { errorUrl = node.Value; continue; } if (node.Name == "Sleep") { sleep = node.Value; continue; } if (settings != null && node.Name == "GetRequest") { if (settings.Start != DateTime.MinValue && settings.End != DateTime.MinValue) { foreach (XmlNode n1 in node.ChildNodes) { if (n1.Name == "GetRequestNormal") { foreach (XmlNode n2 in n1.ChildNodes) { if (n2.Name == "AccessSelection") { foreach (XmlNode n3 in n2.ChildNodes) { if (n3.Name == "AccessSelector") { if (n3.Attributes["Value"].Value != "1") { break; } } else if (n3.Name == "AccessParameters") { foreach (XmlNode n4 in n3.ChildNodes) { if (n4.Name == "Structure") { bool start = true; foreach (XmlNode n5 in n4.ChildNodes) { if (n5.Name == "OctetString") { if (start) { GXByteBuffer bb = new GXByteBuffer(); GXCommon.SetData(this.Settings, bb, DataType.OctetString, settings.Start); n5.Attributes["Value"].Value = bb.ToHex(false, 2); start = false; } else { GXByteBuffer bb = new GXByteBuffer(); GXCommon.SetData(this.Settings, bb, DataType.OctetString, settings.End); n5.Attributes["Value"].Value = bb.ToHex(false, 2); break; } } } } break; } break; } } break; } } break; } } } } GXDLMSXmlSettings s = new GXDLMSXmlSettings(translator.OutputType, translator.ShowStringAsHex, translator.Hex, translator.tagsByName);; s.settings.ClientAddress = Settings.ClientAddress; s.settings.ServerAddress = Settings.ServerAddress; byte[] reply = translator.XmlToPdu(node.OuterXml, s); if (s.command == Command.Snrm && !s.settings.IsServer) { Settings.Limits.MaxInfoTX = s.settings.Limits.MaxInfoTX; Settings.Limits.MaxInfoRX = s.settings.Limits.MaxInfoRX; Settings.Limits.WindowSizeRX = s.settings.Limits.WindowSizeRX; Settings.Limits.WindowSizeTX = s.settings.Limits.WindowSizeTX; } else if (s.command == Command.Ua && s.settings.IsServer) { Settings.Limits.MaxInfoTX = s.settings.Limits.MaxInfoTX; Settings.Limits.MaxInfoRX = s.settings.Limits.MaxInfoRX; Settings.Limits.WindowSizeRX = s.settings.Limits.WindowSizeRX; Settings.Limits.WindowSizeTX = s.settings.Limits.WindowSizeTX; } if (s.template) { reply = null; } GXDLMSXmlPdu p = new GXDLMSXmlPdu(s.command, node, reply); if (description != "") { p.Description = description; } if (error != "") { p.Error = error; } if (errorUrl != "") { p.ErrorUrl = errorUrl; } if (!string.IsNullOrEmpty(sleep)) { p.Sleep = int.Parse(sleep); } actions.Add(p); } } } } return(actions); }