Exemplo n.º 1
0
        private void binaryDataEditorControl_DataChanged(object sender, EventArgs e)
        {
            if (_node != null)
            {
                ByteArrayDataValue byteArray = _node as ByteArrayDataValue;

                if (byteArray != null)
                {
                    byteArray.Value = binaryDataEditorControl.Data;
                }
                else
                {
                    _node = _node.ReplaceNode(binaryDataEditorControl.Data);
                }
            }
        }
Exemplo n.º 2
0
        private void SetupFrame()
        {
            if (_node != null)
            {
                binaryDataEditorControl.PacketColor = _color;
                ByteArrayDataValue byteArray = _node as ByteArrayDataValue;

                if (byteArray != null)
                {
                    binaryDataEditorControl.Data = (byte[])byteArray.Value;
                }
                else
                {
                    binaryDataEditorControl.Data = _node.ToArray();
                }

                binaryDataEditorControl.ReadOnly = _readOnly;
            }
        }
Exemplo n.º 3
0
            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.º 4
0
        private static DataNode GetNode(string name, object o, Dictionary <Type, Guid> derivedTypes, bool readOnly)
        {
            DataNode ret = null;

            if (o != null)
            {
                Type t = o.GetType();

                if (o is DataNode)
                {
                    ret = ((DataNode)o).CloneNode();
                }
                else if (t.IsEnum)
                {
                    ret = new EnumDataValue(name, (Enum)o);
                }
                else if (t.IsPrimitive)
                {
                    ret = GetPrimitiveType(name, t, o);
                }
                else if (o is IPrimitiveValue)
                {
                    object v = ((IPrimitiveValue)o).Value;

                    ret = GetPrimitiveType(name, v.GetType(), v);
                }
                else if (t == typeof(DateTime))
                {
                    // Use a unix datetime, doesn't _really_ matter
                    ret = new UnixDateTimeDataValue(name, false, (DateTime)o);
                }
                else if (t == typeof(string))
                {
                    ret = new StringDataValue(name, (string)o);
                }
                else if (t == typeof(BigInteger))
                {
                    ret = new BigIntegerDataValue(name, (BigInteger)o);
                }
                else if (t.IsArray)
                {
                    if (t.GetElementType() == typeof(byte))
                    {
                        byte[] newArr = (byte[])((byte[])o).Clone();
                        ret = new ByteArrayDataValue(name, (byte[])o);
                    }
                    else if (t.GetElementType() == typeof(char))
                    {
                        ret = new StringDataValue(name, new string((char[])o));
                    }
                    else
                    {
                        DataKey key = new DataKey(name);

                        GetArrayType(key, t, o, derivedTypes, readOnly);

                        ret = key;
                    }
                }
                else if (t == typeof(IPAddress))
                {
                    ret = new IPAddressDataValue(name, (IPAddress)o);
                }
                else
                {
                    INodeConverter converter = o as INodeConverter;

                    if (converter != null)
                    {
                        ret = converter.ToNode(name);
                    }
                    else
                    {
                        DataKey key = new DataKey(name);

                        GetComplexType(key, t, o, derivedTypes);

                        ret = key;
                    }
                }

                if (ret != null)
                {
                    ret.Readonly = readOnly;
                }
            }

            return(ret);
        }
Exemplo n.º 5
0
        protected override DataNode ArrayToNode(byte[] array, DataNode node)
        {
            ByteArrayDataValue value = new ByteArrayDataValue(node.Name, array);

            return(value);
        }