Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add a string with a specific encoding
        /// </summary>
        /// <param name="name">The name of the value</param>
        /// <param name="value">The value itself</param>
        /// <param name="encoding">String encoding type to use</param>
        /// <returns>The added value object</returns>
        public DataValue AddValue(string name, string value, Encoding encoding)
        {
            DataValue dataValue = new StringDataValue(name, value, encoding);

            AddSubNode(dataValue);

            return(dataValue);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add a string with a specific named encoding
        /// </summary>
        /// <param name="name">The name of the value</param>
        /// <param name="value">The value itself</param>
        /// <param name="encoding">The encoding name (e.g. UTF-8)</param>
        /// <returns>The added value object</returns>
        public DataValue AddValue(string name, string value, string encoding)
        {
            Encoding enc = Encoding.GetEncoding(encoding);

            if (enc == null)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, CANAPE.Properties.Resources.DataKey_AddValueInvalidEncoding, encoding));
            }

            DataValue dataValue = new StringDataValue(name, value, enc);

            AddSubNode(dataValue);

            return(dataValue);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        protected override object GetValue(LogPacket p)
        {
            DataNode node = p.Frame.Root.SelectSingleNode(SelectionPath);

            if (node == null)
            {
                node = new StringDataValue("", "");
            }

            if (FormatExpression.IsValid)
            {
                ExpressionResolver _resolver = new ExpressionResolver(typeof(LogPacket));
                Dictionary<string, object> extras = new Dictionary<string,object>();
                extras["value"] = node;

                try
                {
                    return _resolver.Resolve(p, _formatExpression, extras) ?? String.Empty;
                }
                catch (Exception)
                {
                    return String.Empty;
                }
            }
            else
            {
                return RawValue ? node.Value : node;
            }
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Add a string with a specific named encoding 
        /// </summary>
        /// <param name="name">The name of the value</param>
        /// <param name="value">The value itself</param>
        /// <param name="encoding">The encoding name (e.g. UTF-8)</param>
        /// <returns>The added value object</returns>
        public DataValue AddValue(string name, string value, string encoding)
        {
            Encoding enc = Encoding.GetEncoding(encoding);
            if (enc == null)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, CANAPE.Properties.Resources.DataKey_AddValueInvalidEncoding, encoding));
            }

            DataValue dataValue = new StringDataValue(name, value, enc);

            AddSubNode(dataValue);

            return dataValue;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Add a string with a specific encoding
        /// </summary>
        /// <param name="name">The name of the value</param>
        /// <param name="value">The value itself</param>
        /// <param name="encoding">String encoding type to use</param>
        /// <returns>The added value object</returns>
        public DataValue AddValue(string name, string value, Encoding encoding)
        {
            DataValue dataValue = new StringDataValue(name, value, encoding);

            AddSubNode(dataValue);

            return dataValue;
        }