Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <summary>
        /// Convert the frame to a string value
        /// </summary>
        /// <param name="value">The string value</param>
        /// <param name="encoding">The encoding for the string</param>
        /// <returns>The data value</returns>
        public DataValue FromDataString(string value, Encoding encoding)
        {
            DataValue ret       = null;
            bool      doConvert = true;

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

                if (dv != null)
                {
                    dv.Value = value;
                    // Only set encoding if different
                    if (encoding != null)
                    {
                        dv.StringEncoding = encoding;
                    }
                    ret       = dv;
                    doConvert = false;
                }
            }

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

                root.SetLinks(this, null);
                ret = root.AddValue("Data", value, encoding ?? BinaryEncoding.Instance);

                Root = root;
            }

            OnModified();

            return(ret);
        }