Пример #1
0
        static public TagDataNode CreateFromTag(TagNode tag)
        {
            if (tag == null || !_tagRegistry.ContainsKey(tag.GetTagType()))
            {
                return(null);
            }

            return(Activator.CreateInstance(_tagRegistry[tag.GetTagType()], tag) as TagDataNode);
        }
Пример #2
0
        public static string Serialize(TagNode tag, int level)
        {
            StringBuilder str = new StringBuilder();

            if (tag.GetTagType() == TagType.TAG_COMPOUND) {
                SerializeCompound(tag as TagNodeCompound, str, level);
            }
            else if (tag.GetTagType() == TagType.TAG_LIST) {
                SerializeList(tag as TagNodeList, str, level);
            }
            else {
                SerializeScaler(tag, str);
            }

            return str.ToString();
        }
        public static string GetTagNodeText(TagNode tag)
        {
            if (tag == null)
                return null;

            switch (tag.GetTagType())
            {
                case TagType.TAG_BYTE:
                case TagType.TAG_SHORT:
                case TagType.TAG_INT:
                case TagType.TAG_LONG:
                case TagType.TAG_FLOAT:
                case TagType.TAG_DOUBLE:
                case TagType.TAG_STRING:
                    return tag.ToString();

                case TagType.TAG_BYTE_ARRAY:
                    return tag.ToTagByteArray().Length + " bytes";

                case TagType.TAG_LIST:
                    return tag.ToTagList().Count + " entries";

                case TagType.TAG_COMPOUND:
                    return tag.ToTagCompound().Count + " entries";
            }

            return null;
        }
Пример #4
0
        public bool AppendTag (TagNode tag)
        {
            if (_tag.ValueType != tag.GetTagType())
                return false;

            _tag.Add(tag);

            SetModified();
            return true;
        }
Пример #5
0
        public bool AppendTag(TagNode tag)
        {
            if (_tag.ValueType != tag.GetTagType())
            {
                return(false);
            }

            _tag.Add(tag);

            SetModified();
            return(true);
        }
Пример #6
0
        public bool InsertTag (TagNode tag, int index)
        {
            if (index < 0 || index > _tag.Count)
                return false;

            if (_tag.ValueType != tag.GetTagType())
                return false;

            _tag.Insert(index, tag);

            SetModified();
            return true;
        }
Пример #7
0
        public EditValue(TagNode tag)
        {
            InitializeComponent();

              _tag = tag;

              if (tag == null) {
            DialogResult = DialogResult.Abort;
            Close();
            return;
              }
              switch(_tag.GetTagType()) {
            case TagType.TAG_DOUBLE:
              textBox1.Minimum = decimal.MinValue;
              textBox1.Maximum = decimal.MaxValue;
              hasDecimal = true;
              textBox1.Value = (decimal)_tag.ToTagDouble().Data;
              break;
            case TagType.TAG_FLOAT:
              textBox1.Minimum = decimal.MinValue;
              textBox1.Maximum = decimal.MaxValue;
              hasDecimal = true;
              textBox1.Value = (decimal)_tag.ToTagFloat().Data;
              break;
            case TagType.TAG_SHORT:
              textBox1.Minimum = Int16.MinValue;
              textBox1.Maximum = Int16.MaxValue;
              hasDecimal = false;
              textBox1.Value = (decimal)_tag.ToTagShort().Data;
              break;
            case TagType.TAG_INT:
              textBox1.Minimum = Int32.MinValue;
              textBox1.Maximum = Int32.MaxValue;
              hasDecimal = false;
              textBox1.Value = (decimal)_tag.ToTagInt().Data;
              break;
            case TagType.TAG_LONG:
              textBox1.Minimum = Int64.MinValue;
              textBox1.Maximum = Int64.MaxValue;
              hasDecimal = false;
              textBox1.Value = (decimal)_tag.ToTagLong().Data;
              break;
            case TagType.TAG_BYTE:
              textBox1.Minimum = byte.MinValue;
              textBox1.Maximum = byte.MaxValue;
              hasDecimal = false;
              textBox1.Value = (decimal)_tag.ToTagByte().Data;
              break;
              }
        }
