protected override LTSModel CreateModel(string declare, List<LTSCanvas> canvas) { WSNModel model = new WSNModel(mExtendInfo, declare, canvas); return model; }
/// <summary> /// Load model from XML string /// </summary> /// <param name="xml"></param> /// <param name="PNDocRes"></param> /// <returns></returns> public static WSNModel LoadModelFromXML(string xml, XmlDocument PNDocRes) { WSNModel model = new WSNModel(); do { XmlDocument doc = new XmlDocument(); try { doc.LoadXml(xml); } catch { } XmlNodeList nodes = null; do { nodes = doc.GetElementsByTagName(XmlTag.TAG_DECLARATION); if (nodes == null || nodes.Count != 1) { break; } model.Declaration = nodes.Item(0).InnerText; } while (false); do { nodes = doc.GetElementsByTagName(XmlTag.TAG_NETWORK); if (nodes == null) { break; } // mlqvu -- load attributes for network tag XmlNode firstNetworkNode = nodes[0]; if (firstNetworkNode == null) { break; } if (model.mExtendInfo == null) { model.mExtendInfo = new WSNExtendInfo(); } try { String noID = firstNetworkNode.Attributes[XmlTag.ATTR_mID].Value; model.mExtendInfo.mID = long.Parse(noID); String noPacket = firstNetworkNode.Attributes[XmlTag.ATTR_NUMOFPACKETS].Value; model.mExtendInfo.mNumberPacket = Int32.Parse(noPacket); String noSensor = firstNetworkNode.Attributes[XmlTag.ATTR_NUMOFSENSORS].Value; model.mExtendInfo.mNumberSensor = Int32.Parse(noSensor); String maxSensorBufferSize = firstNetworkNode.Attributes[XmlTag.ATTR_SENSOR_MAX_BUFFER_SIZE].Value; model.mExtendInfo.mSensorMaxBufferSize = Int32.Parse(maxSensorBufferSize); String maxSensorQueueSize = firstNetworkNode.Attributes[XmlTag.ATTR_SENSOR_MAX_QUEUE_SIZE].Value; model.mExtendInfo.mSensorMaxQueueSize = Int32.Parse(maxSensorQueueSize); String maxChannelBufferSize = firstNetworkNode.Attributes[XmlTag.ATTR_CHANNEL_MAX_BUFFER_SIZE].Value; model.mExtendInfo.mChannelMaxBufferSize = Int32.Parse(maxChannelBufferSize); } catch (Exception e) { } LTSCanvas canvas = null; foreach (XmlElement node in nodes[0].ChildNodes) { canvas = new WSNCanvas(node.GetAttribute(XmlTag.ATTR_NAME)); canvas.LoadFromXml(node); model.Processes.Add(canvas); } } while (false); } while (false); return(model); }
/// <summary> /// Load model from XML string /// </summary> /// <param name="xml"></param> /// <param name="PNDocRes"></param> /// <returns></returns> public static WSNModel LoadModelFromXML(string xml, XmlDocument PNDocRes) { WSNModel model = new WSNModel(); do { XmlDocument doc = new XmlDocument(); try { doc.LoadXml(xml); } catch { } XmlNodeList nodes = null; do { nodes = doc.GetElementsByTagName(XmlTag.TAG_DECLARATION); if (nodes == null || nodes.Count != 1) break; model.Declaration = nodes.Item(0).InnerText; } while (false); do { nodes = doc.GetElementsByTagName(XmlTag.TAG_NETWORK); if (nodes == null) break; // mlqvu -- load attributes for network tag XmlNode firstNetworkNode = nodes[0]; if (firstNetworkNode == null) break; if (model.mExtendInfo == null) model.mExtendInfo = new WSNExtendInfo(); try { String noID = firstNetworkNode.Attributes[XmlTag.ATTR_mID].Value; model.mExtendInfo.mID = long.Parse(noID); String noPacket = firstNetworkNode.Attributes[XmlTag.ATTR_NUMOFPACKETS].Value; model.mExtendInfo.mNumberPacket = Int32.Parse(noPacket); String noSensor = firstNetworkNode.Attributes[XmlTag.ATTR_NUMOFSENSORS].Value; model.mExtendInfo.mNumberSensor = Int32.Parse(noSensor); String maxSensorBufferSize = firstNetworkNode.Attributes[XmlTag.ATTR_SENSOR_MAX_BUFFER_SIZE].Value; model.mExtendInfo.mSensorMaxBufferSize = Int32.Parse(maxSensorBufferSize); String maxSensorQueueSize = firstNetworkNode.Attributes[XmlTag.ATTR_SENSOR_MAX_QUEUE_SIZE].Value; model.mExtendInfo.mSensorMaxQueueSize = Int32.Parse(maxSensorQueueSize); String maxChannelBufferSize = firstNetworkNode.Attributes[XmlTag.ATTR_CHANNEL_MAX_BUFFER_SIZE].Value; model.mExtendInfo.mChannelMaxBufferSize = Int32.Parse(maxChannelBufferSize); } catch (Exception e) { } LTSCanvas canvas = null; foreach (XmlElement node in nodes[0].ChildNodes) { canvas = new WSNCanvas(node.GetAttribute(XmlTag.ATTR_NAME)); canvas.LoadFromXml(node); model.Processes.Add(canvas); } } while (false); } while (false); return model; }