private void ParseList(XmlBinaryNode listNode)
 {
     if (offset >= xmlDoc.Length)
     {
         return;
     }
     while (xmlDoc[offset] != XmlBinaryNodeType.EndListText && xmlDoc[offset] != XmlBinaryNodeType.EndListTextWithEndElement)
     {
         ParseContentNode(listNode);
         if (offset >= xmlDoc.Length)
         {
             return;
         }
     }
     listNode.AddChild(new XmlBinaryNode(xmlDoc[offset], depth));
     offset++; // EndListText
 }
示例#2
0
 private void Parse(ref XmlBinaryNode parent, bool insideAttribute, bool insideArray)
 {
     if (offset >= xmlDoc.Length) return;
     bool first = true;
     while (offset < xmlDoc.Length)
     {
         if (!first && insideAttribute)
         {
             return;
         }
         first = false;
         byte nodeType = xmlDoc[offset];
         if (XmlBinaryNodeType.IsTextNode(nodeType) || XmlBinaryNodeType.IsTextNodeWithEndElement(nodeType))
         {
             ParseContentNode(parent);
             if (XmlBinaryNodeType.IsTextNodeWithEndElement(nodeType))
             {
                 depth--;
                 return;
             }
         }
         else
         {
             offset++;
             XmlBinaryNode newNode = new XmlBinaryNode(nodeType, depth);
             if (parent == null)
             {
                 parent = newNode;
             }
             else
             {
                 parent.AddChild(newNode);
             }
             switch (nodeType)
             {
                 case XmlBinaryNodeType.EndElement:
                     depth--;
                     return;
                 case XmlBinaryNodeType.Comment:
                     newNode.Text = ReadString(0);
                     break;
                 case XmlBinaryNodeType.ShortElement:
                 case XmlBinaryNodeType.ShortDictionaryElement:
                 case XmlBinaryNodeType.Element:
                 case XmlBinaryNodeType.DictionaryElement:
                     {
                         bool isDictionaryElement = XmlBinaryNodeType.IsDictionaryElementNode(nodeType);
                         bool isShortElement = XmlBinaryNodeType.GetNodeName(nodeType).StartsWith("Short");
                         if (!isShortElement)
                         {
                             newNode.Prefix = ReadString(0);
                         }
                         if (isDictionaryElement)
                         {
                             newNode.DictionaryLocalName = ReadDictionaryString();
                         }
                         else
                         {
                             newNode.LocalName = ReadString(0);
                         }
                         int oldDepth = depth;
                         depth++;
                         Parse(ref newNode);
                         if (depth != oldDepth) ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                         if (insideArray)
                         {
                             return;
                         }
                     }
                     break;
                 case XmlBinaryNodeType.PrefixElementA:
                 case XmlBinaryNodeType.PrefixElementB:
                 case XmlBinaryNodeType.PrefixElementC:
                 case XmlBinaryNodeType.PrefixElementD:
                 case XmlBinaryNodeType.PrefixElementE:
                 case XmlBinaryNodeType.PrefixElementF:
                 case XmlBinaryNodeType.PrefixElementG:
                 case XmlBinaryNodeType.PrefixElementH:
                 case XmlBinaryNodeType.PrefixElementI:
                 case XmlBinaryNodeType.PrefixElementJ:
                 case XmlBinaryNodeType.PrefixElementK:
                 case XmlBinaryNodeType.PrefixElementL:
                 case XmlBinaryNodeType.PrefixElementM:
                 case XmlBinaryNodeType.PrefixElementN:
                 case XmlBinaryNodeType.PrefixElementO:
                 case XmlBinaryNodeType.PrefixElementP:
                 case XmlBinaryNodeType.PrefixElementQ:
                 case XmlBinaryNodeType.PrefixElementR:
                 case XmlBinaryNodeType.PrefixElementS:
                 case XmlBinaryNodeType.PrefixElementT:
                 case XmlBinaryNodeType.PrefixElementU:
                 case XmlBinaryNodeType.PrefixElementV:
                 case XmlBinaryNodeType.PrefixElementW:
                 case XmlBinaryNodeType.PrefixElementX:
                 case XmlBinaryNodeType.PrefixElementY:
                 case XmlBinaryNodeType.PrefixElementZ:
                 case XmlBinaryNodeType.PrefixDictionaryElementA:
                 case XmlBinaryNodeType.PrefixDictionaryElementB:
                 case XmlBinaryNodeType.PrefixDictionaryElementC:
                 case XmlBinaryNodeType.PrefixDictionaryElementD:
                 case XmlBinaryNodeType.PrefixDictionaryElementE:
                 case XmlBinaryNodeType.PrefixDictionaryElementF:
                 case XmlBinaryNodeType.PrefixDictionaryElementG:
                 case XmlBinaryNodeType.PrefixDictionaryElementH:
                 case XmlBinaryNodeType.PrefixDictionaryElementI:
                 case XmlBinaryNodeType.PrefixDictionaryElementJ:
                 case XmlBinaryNodeType.PrefixDictionaryElementK:
                 case XmlBinaryNodeType.PrefixDictionaryElementL:
                 case XmlBinaryNodeType.PrefixDictionaryElementM:
                 case XmlBinaryNodeType.PrefixDictionaryElementN:
                 case XmlBinaryNodeType.PrefixDictionaryElementO:
                 case XmlBinaryNodeType.PrefixDictionaryElementP:
                 case XmlBinaryNodeType.PrefixDictionaryElementQ:
                 case XmlBinaryNodeType.PrefixDictionaryElementR:
                 case XmlBinaryNodeType.PrefixDictionaryElementS:
                 case XmlBinaryNodeType.PrefixDictionaryElementT:
                 case XmlBinaryNodeType.PrefixDictionaryElementU:
                 case XmlBinaryNodeType.PrefixDictionaryElementV:
                 case XmlBinaryNodeType.PrefixDictionaryElementW:
                 case XmlBinaryNodeType.PrefixDictionaryElementX:
                 case XmlBinaryNodeType.PrefixDictionaryElementY:
                 case XmlBinaryNodeType.PrefixDictionaryElementZ:
                     {
                         char prefixLetter;
                         bool isDictionaryElement = XmlBinaryNodeType.IsDictionaryElementNode(nodeType);
                         prefixLetter = (char)((int)'a' + (int)nodeType - (int)(isDictionaryElement ? XmlBinaryNodeType.PrefixDictionaryElementA : XmlBinaryNodeType.PrefixElementA));
                         newNode.Prefix = new string(prefixLetter, 1);
                         if (isDictionaryElement)
                         {
                             newNode.DictionaryLocalName = ReadDictionaryString();
                         }
                         else
                         {
                             newNode.LocalName = ReadString(0);
                         }
                         int oldDepth = depth;
                         depth++;
                         Parse(ref newNode);
                         if (depth != oldDepth) ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                         if (insideArray)
                         {
                             return;
                         }
                     }
                     break;
                 case XmlBinaryNodeType.ShortAttribute:
                 case XmlBinaryNodeType.ShortDictionaryAttribute:
                 case XmlBinaryNodeType.Attribute:
                 case XmlBinaryNodeType.DictionaryAttribute:
                     {
                         bool isDictionaryAttribute = XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType);
                         bool isShortAttribute = XmlBinaryNodeType.GetNodeName(nodeType).StartsWith("Short");
                         if (!isShortAttribute)
                         {
                             newNode.Prefix = ReadString(0);
                         }
                         if (isDictionaryAttribute)
                         {
                             newNode.DictionaryLocalName = ReadDictionaryString();
                         }
                         else
                         {
                             newNode.LocalName = ReadString(0);
                         }
                         int oldDepth = depth;
                         depth++;
                         Parse(ref newNode, true);
                         if (depth != (oldDepth + 1)) ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                         depth--;
                         if (newNode.Children.Count != 1)
                         {
                             throw new ArgumentException("Error, attribute nodes must have exactly one child, at offset " + offset);
                         }
                     }
                     break;
                 case XmlBinaryNodeType.ShortXmlnsAttribute:
                 case XmlBinaryNodeType.ShortDictionaryXmlnsAttribute:
                 case XmlBinaryNodeType.XmlnsAttribute:
                 case XmlBinaryNodeType.DictionaryXmlnsAttribute:
                     {
                         bool isDictionaryAttribute = XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType);
                         bool isShortAttribute = XmlBinaryNodeType.GetNodeName(nodeType).StartsWith("Short");
                         if (!isShortAttribute)
                         {
                             newNode.Prefix = ReadString(0);
                         }
                         if (isDictionaryAttribute)
                         {
                             newNode.DictionaryNamespaceURI = ReadDictionaryString();
                         }
                         else
                         {
                             newNode.NamespaceURI = ReadString(0);
                         }
                     }
                     break;
                 case XmlBinaryNodeType.PrefixAttributeA:
                 case XmlBinaryNodeType.PrefixAttributeB:
                 case XmlBinaryNodeType.PrefixAttributeC:
                 case XmlBinaryNodeType.PrefixAttributeD:
                 case XmlBinaryNodeType.PrefixAttributeE:
                 case XmlBinaryNodeType.PrefixAttributeF:
                 case XmlBinaryNodeType.PrefixAttributeG:
                 case XmlBinaryNodeType.PrefixAttributeH:
                 case XmlBinaryNodeType.PrefixAttributeI:
                 case XmlBinaryNodeType.PrefixAttributeJ:
                 case XmlBinaryNodeType.PrefixAttributeK:
                 case XmlBinaryNodeType.PrefixAttributeL:
                 case XmlBinaryNodeType.PrefixAttributeM:
                 case XmlBinaryNodeType.PrefixAttributeN:
                 case XmlBinaryNodeType.PrefixAttributeO:
                 case XmlBinaryNodeType.PrefixAttributeP:
                 case XmlBinaryNodeType.PrefixAttributeQ:
                 case XmlBinaryNodeType.PrefixAttributeR:
                 case XmlBinaryNodeType.PrefixAttributeS:
                 case XmlBinaryNodeType.PrefixAttributeT:
                 case XmlBinaryNodeType.PrefixAttributeU:
                 case XmlBinaryNodeType.PrefixAttributeV:
                 case XmlBinaryNodeType.PrefixAttributeW:
                 case XmlBinaryNodeType.PrefixAttributeX:
                 case XmlBinaryNodeType.PrefixAttributeY:
                 case XmlBinaryNodeType.PrefixAttributeZ:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeA:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeB:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeC:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeD:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeE:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeF:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeG:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeH:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeI:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeJ:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeK:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeL:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeM:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeN:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeO:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeP:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeQ:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeR:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeS:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeT:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeU:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeV:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeW:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeX:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeY:
                 case XmlBinaryNodeType.PrefixDictionaryAttributeZ:
                     {
                         char prefixLetter;
                         bool isDictionaryAttribute = XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType);
                         prefixLetter = (char)((int)'a' + (int)nodeType - (int)(isDictionaryAttribute ? XmlBinaryNodeType.PrefixDictionaryAttributeA : XmlBinaryNodeType.PrefixAttributeA));
                         newNode.Prefix = new string(prefixLetter, 1);
                         if (isDictionaryAttribute)
                         {
                             newNode.DictionaryLocalName = ReadDictionaryString();
                         }
                         else
                         {
                             newNode.LocalName = ReadString(0);
                         }
                         int oldDepth = depth;
                         depth++;
                         Parse(ref newNode, true);
                         if (depth != (oldDepth + 1)) ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                         depth--;
                         if (newNode.Children.Count != 1)
                         {
                             throw new ArgumentException("Error, attribute nodes must have exactly one child, at offset " + offset);
                         }
                     }
                     break;
                 case XmlBinaryNodeType.Array:
                     {
                         int oldDepth = depth;
                         depth++;
                         ParseArray(newNode);
                         if (depth != oldDepth) ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                     }
                     break;
                 default:
                     throw new ArgumentException(String.Format("Error, the test is not ready to handle the type {0:X2} ({1}) yet", nodeType, XmlBinaryNodeType.GetNodeName(nodeType)));
             }
         }
     }
 }