Пример #8
0
        private bool ValidateValueInput()
        {
            try {
                switch (_tag.GetTagType())
                {
                case TagType.TAG_BYTE:
                    _tag.ToTagByte().Data = unchecked ((byte)sbyte.Parse(textBox1.Text));
                    break;

                case TagType.TAG_SHORT:
                    _tag.ToTagShort().Data = short.Parse(textBox1.Text);
                    break;

                case TagType.TAG_INT:
                    _tag.ToTagInt().Data = int.Parse(textBox1.Text);
                    break;

                case TagType.TAG_LONG:
                    _tag.ToTagLong().Data = long.Parse(textBox1.Text);
                    break;

                case TagType.TAG_FLOAT:
                    _tag.ToTagFloat().Data = float.Parse(textBox1.Text);
                    break;

                case TagType.TAG_DOUBLE:
                    _tag.ToTagDouble().Data = double.Parse(textBox1.Text);
                    break;

                case TagType.TAG_STRING:
                    _tag.ToTagString().Data = textBox1.Text;
                    break;
                }
            }
            catch (FormatException) {
                MessageBox.Show("The value is formatted incorrectly for the given type.");
                return(false);
            }
            catch (OverflowException) {
                MessageBox.Show("The value is outside the acceptable range for the given type.");
                return(false);
            }
            catch {
                return(false);
            }

            return(true);
        }
Пример #9
0
        private bool ValidateValueInput()
        {
            try {
                switch (_tag.GetTagType())
                {
                case TagType.TAG_BYTE:
                    _tag.ToTagByte().Data = unchecked ((byte)sbyte.Parse(textBox1.Text));
                    break;

                case TagType.TAG_SHORT:
                    _tag.ToTagShort().Data = short.Parse(textBox1.Text);
                    break;

                case TagType.TAG_INT:
                    _tag.ToTagInt().Data = int.Parse(textBox1.Text);
                    break;

                case TagType.TAG_LONG:
                    _tag.ToTagLong().Data = long.Parse(textBox1.Text);
                    break;

                case TagType.TAG_FLOAT:
                    _tag.ToTagFloat().Data = float.Parse(textBox1.Text);
                    break;

                case TagType.TAG_DOUBLE:
                    _tag.ToTagDouble().Data = double.Parse(textBox1.Text);
                    break;

                case TagType.TAG_STRING:
                    _tag.ToTagString().Data = textBox1.Text;
                    break;
                }
            }
            catch (FormatException) {
                MessageBox.Show("指定された値の型が合っていません。。");
                return(false);
            }
            catch (OverflowException) {
                MessageBox.Show("指定された値が大きすぎです。オーバーフローします。", "エラー");
                return(false);
            }
            catch {
                return(false);
            }

            return(true);
        }
Пример #10
0
        private bool ValidateValueInput()
        {
            try {
                switch (_tag.GetTagType())
                {
                case TagType.TAG_BYTE:
                    _tag.ToTagByte().Data = unchecked ((byte)sbyte.Parse(_valueField.StringValue));
                    break;

                case TagType.TAG_SHORT:
                    _tag.ToTagShort().Data = short.Parse(_valueField.StringValue);
                    break;

                case TagType.TAG_INT:
                    _tag.ToTagInt().Data = int.Parse(_valueField.StringValue);
                    break;

                case TagType.TAG_LONG:
                    _tag.ToTagLong().Data = long.Parse(_valueField.StringValue);
                    break;

                case TagType.TAG_FLOAT:
                    _tag.ToTagFloat().Data = float.Parse(_valueField.StringValue);
                    break;

                case TagType.TAG_DOUBLE:
                    _tag.ToTagDouble().Data = double.Parse(_valueField.StringValue);
                    break;

                case TagType.TAG_STRING:
                    _tag.ToTagString().Data = _valueField.StringValue;
                    break;
                }
            }
            catch (FormatException) {
                NSAlert.WithMessage("Invalid Format", "OK", null, null, "The value is formatted incorrectly for the given type.").RunModal();
                return(false);
            }
            catch (OverflowException) {
                NSAlert.WithMessage("Invalid Range", "OK", null, null, "The value is outside the acceptable range for the given type.").RunModal();
                return(false);
            }
            catch {
                return(false);
            }

            return(true);
        }
Пример #11
0
        public bool AppendTag(TagNode tag)
        {
            if (tag == null || !CanCreateTag(tag.GetTagType()))
                return false;

            _container.InsertTag(tag, _container.TagCount);
            IsDataModified = true;

            if (IsExpanded) {
                TagDataNode node = TagDataNode.CreateFromTag(tag);
                if (node != null)
                    Nodes.Add(node);
            }

            return true;
        }
Пример #12
0
        public bool InsertTag(TagNode tag, int index)
        {
            if (index < 0 || index > _tag.Count)
            {
                return(false);
            }

            if (_tag.ValueType != tag.GetTagType())
            {
                return(false);
            }

            _tag.Insert(index, tag);

            SetModified();
            return(true);
        }
        public bool AppendTag(TagNode tag)
        {
            if (tag == null || !CanCreateTag(tag.GetTagType()))
            {
                return(false);
            }

            _container.InsertTag(tag, _container.TagCount);
            IsDataModified = true;

            if (IsExpanded)
            {
                TagDataNode node = TagDataNode.CreateFromTag(tag);
                if (node != null)
                {
                    Nodes.Add(node);
                }
            }

            return(true);
        }
