Ejemplo n.º 1
0
        internal static HeaderBlock Create(Mdf mdf)
        {
            var block = new HeaderBlock(mdf);

            block.Identifier          = "HD";
            block.Date                = "";
            block.Time                = "";
            block.Author              = "";
            block.Organization        = "";
            block.Project             = "";
            block.Subject             = "";
            block.TimerIdentification = "";

            return(block);
        }
Ejemplo n.º 2
0
        public Mdf(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanSeek)
            {
                throw new ArgumentException("stream");
            }

            Data          = stream;
            Data.Position = 0;
            IDBlock       = new IdentificationBlock(this);
            HDBlock       = new HeaderBlock(this);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Read MDF from stream.
        /// </summary>
        /// <param name="stream"></param>
        public Mdf(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanSeek)
            {
                throw new ArgumentException("stream");
            }

            Data          = stream;
            Data.Position = 0;

            DataGroups = new DataGroupCollection(this);
            IDBlock    = IdentificationBlock.Read(this, stream);
            HDBlock    = HeaderBlock.Read(this, stream);
        }
Ejemplo n.º 4
0
 public Mdf()
 {
     DataGroups = new DataGroupCollection(this);
     IDBlock    = IdentificationBlock.Create(this);
     HDBlock    = HeaderBlock.Create(this);
 }
Ejemplo n.º 5
0
        internal static HeaderBlock Read(Mdf mdf, Stream stream)
        {
            var block = new HeaderBlock(mdf);

            block.Read(stream);

            var data = new byte[block.Size - 4];
            var read = stream.Read(data, 0, data.Length);

            if (read != data.Length)
            {
                throw new FormatException();
            }

            block.DataGroupsCount = BitConverter.ToUInt16(data, 12);
            block.Date            = mdf.IDBlock.Encoding.GetString(data, 14, 10).Humanize();
            block.Time            = mdf.IDBlock.Encoding.GetString(data, 24, 8).Humanize();
            block.Author          = mdf.IDBlock.Encoding.GetString(data, 32, 32).Humanize();
            block.Organization    = mdf.IDBlock.Encoding.GetString(data, 64, 32).Humanize();
            block.Project         = mdf.IDBlock.Encoding.GetString(data, 96, 32).Humanize();
            block.Subject         = mdf.IDBlock.Encoding.GetString(data, 128, 32).Humanize();

            if (mdf.IDBlock.Version >= 320)
            {
                block.TimeStamp           = BitConverter.ToUInt64(data, 160);
                block.UTCTimeOffset       = BitConverter.ToInt16(data, 168);
                block.TimeQuality         = (TimeQuality)BitConverter.ToUInt16(data, 170);
                block.TimerIdentification = mdf.IDBlock.Encoding.GetString(data, 172, 32).Humanize();
            }
            else
            {
                block.TimeStamp           = 0;
                block.UTCTimeOffset       = 0;
                block.TimeQuality         = 0;
                block.TimerIdentification = "";
            }

            var ptrFirstDataGroup = BitConverter.ToUInt32(data, 0);
            var ptrTextBlock      = BitConverter.ToUInt32(data, 4);
            var ptrProgramBlock   = BitConverter.ToUInt32(data, 8);

            // Check if ptrTextBlock is null
            if (ptrTextBlock != 0)
            {
                stream.Position   = ptrTextBlock;
                block.FileComment = TextBlock.Read(mdf, stream);
            }

            // Check if ptrProgramBlock is null
            if (ptrProgramBlock != 0)
            {
                stream.Position    = ptrProgramBlock;
                block.ProgramBlock = ProgramBlock.Read(mdf, stream);
            }

            // Check if ptrFirstDataGroup is null
            if (ptrFirstDataGroup != 0)
            {
                mdf.DataGroups.Read(DataGroupBlock.Read(mdf, stream, ptrFirstDataGroup));
            }

            return(block);
        }