public WSNCanvas Duplicate() { WSNCanvas duplicate = new WSNCanvas(); duplicate.LoadFromXml(this.Clone()); duplicate.Node.Text = this.Node.Text + "-Copy"; bool nameExist = true; while (nameExist) { nameExist = false; foreach (TreeNode node in this.Node.Parent.Nodes) { if (node.Text.Equals(duplicate.Node.Text, StringComparison.CurrentCultureIgnoreCase)) { duplicate.Node.Text = duplicate.Node.Text + "-Copy"; nameExist = true; break; } } } return(duplicate); }
public WSNCanvas Duplicate() { WSNCanvas duplicate = new WSNCanvas(); duplicate.LoadFromXml(this.Clone()); duplicate.Node.Text = this.Node.Text + "-Copy"; bool nameExist = true; while (nameExist) { nameExist = false; foreach (TreeNode node in this.Node.Parent.Nodes) { if (node.Text.Equals(duplicate.Node.Text, StringComparison.CurrentCultureIgnoreCase)) { duplicate.Node.Text = duplicate.Node.Text + "-Copy"; nameExist = true; break; } } } return duplicate; }
/// <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); }
public PNGenerationHelper buildHelperAfterCluster(String newFileName) { PNGenerationHelper helper = null; do { if (CurrentActiveTab is WSNTabItem) { helper = new PNGenerationHelper(newFileName, CurrentActiveTab); break; } if ((CurrentActiveTab is PNTabItem) == false) break; XmlDocument pnDoc = new XmlDocument(); try { pnDoc.Load(CurrentActiveTab.FileName); } catch { MessageBox.Show("Error when reading PN file!"); } IList<WSNCanvas> listCanvas = new List<WSNCanvas>(); KWSNGenerationHelper tempHelper = new KWSNGenerationHelper(newFileName, CurrentActiveTab); XmlDocument doc = tempHelper.GenerateXML(); XmlElement wsnNode = doc.ChildNodes[0] as XmlElement; XmlElement networkNode = wsnNode.GetElementsByTagName(XmlTag.TAG_NETWORK)[0] as XmlElement; foreach (XmlElement process in networkNode.ChildNodes) { WSNCanvas kCanvas = new WSNCanvas(process.GetAttribute(XmlTag.ATTR_NAME)); kCanvas.LoadFromXml(process); listCanvas.Add(kCanvas); } helper = new PNGenerationHelper(newFileName, CurrentActiveTab); } while (false); return helper; }
/// <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; }