/// <summary> /// Copies the packet from this <see cref="Miner.Interop.Process.IPxNode" /> to the specified <paramref name="node" /> /// object. /// </summary> /// <param name="packetPrefix">The packet ID prefix.</param> /// <param name="node">The node.</param> /// <exception cref="System.ArgumentNullException">node</exception> protected virtual void CopyPacket(string packetPrefix, IPxNode node) { if (node == null) { throw new ArgumentNullException("node"); } // When the entity is not a mobile node we can stop here. IMMPxMobileHelper helper = (IMMPxMobileHelper)_PxApp; if (!helper.IsMobileSide(false)) { return; } // When the original packet doesn't exist exit out. string fileName = helper.GetPacketPath(this.Node, true); if (!File.Exists(fileName)) { return; } // Create a new packet for the clone. string packetID = string.Format(CultureInfo.InvariantCulture, "{1}_{0}", Regex.Replace(Guid.NewGuid().ToString(), "{|}", ""), packetPrefix); string clonePacket = helper.CreatePacket(node.Node, true, ref packetID); // Load the original packet into the cloned packet. XmlDocument cloneDoc = new XmlDocument(); cloneDoc.Load(fileName); // Update the node data. XmlNode element = cloneDoc.SelectSingleNode("/XML_PACKET/PACKET_ADAPTER/NODE_DATA"); if (element != null) { if (element.Attributes != null) { element.Attributes["NODE_ID"].Value = node.Node.Id.ToString(CultureInfo.InvariantCulture); } } // Save the modified packet. cloneDoc.Save(clonePacket); }
/// <summary> /// Copies the history from this <see cref="Miner.Interop.Process.IPxNode" /> to the specified <paramref name="node" /> /// object. /// </summary> /// <param name="node">The node.</param> protected virtual void CopyHistory(IPxNode node) { if (this.History == null || node == null) { return; } this.History.Reset(); IMMPxHistory history; while ((history = this.History.Next()) != null) { var copy = history.Copy(); copy.NodeId = node.Node.Id; copy.nodeTypeId = node.Node.NodeType; node.History.Add(copy); } // Add another record for the clone to record the clone operation. node.AddHistory(string.Format(CultureInfo.CurrentCulture, "{0} copied from {0} " + this.ID + ".", _NodeTypeName, _NodeTypeName.ToLower(CultureInfo.CurrentCulture)), ""); }