private void DumpTemplate(ref byte *r)
        {
            var entry = (TemplateEntry *)r;

            VerifyMagic(0, entry->Magic, CrimsonTags.TEMP);

            writer.PushDictScope(
                "Template(params={0}, props={1}, id={2}, flags={3})",
                entry->NumParams, entry->NumProperties, entry->TemplateId, entry->Flags);

            XDocument doc = BinXmlReader.Read(buffer.mappedFile.CreateViewStream((byte *)&entry[1] - begin, entry->Length, MemoryMappedFileAccess.Read));

            writer.WriteStringBlock("BinXml", doc.ToString());

            writer.PushListScope("Properties");
            var properties       = (PropertyEntry *)(begin + entry->PropertyOffset);
            var structProperties = (PropertyEntry *)(begin + entry->PropertyOffset + entry->NumParams * Marshal.SizeOf <PropertyEntry>());

            for (uint i = 0; i < entry->NumParams; ++i)
            {
                DumpProperty(&properties[i], &structProperties);
            }

            writer.PopScope();

            writer.PopScope();
        }
Exemplo n.º 2
0
        public void DisposeLeavesStreamOpen()
        {
            var substitutionTypes = new List <BinXmlType>();
            var input             = new MemoryStream();
            var reader            = new BinXmlReader(input, substitutionTypes);

            reader.Dispose();

            Assert.True(input.CanRead);
            input.Dispose();
            Assert.False(input.CanRead);
        }
Exemplo n.º 3
0
        public void ReadSimple()
        {
            var substitutionTypes = new List <BinXmlType>();
            var input             = CreateInput(new byte[] {
                // FragmentHeader
                Token.FragmentHeaderToken,
                Constants.MajorVersion,
                Constants.MinorVersion,
                0, /*flags*/

                Token.EndOfFragmentToken
            });

            var doc = BinXmlReader.Read(input, substitutionTypes);

            Assert.Equal("", doc.ToString());
        }
Exemplo n.º 4
0
        public void FragmentHeader_UnsupportedFlags()
        {
            var substitutionTypes = new List <BinXmlType>();
            var input             = CreateInput(new byte[] {
                // FragmentHeader
                Token.FragmentHeaderToken,
                Constants.MajorVersion,
                Constants.MinorVersion,
                1, /*flags*/

                Token.EndOfFragmentToken
            });

            var ex = Assert.Throws <InvalidOperationException>(
                () => BinXmlReader.Read(input, substitutionTypes));

            Assert.Contains("Unsupported flags", ex.Message);
        }
Exemplo n.º 5
0
        private Template ReadTemplate(BinaryReader r)
        {
            long offset = r.BaseStream.Position;

            ReadMagic(r, CrimsonTags.TEMP);
            uint length         = r.ReadUInt32();
            uint paramCount     = r.ReadUInt32();
            uint dataCount      = r.ReadUInt32();
            uint propertyOffset = r.ReadUInt32();
            uint flags          = r.ReadUInt32();
            Guid guid           = r.ReadGuid();

            var       types = new List <BinXmlType>();
            XDocument doc   = BinXmlReader.Read(r.BaseStream, types);

            r.BaseStream.Position = propertyOffset;

            string id = string.Format(
                CultureInfo.InvariantCulture, "template{0:X16}", offset);
            var template = new Template(id);

            long structPropertyOffset = propertyOffset + paramCount * Marshal.SizeOf <PropertyEntry>();

            for (uint i = 0; i < paramCount; ++i)
            {
                r.BaseStream.Position = propertyOffset + i * Marshal.SizeOf <PropertyEntry>();
                template.Properties.Add(ReadProperty(r, ref structPropertyOffset, true));
            }

            ResolvePropertyRefs(in guid, template.Properties);

            r.BaseStream.Position = offset + length;

            MarkObject(offset, template);
            return(template);
        }