public byte[] ToByteArray()
        {
            var buffer = new byte[attributeHelper.GetEntityAttribute().Size];
            using (var stream = new MemoryStream(buffer))
            {
                var writer = new BinaryWriter(stream);
                var dataWriter = new VhdDataWriter(writer);
                dataWriter.WriteBytes(attributeHelper.GetAttribute(() => vhdFooter.Cookie).Offset, vhdFooter.Cookie.Data);

                dataWriter.WriteUInt(attributeHelper.GetAttribute(() => vhdFooter.Features).Offset, (uint)vhdFooter.Features);
                dataWriter.WriteInt(attributeHelper.GetAttribute(() => vhdFooter.FileFormatVersion).Offset,
                                    (int)vhdFooter.FileFormatVersion.Data);
                dataWriter.WriteLong(attributeHelper.GetAttribute(() => vhdFooter.HeaderOffset).Offset, vhdFooter.HeaderOffset);
                dataWriter.WriteTimeStamp(attributeHelper.GetAttribute(() => vhdFooter.TimeStamp).Offset, vhdFooter.TimeStamp);
                dataWriter.WriteBytes(attributeHelper.GetAttribute(() => vhdFooter.CreatorApplication).Offset,
                                      Encoding.ASCII.GetBytes(vhdFooter.CreatorApplication));
                dataWriter.WriteUInt(attributeHelper.GetAttribute(() => vhdFooter.CreatorVersion).Offset,
                                     vhdFooter.CreatorVersion.Data);
                dataWriter.WriteUInt(attributeHelper.GetAttribute(() => vhdFooter.CreatorHostOsType).Offset,
                                     (uint)vhdFooter.CreatorHostOsType);
                dataWriter.WriteLong(attributeHelper.GetAttribute(() => vhdFooter.PhsyicalSize).Offset, vhdFooter.PhsyicalSize);
                dataWriter.WriteLong(attributeHelper.GetAttribute(() => vhdFooter.VirtualSize).Offset, vhdFooter.VirtualSize);

                dataWriter.SetPosition(attributeHelper.GetAttribute(() => vhdFooter.DiskGeometry).Offset);
                WriteDiskGeometry(dataWriter, vhdFooter.DiskGeometry);

                dataWriter.WriteInt(attributeHelper.GetAttribute(() => vhdFooter.DiskType).Offset, (int)vhdFooter.DiskType);
                dataWriter.WriteGuid(attributeHelper.GetAttribute(() => vhdFooter.UniqueId).Offset, vhdFooter.UniqueId);
                dataWriter.WriteBoolean(attributeHelper.GetAttribute(() => vhdFooter.SavedState).Offset, vhdFooter.SavedState);
                dataWriter.WriteBytes(attributeHelper.GetAttribute(() => vhdFooter.Reserved).Offset, vhdFooter.Reserved);

                dataWriter.WriteUInt(attributeHelper.GetAttribute(() => vhdFooter.CheckSum).Offset, ComputeCheckSum(buffer));
            }
            return buffer;
        }
示例#2
0
        public byte[] ToByteArray()
        {
            var buffer = new byte[attributeHelper.GetEntityAttribute().Size];

            using (var stream = new MemoryStream(buffer))
            {
                var writer     = new BinaryWriter(stream);
                var dataWriter = new VhdDataWriter(writer);
                dataWriter.WriteBytes(attributeHelper.GetAttribute(() => vhdFooter.Cookie).Offset, vhdFooter.Cookie.Data);

                dataWriter.WriteUInt(attributeHelper.GetAttribute(() => vhdFooter.Features).Offset, (uint)vhdFooter.Features);
                dataWriter.WriteInt(attributeHelper.GetAttribute(() => vhdFooter.FileFormatVersion).Offset,
                                    (int)vhdFooter.FileFormatVersion.Data);
                dataWriter.WriteLong(attributeHelper.GetAttribute(() => vhdFooter.HeaderOffset).Offset, vhdFooter.HeaderOffset);
                dataWriter.WriteTimeStamp(attributeHelper.GetAttribute(() => vhdFooter.TimeStamp).Offset, vhdFooter.TimeStamp);
                dataWriter.WriteBytes(attributeHelper.GetAttribute(() => vhdFooter.CreatorApplication).Offset,
                                      Encoding.ASCII.GetBytes(vhdFooter.CreatorApplication));
                dataWriter.WriteUInt(attributeHelper.GetAttribute(() => vhdFooter.CreatorVersion).Offset,
                                     vhdFooter.CreatorVersion.Data);
                dataWriter.WriteUInt(attributeHelper.GetAttribute(() => vhdFooter.CreatorHostOsType).Offset,
                                     (uint)vhdFooter.CreatorHostOsType);
                dataWriter.WriteLong(attributeHelper.GetAttribute(() => vhdFooter.PhsyicalSize).Offset, vhdFooter.PhsyicalSize);
                dataWriter.WriteLong(attributeHelper.GetAttribute(() => vhdFooter.VirtualSize).Offset, vhdFooter.VirtualSize);

                dataWriter.SetPosition(attributeHelper.GetAttribute(() => vhdFooter.DiskGeometry).Offset);
                WriteDiskGeometry(dataWriter, vhdFooter.DiskGeometry);

                dataWriter.WriteInt(attributeHelper.GetAttribute(() => vhdFooter.DiskType).Offset, (int)vhdFooter.DiskType);
                dataWriter.WriteGuid(attributeHelper.GetAttribute(() => vhdFooter.UniqueId).Offset, vhdFooter.UniqueId);
                dataWriter.WriteBoolean(attributeHelper.GetAttribute(() => vhdFooter.SavedState).Offset, vhdFooter.SavedState);
                dataWriter.WriteBytes(attributeHelper.GetAttribute(() => vhdFooter.Reserved).Offset, vhdFooter.Reserved);

                dataWriter.WriteUInt(attributeHelper.GetAttribute(() => vhdFooter.CheckSum).Offset, ComputeCheckSum(buffer));
            }
            return(buffer);
        }
 private static void WriteDiskGeometry(VhdDataWriter dataWriter, DiskGeometry diskGeometry)
 {
     dataWriter.WriteInt16(diskGeometry.Cylinder);
     dataWriter.WriteByte(diskGeometry.Heads);
     dataWriter.WriteByte(diskGeometry.Sectors);
 }
示例#4
0
 private static void WriteDiskGeometry(VhdDataWriter dataWriter, DiskGeometry diskGeometry)
 {
     dataWriter.WriteInt16(diskGeometry.Cylinder);
     dataWriter.WriteByte(diskGeometry.Heads);
     dataWriter.WriteByte(diskGeometry.Sectors);
 }