示例#1
0
        /// <summary>
        /// Replace a node in the subnodes with a new binary version
        /// </summary>
        /// <param name="oldNode">The old node to replace</param>
        /// <param name="newNode">The new node as a binary string</param>
        /// <returns>The new data value</returns>
        internal DataValue ReplaceNode(DataNode oldNode, byte[] newNode)
        {
            DataValue ret = null;

            if (oldNode is ByteArrayDataValue)
            {
                // We can replace the contents without having to do anything too clever
                ret       = oldNode as DataValue;
                ret.Value = newNode;

                OnModified();
            }
            else
            {
                int idx = IndexOfSubNode(oldNode);

                if (idx >= 0)
                {
                    ret = new ByteArrayDataValue(oldNode.Name, newNode);
                    ret.SetLinks(_frame, this);
                    oldNode.SetLinks(null, null);
                    _subNodes[idx] = ret;
                    OnModified();
                }
            }

            return(ret);
        }
示例#2
0
        /// <summary>
        /// Replace the a node in the subnodes with a new string version
        /// </summary>
        /// <param name="oldNode">The old node to replace</param>
        /// <param name="newNode">The new node as a string</param>
        /// <param name="encoding">The string encoding</param>
        /// <returns>The new data value</returns>
        internal DataValue ReplaceNode(DataNode oldNode, string newNode, Encoding encoding)
        {
            StringDataValue ret = oldNode as StringDataValue;

            if (ret != null)
            {
                // We can replace the contents without having to do anything too clever
                ret.Value          = newNode;
                ret.StringEncoding = encoding;

                OnModified();
            }
            else
            {
                int idx = IndexOfSubNode(oldNode);

                if (idx >= 0)
                {
                    ret = new StringDataValue(oldNode.Name, newNode, encoding);
                    ret.SetLinks(_frame, this);
                    oldNode.SetLinks(null, null);
                    _subNodes[idx] = ret;
                    OnModified();
                }
                else
                {
                    throw new ArgumentException(CANAPE.Properties.Resources.DataKey_InvalidChildNode);
                }
            }

            return(ret);
        }
示例#3
0
        /// <summary>
        /// Remove the specified node
        /// </summary>
        /// <param name="node">The node to remove</param>
        internal void RemoveNode(DataNode node)
        {
            node.SetLinks(null, null);
            int index = IndexOfSubNode(node);

            if (index >= 0)
            {
                _subNodes.RemoveAt(index);
                OnModified();
            }
        }
示例#4
0
        /// <summary>
        /// This method can be overriden by a deriving class to customise how data is stored
        /// in the key
        /// </summary>
        /// <param name="node"></param>
        public virtual void AddSubNode(DataNode node)
        {
            if (node != null)
            {
                if (node.Frame != null)
                {
                    throw new InvalidOperationException(CANAPE.Properties.Resources.DataKey_AddSubNodeException);
                }

                node.SetLinks(_frame, this);
                _subNodes.Add(node);
                OnModified();
            }
        }
示例#5
0
        /// <summary>
        /// Clone the node and any contained subnodes
        /// </summary>
        /// <returns>THe cloned node detached from the frame</returns>
        public DataNode CloneNode()
        {
            BinaryFormatter fmt = new BinaryFormatter();
            MemoryStream    stm = new MemoryStream();

            fmt.Serialize(stm, this);
            stm.Position = 0;

            // This will actually serialize the entire frame, no matter.
            DataNode ret = (DataNode)fmt.Deserialize(stm);

            // Disconnect from the tree
            ret.SetLinks(null, null);

            return(ret);
        }
示例#6
0
        /// <summary>
        /// Replace the a node in the subnodes with a new one
        /// </summary>
        /// <param name="oldNode">The old node to replace</param>
        /// <param name="newNode">The new node</param>
        internal void ReplaceNode(DataNode oldNode, DataNode newNode)
        {
            // Don't replace the node if it happens to be exactly the same
            if (!Object.ReferenceEquals(oldNode, newNode))
            {
                int idx = IndexOfSubNode(oldNode);

                if (idx >= 0)
                {
                    newNode.SetLinks(_frame, this);
                    oldNode.SetLinks(null, null);
                    _subNodes[idx] = newNode;
                    OnModified();
                }
                else
                {
                    throw new ArgumentException(CANAPE.Properties.Resources.DataKey_InvalidChildNode);
                }
            }
        }