Пример #14
0
        private static void SerializeScaler(TagNode tag, StringBuilder str)
        {
            switch (tag.GetTagType()) {
                case TagType.TAG_STRING:
                    str.Append("\"" + tag.ToTagString().Data + "\"");
                    break;

                case TagType.TAG_BYTE:
                    str.Append(tag.ToTagByte().Data);
                    break;

                case TagType.TAG_SHORT:
                    str.Append(tag.ToTagShort().Data);
                    break;

                case TagType.TAG_INT:
                    str.Append(tag.ToTagInt().Data);
                    break;

                case TagType.TAG_LONG:
                    str.Append(tag.ToTagLong().Data);
                    break;

                case TagType.TAG_FLOAT:
                    str.Append(tag.ToTagFloat().Data);
                    break;

                case TagType.TAG_DOUBLE:
                    str.Append(tag.ToTagDouble().Data);
                    break;

                case TagType.TAG_BYTE_ARRAY:
                    str.Append(Convert.ToBase64String(tag.ToTagByteArray().Data));
                    /*if (tag.ToTagByteArray().Length == (16 * 16 * 128 / 2)) {
                        str.Append(Base16.Encode(tag.ToTagByteArray().Data, 1));
                    }
                    else {
                        str.Append(Base16.Encode(tag.ToTagByteArray().Data, 2));
                    }*/
                    break;
            }
        }
Пример #15
0
        static TreeNode NodeFromTag(TagNode tag, int descriptionIndex, string name)
        {
            var text = SubstrateHelper.GetNodeText(name, tag);
            var node = ServerNode.InitializeTreeNode(_tagIconIndex[tag.GetTagType()], text, tag);

            if (tag.GetTagType() == TagType.TAG_LIST)
            {
                PopulateNodeFromTag(node, descriptionIndex, tag.ToTagList());
            }
            else if (tag.GetTagType() == TagType.TAG_COMPOUND)
            {
                PopulateNodeFromTag(node, descriptionIndex, tag.ToTagCompound());
            }

            return node;
        }
Пример #16
0
        public override bool Matches(TagCompoundDataNode container, List <TagDataNode> matchedNodes)
        {
            TagDataNode childNode = GetChild(container, Name);
            TagNode     tag       = container.NamedTagContainer.GetTagNode(Name);

            if (tag == null)
            {
                return(false);
            }

            try {
                switch (tag.GetTagType())
                {
                case TagType.TAG_BYTE:
                case TagType.TAG_INT:
                case TagType.TAG_LONG:
                case TagType.TAG_SHORT:
                    switch (Operator)
                    {
                    case WildcardOperator.Equals:
                        if (long.Parse(Value) != tag.ToTagLong())
                        {
                            return(false);
                        }
                        break;

                    case WildcardOperator.NotEquals:
                        if (long.Parse(Value) == tag.ToTagLong())
                        {
                            return(false);
                        }
                        break;
                    }

                    if (!matchedNodes.Contains(childNode))
                    {
                        matchedNodes.Add(childNode);
                    }
                    return(true);

                case TagType.TAG_FLOAT:
                case TagType.TAG_DOUBLE:
                    switch (Operator)
                    {
                    case WildcardOperator.Equals:
                        if (double.Parse(Value) != tag.ToTagDouble())
                        {
                            return(false);
                        }
                        break;

                    case WildcardOperator.NotEquals:
                        if (double.Parse(Value) == tag.ToTagDouble())
                        {
                            return(false);
                        }
                        break;
                    }

                    if (!matchedNodes.Contains(childNode))
                    {
                        matchedNodes.Add(childNode);
                    }
                    return(true);

                case TagType.TAG_STRING:
                    switch (Operator)
                    {
                    case WildcardOperator.Equals:
                        if (Value != tag.ToTagString().Data)
                        {
                            return(false);
                        }
                        break;

                    case WildcardOperator.NotEquals:
                        if (Value == tag.ToTagString().Data)
                        {
                            return(false);
                        }
                        break;
                    }

                    if (!matchedNodes.Contains(childNode))
                    {
                        matchedNodes.Add(childNode);
                    }
                    return(true);
                }
            }
            catch { }

            return(false);
        }
Пример #17
0
        static public TagDataNode CreateFromTag (TagNode tag)
        {
            if (tag == null || !_tagRegistry.ContainsKey(tag.GetTagType()))
                return null;

            return Activator.CreateInstance(_tagRegistry[tag.GetTagType()], tag) as TagDataNode;
        }