示例#3
0
 private void Parse(ref XmlBinaryNode parent, bool insideAttribute)
 {
     Parse(ref parent, insideAttribute, false);
 }
示例#4
0
 private void Parse(ref XmlBinaryNode parent)
 {
     Parse(ref parent, false, false);
 }
示例#5
0
 private void ParseArray(XmlBinaryNode parent)
 {
     Parse(ref parent, false, true);
     if ((offset + 1) >= xmlDoc.Length) ThrowOffsetException("Inside array");
     byte arrayNodeType = xmlDoc[offset];
     offset++;
     int elementCount = ReadMB32();
     parent.ArrayElements = new BinaryArrayElements(arrayNodeType, elementCount);
     for (int i = 0; i < elementCount; i++)
     {
         switch (arrayNodeType)
         {
             case XmlBinaryNodeType.BoolTextWithEndElement:
                 if (i == 0)
                 {
                     parent.ArrayElements.BoolArray = new bool[elementCount];
                 }
                 if (offset >= xmlDoc.Length) ThrowOffsetException("Error in BoolArray");
                 parent.ArrayElements.BoolArray[i] = (xmlDoc[offset] != 0x00);
                 offset++;
                 break;
             case XmlBinaryNodeType.DateTimeTextWithEndElement:
                 if (i == 0)
                 {
                     parent.ArrayElements.DateTimeArray = new DateTime[elementCount];
                 }
                 parent.ArrayElements.DateTimeArray[i] = ReadDateTime();
                 break;
             case XmlBinaryNodeType.DecimalTextWithEndElement:
                 if (i == 0)
                 {
                     parent.ArrayElements.DecimalArray = new decimal[elementCount];
                 }
                 parent.ArrayElements.DecimalArray[i] = ReadDecimal();
                 break;
             case XmlBinaryNodeType.DoubleTextWithEndElement:
                 if (i == 0)
                 {
                     parent.ArrayElements.DoubleArray = new double[elementCount];
                 }
                 parent.ArrayElements.DoubleArray[i] = ReadDouble();
                 break;
             case XmlBinaryNodeType.GuidTextWithEndElement:
                 if (i == 0)
                 {
                     parent.ArrayElements.GuidArray = new Guid[elementCount];
                 }
                 parent.ArrayElements.GuidArray[i] = ReadGuid();
                 break;
             case XmlBinaryNodeType.Int16TextWithEndElement:
                 if (i == 0)
                 {
                     parent.ArrayElements.ShortArray = new short[elementCount];
                 }
                 parent.ArrayElements.ShortArray[i] = (short)ReadInt(2);
                 break;
             case XmlBinaryNodeType.Int32TextWithEndElement:
                 if (i == 0)
                 {
                     parent.ArrayElements.IntArray = new int[elementCount];
                 }
                 parent.ArrayElements.IntArray[i] = ReadInt(4);
                 break;
             case XmlBinaryNodeType.Int64TextWithEndElement:
                 if (i == 0)
                 {
                     parent.ArrayElements.LongArray = new long[elementCount];
                 }
                 parent.ArrayElements.LongArray[i] = ReadLong();
                 break;
             case XmlBinaryNodeType.FloatTextWithEndElement:
                 if (i == 0)
                 {
                     parent.ArrayElements.FloatArray = new float[elementCount];
                 }
                 parent.ArrayElements.FloatArray[i] = ReadFloat();
                 break;
             case XmlBinaryNodeType.TimeSpanTextWithEndElement:
                 if (i == 0)
                 {
                     parent.ArrayElements.TimeSpanArray = new TimeSpan[elementCount];
                 }
                 parent.ArrayElements.TimeSpanArray[i] = TimeSpan.FromTicks(ReadLong());
                 break;
             default:
                 throw new ArgumentException(String.Format("Invalid array node type: {0:X2} - {1}",
                     arrayNodeType, XmlBinaryNodeType.GetNodeName(arrayNodeType)));
         }
     }
     if (XmlBinaryNodeType.IsTextNodeWithEndElement(arrayNodeType))
     {
         depth--;
     }
 }
