Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts this frame to a basic one with a data set
        /// </summary>
        /// <param name="data">The basic data to convert to</param>
        /// <returns>The data value</returns>
        public DataValue ConvertToBasic(byte[] data)
        {
            DataValue ret       = null;
            bool      doConvert = true;

            // If already basic, don't convert the entire frame
            if (IsBasic)
            {
                ByteArrayDataValue dv = SelectSingleNode("/Data") as ByteArrayDataValue;

                if (dv != null)
                {
                    dv.Value  = data;
                    ret       = dv;
                    doConvert = false;
                }
            }

            // Not basic or we failed
            if (doConvert)
            {
                DataKey root = new DataKey("Root");
                root.Class        = new Guid(DataNodeClasses.BINARY_NODE_CLASS);
                root.FormatString = "$Data";

                root.SetLinks(this, null);
                ret = root.AddValue("Data", data);

                Root = root;
            }

            OnModified();

            return(ret);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add an array of bytes
        /// </summary>
        /// <param name="name">The name of the value</param>
        /// <param name="data">The value itself</param>
        /// <returns>The added value object</returns>
        public DataValue AddValue(string name, byte[] data)
        {
            DataValue dataValue = new ByteArrayDataValue(name, data);

            AddSubNode(dataValue);

            return(dataValue);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Return either a single node or an empty value
        /// </summary>
        /// <param name="path">The XPath to select on</param>
        /// <returns>The first selected node, or an empty ByteArrayDataValue if not found</returns>
        public DataNode SelectSingleNodeOrEmpty(string path)
        {
            DataNode ret = SelectSingleNode(path);

            if (ret == null)
            {
                ret = new ByteArrayDataValue("Empty", new byte[0]);
            }

            return(ret);
        }
            private string FormatNode(DataNode node)
            {
                string ret;

                if (IsBasic)
                {
                    if (node is DataValue)
                    {
                        ret = String.Format("{0}={1}", node.Name, node.ToString());
                    }
                    else
                    {
                        ret = new ByteArrayDataValue("root", node.ToArray()).ToString();
                    }
                }
                else
                {
                    string value = node.ToString();

                    if (value == node.Name)
                    {
                        ret = value;
                    }
                    else
                    {
                        ret = String.Format("{0}={1}", node.Name, value);
                    }
                }

                if (ret.Length > 32)
                {
                    return ret.Substring(0, 32);
                }
                else
                {
                    return ret;
                }
            }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Add an array of bytes
        /// </summary>
        /// <param name="name">The name of the value</param>
        /// <param name="data">The value itself</param>
        /// <returns>The added value object</returns>
        public DataValue AddValue(string name, byte[] data)
        {
            DataValue dataValue = new ByteArrayDataValue(name, data);
            AddSubNode(dataValue);

            return dataValue;
        }