示例#6
0
 private void ParseList(XmlBinaryNode listNode)
 {
     if (offset >= xmlDoc.Length) return;
     while (xmlDoc[offset] != XmlBinaryNodeType.EndListText && xmlDoc[offset] != XmlBinaryNodeType.EndListTextWithEndElement)
     {
         ParseContentNode(listNode);
         if (offset >= xmlDoc.Length) return;
     }
     listNode.AddChild(new XmlBinaryNode(xmlDoc[offset], depth));
     offset++; // EndListText
 }
示例#7
0
 private void ParseContentNode(XmlBinaryNode parent)
 {
     byte nodeType = xmlDoc[offset];
     offset++;
     XmlBinaryNode newNode = new XmlBinaryNode(nodeType, depth);
     parent.AddChild(newNode);
     switch (nodeType)
     {
         case XmlBinaryNodeType.Chars8Text:
         case XmlBinaryNodeType.Chars8TextWithEndElement:
             newNode.Text = ReadString(8);
             break;
         case XmlBinaryNodeType.Chars16Text:
         case XmlBinaryNodeType.Chars16TextWithEndElement:
             newNode.Text = ReadString(16);
             break;
         case XmlBinaryNodeType.Chars32Text:
         case XmlBinaryNodeType.Chars32TextWithEndElement:
             newNode.Text = ReadString(32);
             break;
         case XmlBinaryNodeType.UnicodeChars8Text:
         case XmlBinaryNodeType.UnicodeChars8TextWithEndElement:
         case XmlBinaryNodeType.UnicodeChars16Text:
         case XmlBinaryNodeType.UnicodeChars16TextWithEndElement:
         case XmlBinaryNodeType.UnicodeChars32Text:
         case XmlBinaryNodeType.UnicodeChars32TextWithEndElement:
             {
                 int unicodeTextLenSize = 0;
                 switch (nodeType)
                 {
                     case XmlBinaryNodeType.UnicodeChars8Text:
                     case XmlBinaryNodeType.UnicodeChars8TextWithEndElement:
                         unicodeTextLenSize = 1;
                         break;
                     case XmlBinaryNodeType.UnicodeChars16Text:
                     case XmlBinaryNodeType.UnicodeChars16TextWithEndElement:
                         unicodeTextLenSize = 2;
                         break;
                     case XmlBinaryNodeType.UnicodeChars32Text:
                     case XmlBinaryNodeType.UnicodeChars32TextWithEndElement:
                         unicodeTextLenSize = 4;
                         break;
                 }
                 int unicodeTextLength = ReadInt(unicodeTextLenSize);
                 if ((offset + unicodeTextLength) > xmlDoc.Length)
                 {
                     ThrowOffsetException("Error reading UnicodeCharsXText");
                 }
                 byte[] temp = new byte[unicodeTextLength];
                 Buffer.BlockCopy(xmlDoc, offset, temp, 0, unicodeTextLength);
                 newNode.Text = unicodeEncoding.GetString(temp, 0, temp.Length);
                 offset += unicodeTextLength;
             }
             break;
         case XmlBinaryNodeType.Bytes8Text:
         case XmlBinaryNodeType.Bytes8TextWithEndElement:
         case XmlBinaryNodeType.Bytes16Text:
         case XmlBinaryNodeType.Bytes16TextWithEndElement:
         case XmlBinaryNodeType.Bytes32Text:
         case XmlBinaryNodeType.Bytes32TextWithEndElement:
             {
                 int byteArrayLenSize = 0;
                 switch (nodeType)
                 {
                     case XmlBinaryNodeType.Bytes8Text:
                     case XmlBinaryNodeType.Bytes8TextWithEndElement:
                         byteArrayLenSize = 1;
                         break;
                     case XmlBinaryNodeType.Bytes16Text:
                     case XmlBinaryNodeType.Bytes16TextWithEndElement:
                         byteArrayLenSize = 2;
                         break;
                     case XmlBinaryNodeType.Bytes32Text:
                     case XmlBinaryNodeType.Bytes32TextWithEndElement:
                         byteArrayLenSize = 4;
                         break;
                 }
                 int byteArrayLength = ReadInt(byteArrayLenSize);
                 if ((offset + byteArrayLength) > xmlDoc.Length)
                 {
                     ThrowOffsetException("Error reading BytesXText");
                 }
                 newNode.Bytes = new byte[byteArrayLength];
                 Buffer.BlockCopy(xmlDoc, offset, newNode.Bytes, 0, byteArrayLength);
                 offset += byteArrayLength;
             }
             break;
         case XmlBinaryNodeType.Int8Text:
         case XmlBinaryNodeType.Int8TextWithEndElement:
             newNode.IntValue = ReadInt(1);
             break;
         case XmlBinaryNodeType.Int16Text:
         case XmlBinaryNodeType.Int16TextWithEndElement:
             newNode.IntValue = ReadInt(2);
             break;
         case XmlBinaryNodeType.Int32Text:
         case XmlBinaryNodeType.Int32TextWithEndElement:
             newNode.IntValue = ReadInt(4);
             break;
         case XmlBinaryNodeType.Int64Text:
         case XmlBinaryNodeType.Int64TextWithEndElement:
         case XmlBinaryNodeType.UInt64Text:
         case XmlBinaryNodeType.UInt64TextWithEndElement:
             newNode.LongValue = ReadLong();
             break;
         case XmlBinaryNodeType.FloatText:
         case XmlBinaryNodeType.FloatTextWithEndElement:
             newNode.FloatValue = ReadFloat();
             break;
         case XmlBinaryNodeType.DoubleText:
         case XmlBinaryNodeType.DoubleTextWithEndElement:
             newNode.DoubleValue = ReadDouble();
             break;
         case XmlBinaryNodeType.DecimalText:
         case XmlBinaryNodeType.DecimalTextWithEndElement:
             newNode.DecimalValue = ReadDecimal();
             break;
         case XmlBinaryNodeType.DateTimeText:
         case XmlBinaryNodeType.DateTimeTextWithEndElement:
             newNode.DateTimeValue = ReadDateTime();
             break;
         case XmlBinaryNodeType.TimeSpanText:
         case XmlBinaryNodeType.TimeSpanTextWithEndElement:
             newNode.TimeSpanValue = TimeSpan.FromTicks(ReadLong());
             break;
         case XmlBinaryNodeType.EmptyText:
         case XmlBinaryNodeType.EmptyTextWithEndElement:
             newNode.Text = "";
             break;
         case XmlBinaryNodeType.ZeroText:
         case XmlBinaryNodeType.ZeroTextWithEndElement:
             newNode.Text = "0";
             break;
         case XmlBinaryNodeType.OneText:
         case XmlBinaryNodeType.OneTextWithEndElement:
             newNode.Text = "1";
             break;
         case XmlBinaryNodeType.TrueText:
         case XmlBinaryNodeType.TrueTextWithEndElement:
             newNode.Text = "true";
             break;
         case XmlBinaryNodeType.FalseText:
         case XmlBinaryNodeType.FalseTextWithEndElement:
             newNode.Text = "false";
             break;
         case XmlBinaryNodeType.DictionaryText:
         case XmlBinaryNodeType.DictionaryTextWithEndElement:
             newNode.DictionaryText = ReadDictionaryString();
             break;
         case XmlBinaryNodeType.GuidText:
         case XmlBinaryNodeType.GuidTextWithEndElement:
             newNode.GuidValue = ReadGuid();
             break;
         case XmlBinaryNodeType.UniqueIdText:
         case XmlBinaryNodeType.UniqueIdTextWithEndElement:
             {
                 byte[] uniqueIdBytes = new byte[16];
                 if ((offset + uniqueIdBytes.Length) > xmlDoc.Length)
                 {
                     ThrowOffsetException("Error reading UniqueId");
                 }
                 Buffer.BlockCopy(xmlDoc, offset, uniqueIdBytes, 0, uniqueIdBytes.Length);
                 newNode.UniqueIdValue = new UniqueId(uniqueIdBytes);
                 offset += uniqueIdBytes.Length;
             }
             break;
         case XmlBinaryNodeType.StartListTextWithEndElement:
             throw new ArgumentException("StartListTextWithEndElement is an invalid node!");
         case XmlBinaryNodeType.StartListText:
             {
                 depth++;
                 ParseList(newNode);
                 depth--;
             }
             break;
         default:
             throw new ArgumentException(String.Format("Error, the test is not ready to handle the type {0:X2} ({1}) yet", nodeType, XmlBinaryNodeType.GetNodeName(nodeType)));
     }
 }
示例#8
0
 public void AddChild(XmlBinaryNode childNode)
 {
     this.children.Add(childNode);
     childNode.parentNode = this;
     childNode.depth = this.depth + 1;
 }
 public void AddChild(XmlBinaryNode childNode)
 {
     this.children.Add(childNode);
     childNode.parentNode = this;
     childNode.depth      = this.depth + 1;
 }
        private void Parse(ref XmlBinaryNode parent, bool insideAttribute, bool insideArray)
        {
            if (offset >= xmlDoc.Length)
            {
                return;
            }
            bool first = true;

            while (offset < xmlDoc.Length)
            {
                if (!first && insideAttribute)
                {
                    return;
                }
                first = false;
                byte nodeType = xmlDoc[offset];
                if (XmlBinaryNodeType.IsTextNode(nodeType) || XmlBinaryNodeType.IsTextNodeWithEndElement(nodeType))
                {
                    ParseContentNode(parent);
                    if (XmlBinaryNodeType.IsTextNodeWithEndElement(nodeType))
                    {
                        depth--;
                        return;
                    }
                }
                else
                {
                    offset++;
                    XmlBinaryNode newNode = new XmlBinaryNode(nodeType, depth);
                    if (parent == null)
                    {
                        parent = newNode;
                    }
                    else
                    {
                        parent.AddChild(newNode);
                    }
                    switch (nodeType)
                    {
                    case XmlBinaryNodeType.EndElement:
                        depth--;
                        return;

                    case XmlBinaryNodeType.Comment:
                        newNode.Text = ReadString(0);
                        break;

                    case XmlBinaryNodeType.ShortElement:
                    case XmlBinaryNodeType.ShortDictionaryElement:
                    case XmlBinaryNodeType.Element:
                    case XmlBinaryNodeType.DictionaryElement:
                    {
                        bool isDictionaryElement = XmlBinaryNodeType.IsDictionaryElementNode(nodeType);
                        bool isShortElement      = XmlBinaryNodeType.GetNodeName(nodeType).StartsWith("Short");
                        if (!isShortElement)
                        {
                            newNode.Prefix = ReadString(0);
                        }
                        if (isDictionaryElement)
                        {
                            newNode.DictionaryLocalName = ReadDictionaryString();
                        }
                        else
                        {
                            newNode.LocalName = ReadString(0);
                        }
                        int oldDepth = depth;
                        depth++;
                        Parse(ref newNode);
                        if (depth != oldDepth)
                        {
                            ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                        }
                        if (insideArray)
                        {
                            return;
                        }
                    }
                    break;

                    case XmlBinaryNodeType.PrefixElementA:
                    case XmlBinaryNodeType.PrefixElementB:
                    case XmlBinaryNodeType.PrefixElementC:
                    case XmlBinaryNodeType.PrefixElementD:
                    case XmlBinaryNodeType.PrefixElementE:
                    case XmlBinaryNodeType.PrefixElementF:
                    case XmlBinaryNodeType.PrefixElementG:
                    case XmlBinaryNodeType.PrefixElementH:
                    case XmlBinaryNodeType.PrefixElementI:
                    case XmlBinaryNodeType.PrefixElementJ:
                    case XmlBinaryNodeType.PrefixElementK:
                    case XmlBinaryNodeType.PrefixElementL:
                    case XmlBinaryNodeType.PrefixElementM:
                    case XmlBinaryNodeType.PrefixElementN:
                    case XmlBinaryNodeType.PrefixElementO:
                    case XmlBinaryNodeType.PrefixElementP:
                    case XmlBinaryNodeType.PrefixElementQ:
                    case XmlBinaryNodeType.PrefixElementR:
                    case XmlBinaryNodeType.PrefixElementS:
                    case XmlBinaryNodeType.PrefixElementT:
                    case XmlBinaryNodeType.PrefixElementU:
                    case XmlBinaryNodeType.PrefixElementV:
                    case XmlBinaryNodeType.PrefixElementW:
                    case XmlBinaryNodeType.PrefixElementX:
                    case XmlBinaryNodeType.PrefixElementY:
                    case XmlBinaryNodeType.PrefixElementZ:
                    case XmlBinaryNodeType.PrefixDictionaryElementA:
                    case XmlBinaryNodeType.PrefixDictionaryElementB:
                    case XmlBinaryNodeType.PrefixDictionaryElementC:
                    case XmlBinaryNodeType.PrefixDictionaryElementD:
                    case XmlBinaryNodeType.PrefixDictionaryElementE:
                    case XmlBinaryNodeType.PrefixDictionaryElementF:
                    case XmlBinaryNodeType.PrefixDictionaryElementG:
                    case XmlBinaryNodeType.PrefixDictionaryElementH:
                    case XmlBinaryNodeType.PrefixDictionaryElementI:
                    case XmlBinaryNodeType.PrefixDictionaryElementJ:
                    case XmlBinaryNodeType.PrefixDictionaryElementK:
                    case XmlBinaryNodeType.PrefixDictionaryElementL:
                    case XmlBinaryNodeType.PrefixDictionaryElementM:
                    case XmlBinaryNodeType.PrefixDictionaryElementN:
                    case XmlBinaryNodeType.PrefixDictionaryElementO:
                    case XmlBinaryNodeType.PrefixDictionaryElementP:
                    case XmlBinaryNodeType.PrefixDictionaryElementQ:
                    case XmlBinaryNodeType.PrefixDictionaryElementR:
                    case XmlBinaryNodeType.PrefixDictionaryElementS:
                    case XmlBinaryNodeType.PrefixDictionaryElementT:
                    case XmlBinaryNodeType.PrefixDictionaryElementU:
                    case XmlBinaryNodeType.PrefixDictionaryElementV:
                    case XmlBinaryNodeType.PrefixDictionaryElementW:
                    case XmlBinaryNodeType.PrefixDictionaryElementX:
                    case XmlBinaryNodeType.PrefixDictionaryElementY:
                    case XmlBinaryNodeType.PrefixDictionaryElementZ:
                    {
                        char prefixLetter;
                        bool isDictionaryElement = XmlBinaryNodeType.IsDictionaryElementNode(nodeType);
                        prefixLetter   = (char)((int)'a' + (int)nodeType - (int)(isDictionaryElement ? XmlBinaryNodeType.PrefixDictionaryElementA : XmlBinaryNodeType.PrefixElementA));
                        newNode.Prefix = new string(prefixLetter, 1);
                        if (isDictionaryElement)
                        {
                            newNode.DictionaryLocalName = ReadDictionaryString();
                        }
                        else
                        {
                            newNode.LocalName = ReadString(0);
                        }
                        int oldDepth = depth;
                        depth++;
                        Parse(ref newNode);
                        if (depth != oldDepth)
                        {
                            ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                        }
                        if (insideArray)
                        {
                            return;
                        }
                    }
                    break;

                    case XmlBinaryNodeType.ShortAttribute:
                    case XmlBinaryNodeType.ShortDictionaryAttribute:
                    case XmlBinaryNodeType.Attribute:
                    case XmlBinaryNodeType.DictionaryAttribute:
                    {
                        bool isDictionaryAttribute = XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType);
                        bool isShortAttribute      = XmlBinaryNodeType.GetNodeName(nodeType).StartsWith("Short");
                        if (!isShortAttribute)
                        {
                            newNode.Prefix = ReadString(0);
                        }
                        if (isDictionaryAttribute)
                        {
                            newNode.DictionaryLocalName = ReadDictionaryString();
                        }
                        else
                        {
                            newNode.LocalName = ReadString(0);
                        }
                        int oldDepth = depth;
                        depth++;
                        Parse(ref newNode, true);
                        if (depth != (oldDepth + 1))
                        {
                            ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                        }
                        depth--;
                        if (newNode.Children.Count != 1)
                        {
                            throw new ArgumentException("Error, attribute nodes must have exactly one child, at offset " + offset);
                        }
                    }
                    break;

                    case XmlBinaryNodeType.ShortXmlnsAttribute:
                    case XmlBinaryNodeType.ShortDictionaryXmlnsAttribute:
                    case XmlBinaryNodeType.XmlnsAttribute:
                    case XmlBinaryNodeType.DictionaryXmlnsAttribute:
                    {
                        bool isDictionaryAttribute = XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType);
                        bool isShortAttribute      = XmlBinaryNodeType.GetNodeName(nodeType).StartsWith("Short");
                        if (!isShortAttribute)
                        {
                            newNode.Prefix = ReadString(0);
                        }
                        if (isDictionaryAttribute)
                        {
                            newNode.DictionaryNamespaceURI = ReadDictionaryString();
                        }
                        else
                        {
                            newNode.NamespaceURI = ReadString(0);
                        }
                    }
                    break;

                    case XmlBinaryNodeType.PrefixAttributeA:
                    case XmlBinaryNodeType.PrefixAttributeB:
                    case XmlBinaryNodeType.PrefixAttributeC:
                    case XmlBinaryNodeType.PrefixAttributeD:
                    case XmlBinaryNodeType.PrefixAttributeE:
                    case XmlBinaryNodeType.PrefixAttributeF:
                    case XmlBinaryNodeType.PrefixAttributeG:
                    case XmlBinaryNodeType.PrefixAttributeH:
                    case XmlBinaryNodeType.PrefixAttributeI:
                    case XmlBinaryNodeType.PrefixAttributeJ:
                    case XmlBinaryNodeType.PrefixAttributeK:
                    case XmlBinaryNodeType.PrefixAttributeL:
                    case XmlBinaryNodeType.PrefixAttributeM:
                    case XmlBinaryNodeType.PrefixAttributeN:
                    case XmlBinaryNodeType.PrefixAttributeO:
                    case XmlBinaryNodeType.PrefixAttributeP:
                    case XmlBinaryNodeType.PrefixAttributeQ:
                    case XmlBinaryNodeType.PrefixAttributeR:
                    case XmlBinaryNodeType.PrefixAttributeS:
                    case XmlBinaryNodeType.PrefixAttributeT:
                    case XmlBinaryNodeType.PrefixAttributeU:
                    case XmlBinaryNodeType.PrefixAttributeV:
                    case XmlBinaryNodeType.PrefixAttributeW:
                    case XmlBinaryNodeType.PrefixAttributeX:
                    case XmlBinaryNodeType.PrefixAttributeY:
                    case XmlBinaryNodeType.PrefixAttributeZ:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeA:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeB:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeC:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeD:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeE:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeF:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeG:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeH:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeI:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeJ:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeK:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeL:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeM:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeN:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeO:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeP:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeQ:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeR:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeS:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeT:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeU:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeV:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeW:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeX:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeY:
                    case XmlBinaryNodeType.PrefixDictionaryAttributeZ:
                    {
                        char prefixLetter;
                        bool isDictionaryAttribute = XmlBinaryNodeType.IsDictionaryAttributeNode(nodeType);
                        prefixLetter   = (char)((int)'a' + (int)nodeType - (int)(isDictionaryAttribute ? XmlBinaryNodeType.PrefixDictionaryAttributeA : XmlBinaryNodeType.PrefixAttributeA));
                        newNode.Prefix = new string(prefixLetter, 1);
                        if (isDictionaryAttribute)
                        {
                            newNode.DictionaryLocalName = ReadDictionaryString();
                        }
                        else
                        {
                            newNode.LocalName = ReadString(0);
                        }
                        int oldDepth = depth;
                        depth++;
                        Parse(ref newNode, true);
                        if (depth != (oldDepth + 1))
                        {
                            ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                        }
                        depth--;
                        if (newNode.Children.Count != 1)
                        {
                            throw new ArgumentException("Error, attribute nodes must have exactly one child, at offset " + offset);
                        }
                    }
                    break;

                    case XmlBinaryNodeType.Array:
                    {
                        int oldDepth = depth;
                        depth++;
                        ParseArray(newNode);
                        if (depth != oldDepth)
                        {
                            ThrowIncorrectDepthException("After " + XmlBinaryNodeType.GetNodeName(nodeType), oldDepth);
                        }
                    }
                    break;

                    default:
                        throw new ArgumentException(String.Format("Error, the test is not ready to handle the type {0:X2} ({1}) yet", nodeType, XmlBinaryNodeType.GetNodeName(nodeType)));
                    }
                }
            }
        }
 private void Parse(ref XmlBinaryNode parent, bool insideAttribute)
 {
     Parse(ref parent, insideAttribute, false);
 }
 private void Parse(ref XmlBinaryNode parent)
 {
     Parse(ref parent, false, false);
 }
        private void ParseArray(XmlBinaryNode parent)
        {
            Parse(ref parent, false, true);
            if ((offset + 1) >= xmlDoc.Length)
            {
                ThrowOffsetException("Inside array");
            }
            byte arrayNodeType = xmlDoc[offset];

            offset++;
            int elementCount = ReadMB32();

            parent.ArrayElements = new BinaryArrayElements(arrayNodeType, elementCount);
            for (int i = 0; i < elementCount; i++)
            {
                switch (arrayNodeType)
                {
                case XmlBinaryNodeType.BoolTextWithEndElement:
                    if (i == 0)
                    {
                        parent.ArrayElements.BoolArray = new bool[elementCount];
                    }
                    if (offset >= xmlDoc.Length)
                    {
                        ThrowOffsetException("Error in BoolArray");
                    }
                    parent.ArrayElements.BoolArray[i] = (xmlDoc[offset] != 0x00);
                    offset++;
                    break;

                case XmlBinaryNodeType.DateTimeTextWithEndElement:
                    if (i == 0)
                    {
                        parent.ArrayElements.DateTimeArray = new DateTime[elementCount];
                    }
                    parent.ArrayElements.DateTimeArray[i] = ReadDateTime();
                    break;

                case XmlBinaryNodeType.DecimalTextWithEndElement:
                    if (i == 0)
                    {
                        parent.ArrayElements.DecimalArray = new decimal[elementCount];
                    }
                    parent.ArrayElements.DecimalArray[i] = ReadDecimal();
                    break;

                case XmlBinaryNodeType.DoubleTextWithEndElement:
                    if (i == 0)
                    {
                        parent.ArrayElements.DoubleArray = new double[elementCount];
                    }
                    parent.ArrayElements.DoubleArray[i] = ReadDouble();
                    break;

                case XmlBinaryNodeType.GuidTextWithEndElement:
                    if (i == 0)
                    {
                        parent.ArrayElements.GuidArray = new Guid[elementCount];
                    }
                    parent.ArrayElements.GuidArray[i] = ReadGuid();
                    break;

                case XmlBinaryNodeType.Int16TextWithEndElement:
                    if (i == 0)
                    {
                        parent.ArrayElements.ShortArray = new short[elementCount];
                    }
                    parent.ArrayElements.ShortArray[i] = (short)ReadInt(2);
                    break;

                case XmlBinaryNodeType.Int32TextWithEndElement:
                    if (i == 0)
                    {
                        parent.ArrayElements.IntArray = new int[elementCount];
                    }
                    parent.ArrayElements.IntArray[i] = ReadInt(4);
                    break;

                case XmlBinaryNodeType.Int64TextWithEndElement:
                    if (i == 0)
                    {
                        parent.ArrayElements.LongArray = new long[elementCount];
                    }
                    parent.ArrayElements.LongArray[i] = ReadLong();
                    break;

                case XmlBinaryNodeType.FloatTextWithEndElement:
                    if (i == 0)
                    {
                        parent.ArrayElements.FloatArray = new float[elementCount];
                    }
                    parent.ArrayElements.FloatArray[i] = ReadFloat();
                    break;

                case XmlBinaryNodeType.TimeSpanTextWithEndElement:
                    if (i == 0)
                    {
                        parent.ArrayElements.TimeSpanArray = new TimeSpan[elementCount];
                    }
                    parent.ArrayElements.TimeSpanArray[i] = TimeSpan.FromTicks(ReadLong());
                    break;

                default:
                    throw new ArgumentException(String.Format("Invalid array node type: {0:X2} - {1}",
                                                              arrayNodeType, XmlBinaryNodeType.GetNodeName(arrayNodeType)));
                }
            }
            if (XmlBinaryNodeType.IsTextNodeWithEndElement(arrayNodeType))
            {
                depth--;
            }
        }
        private void ParseContentNode(XmlBinaryNode parent)
        {
            byte nodeType = xmlDoc[offset];

            offset++;
            XmlBinaryNode newNode = new XmlBinaryNode(nodeType, depth);

            parent.AddChild(newNode);
            switch (nodeType)
            {
            case XmlBinaryNodeType.Chars8Text:
            case XmlBinaryNodeType.Chars8TextWithEndElement:
                newNode.Text = ReadString(8);
                break;

            case XmlBinaryNodeType.Chars16Text:
            case XmlBinaryNodeType.Chars16TextWithEndElement:
                newNode.Text = ReadString(16);
                break;

            case XmlBinaryNodeType.Chars32Text:
            case XmlBinaryNodeType.Chars32TextWithEndElement:
                newNode.Text = ReadString(32);
                break;

            case XmlBinaryNodeType.UnicodeChars8Text:
            case XmlBinaryNodeType.UnicodeChars8TextWithEndElement:
            case XmlBinaryNodeType.UnicodeChars16Text:
            case XmlBinaryNodeType.UnicodeChars16TextWithEndElement:
            case XmlBinaryNodeType.UnicodeChars32Text:
            case XmlBinaryNodeType.UnicodeChars32TextWithEndElement:
            {
                int unicodeTextLenSize = 0;
                switch (nodeType)
                {
                case XmlBinaryNodeType.UnicodeChars8Text:
                case XmlBinaryNodeType.UnicodeChars8TextWithEndElement:
                    unicodeTextLenSize = 1;
                    break;

                case XmlBinaryNodeType.UnicodeChars16Text:
                case XmlBinaryNodeType.UnicodeChars16TextWithEndElement:
                    unicodeTextLenSize = 2;
                    break;

                case XmlBinaryNodeType.UnicodeChars32Text:
                case XmlBinaryNodeType.UnicodeChars32TextWithEndElement:
                    unicodeTextLenSize = 4;
                    break;
                }
                int unicodeTextLength = ReadInt(unicodeTextLenSize);
                if ((offset + unicodeTextLength) > xmlDoc.Length)
                {
                    ThrowOffsetException("Error reading UnicodeCharsXText");
                }
                byte[] temp = new byte[unicodeTextLength];
                Buffer.BlockCopy(xmlDoc, offset, temp, 0, unicodeTextLength);
                newNode.Text = unicodeEncoding.GetString(temp, 0, temp.Length);
                offset      += unicodeTextLength;
            }
            break;

            case XmlBinaryNodeType.Bytes8Text:
            case XmlBinaryNodeType.Bytes8TextWithEndElement:
            case XmlBinaryNodeType.Bytes16Text:
            case XmlBinaryNodeType.Bytes16TextWithEndElement:
            case XmlBinaryNodeType.Bytes32Text:
            case XmlBinaryNodeType.Bytes32TextWithEndElement:
            {
                int byteArrayLenSize = 0;
                switch (nodeType)
                {
                case XmlBinaryNodeType.Bytes8Text:
                case XmlBinaryNodeType.Bytes8TextWithEndElement:
                    byteArrayLenSize = 1;
                    break;

                case XmlBinaryNodeType.Bytes16Text:
                case XmlBinaryNodeType.Bytes16TextWithEndElement:
                    byteArrayLenSize = 2;
                    break;

                case XmlBinaryNodeType.Bytes32Text:
                case XmlBinaryNodeType.Bytes32TextWithEndElement:
                    byteArrayLenSize = 4;
                    break;
                }
                int byteArrayLength = ReadInt(byteArrayLenSize);
                if ((offset + byteArrayLength) > xmlDoc.Length)
                {
                    ThrowOffsetException("Error reading BytesXText");
                }
                newNode.Bytes = new byte[byteArrayLength];
                Buffer.BlockCopy(xmlDoc, offset, newNode.Bytes, 0, byteArrayLength);
                offset += byteArrayLength;
            }
            break;

            case XmlBinaryNodeType.Int8Text:
            case XmlBinaryNodeType.Int8TextWithEndElement:
                newNode.IntValue = ReadInt(1);
                break;

            case XmlBinaryNodeType.Int16Text:
            case XmlBinaryNodeType.Int16TextWithEndElement:
                newNode.IntValue = ReadInt(2);
                break;

            case XmlBinaryNodeType.Int32Text:
            case XmlBinaryNodeType.Int32TextWithEndElement:
                newNode.IntValue = ReadInt(4);
                break;

            case XmlBinaryNodeType.Int64Text:
            case XmlBinaryNodeType.Int64TextWithEndElement:
            case XmlBinaryNodeType.UInt64Text:
            case XmlBinaryNodeType.UInt64TextWithEndElement:
                newNode.LongValue = ReadLong();
                break;

            case XmlBinaryNodeType.FloatText:
            case XmlBinaryNodeType.FloatTextWithEndElement:
                newNode.FloatValue = ReadFloat();
                break;

            case XmlBinaryNodeType.DoubleText:
            case XmlBinaryNodeType.DoubleTextWithEndElement:
                newNode.DoubleValue = ReadDouble();
                break;

            case XmlBinaryNodeType.DecimalText:
            case XmlBinaryNodeType.DecimalTextWithEndElement:
                newNode.DecimalValue = ReadDecimal();
                break;

            case XmlBinaryNodeType.DateTimeText:
            case XmlBinaryNodeType.DateTimeTextWithEndElement:
                newNode.DateTimeValue = ReadDateTime();
                break;

            case XmlBinaryNodeType.TimeSpanText:
            case XmlBinaryNodeType.TimeSpanTextWithEndElement:
                newNode.TimeSpanValue = TimeSpan.FromTicks(ReadLong());
                break;

            case XmlBinaryNodeType.EmptyText:
            case XmlBinaryNodeType.EmptyTextWithEndElement:
                newNode.Text = "";
                break;

            case XmlBinaryNodeType.ZeroText:
            case XmlBinaryNodeType.ZeroTextWithEndElement:
                newNode.Text = "0";
                break;

            case XmlBinaryNodeType.OneText:
            case XmlBinaryNodeType.OneTextWithEndElement:
                newNode.Text = "1";
                break;

            case XmlBinaryNodeType.TrueText:
            case XmlBinaryNodeType.TrueTextWithEndElement:
                newNode.Text = "true";
                break;

            case XmlBinaryNodeType.FalseText:
            case XmlBinaryNodeType.FalseTextWithEndElement:
                newNode.Text = "false";
                break;

            case XmlBinaryNodeType.DictionaryText:
            case XmlBinaryNodeType.DictionaryTextWithEndElement:
                newNode.DictionaryText = ReadDictionaryString();
                break;

            case XmlBinaryNodeType.GuidText:
            case XmlBinaryNodeType.GuidTextWithEndElement:
                newNode.GuidValue = ReadGuid();
                break;

            case XmlBinaryNodeType.UniqueIdText:
            case XmlBinaryNodeType.UniqueIdTextWithEndElement:
            {
                byte[] uniqueIdBytes = new byte[16];
                if ((offset + uniqueIdBytes.Length) > xmlDoc.Length)
                {
                    ThrowOffsetException("Error reading UniqueId");
                }
                Buffer.BlockCopy(xmlDoc, offset, uniqueIdBytes, 0, uniqueIdBytes.Length);
                newNode.UniqueIdValue = new UniqueId(uniqueIdBytes);
                offset += uniqueIdBytes.Length;
            }
            break;

            case XmlBinaryNodeType.StartListTextWithEndElement:
                throw new ArgumentException("StartListTextWithEndElement is an invalid node!");

            case XmlBinaryNodeType.StartListText:
            {
                depth++;
                ParseList(newNode);
                depth--;
            }
            break;

            default:
                throw new ArgumentException(String.Format("Error, the test is not ready to handle the type {0:X2} ({1}) yet", nodeType, XmlBinaryNodeType.GetNodeName(nodeType)));
            }
        }
示例#15
0
        private void AddTreeNode(TreeNode rootNode, XmlBinaryNode node)
        {
            TreeNode childNode = rootNode.Nodes.Add(node.ToString(this.staticDictionary, this.readerSession, false));
            foreach (XmlBinaryNode child in node.Children)
            {
                this.AddTreeNode(childNode, child);
            }

            if (node.NodeType == XmlBinaryNodeType.Array)
            {
                Array elements = null;
                BinaryArrayElements arrayElements = node.ArrayElements;
                byte nodeType = arrayElements.NodeType;
                string nodeTypeName = XmlBinaryNodeType.GetNodeName((byte)(nodeType & 0xFE));
                switch (arrayElements.NodeType)
                {
                    case XmlBinaryNodeType.Int16Text:
                    case XmlBinaryNodeType.Int16TextWithEndElement:
                        elements = arrayElements.ShortArray;
                        break;
                    case XmlBinaryNodeType.Int32Text:
                    case XmlBinaryNodeType.Int32TextWithEndElement:
                        elements = arrayElements.IntArray;
                        break;
                    case XmlBinaryNodeType.Int64Text:
                    case XmlBinaryNodeType.Int64TextWithEndElement:
                        elements = arrayElements.LongArray;
                        break;
                    case XmlBinaryNodeType.BoolText:
                    case XmlBinaryNodeType.BoolTextWithEndElement:
                        elements = arrayElements.BoolArray;
                        break;
                    case XmlBinaryNodeType.DateTimeText:
                    case XmlBinaryNodeType.DateTimeTextWithEndElement:
                        elements = arrayElements.DateTimeArray;
                        break;
                    case XmlBinaryNodeType.DecimalText:
                    case XmlBinaryNodeType.DecimalTextWithEndElement:
                        elements = arrayElements.DecimalArray;
                        break;
                    case XmlBinaryNodeType.DoubleText:
                    case XmlBinaryNodeType.DoubleTextWithEndElement:
                        elements = arrayElements.DoubleArray;
                        break;
                    case XmlBinaryNodeType.FloatText:
                    case XmlBinaryNodeType.FloatTextWithEndElement:
                        elements = arrayElements.FloatArray;
                        break;
                    case XmlBinaryNodeType.GuidText:
                    case XmlBinaryNodeType.GuidTextWithEndElement:
                        elements = arrayElements.GuidArray;
                        break;
                    case XmlBinaryNodeType.TimeSpanText:
                    case XmlBinaryNodeType.TimeSpanTextWithEndElement:
                        elements = arrayElements.TimeSpanArray;
                        break;
                }

                if (elements != null)
                {
                    if (nodeTypeName.EndsWith("Text"))
                    {
                        nodeTypeName = nodeTypeName.Substring(0, nodeTypeName.Length - 4);
                    }

                    foreach (var item in elements)
                    {
                        rootNode.Nodes.Add(string.Format(CultureInfo.InvariantCulture, "({0}) {1}", nodeTypeName, item));
                    }
                }
            }
        }
示例#16
0
 private void PopulateTreeView(XmlBinaryNode binaryNode)
 {
     TreeNode rootNode = this.tvBinaryFile.Nodes.Add(binaryNode.ToString(this.staticDictionary, this.readerSession, false));
     foreach (XmlBinaryNode child in binaryNode.Children)
     {
         AddTreeNode(rootNode, child);
     }
 }