Ejemplo n.º 1
0
        /// <summary>
        /// Create a Dragon tape block object.
        /// Note that it is possible to create illegal blocks using this method by providing an unsupported block type or an invalid
        /// checksum.  Use the <see cref="Validate">Validate</see> method to verify that the block is actually valid.
        /// For supported block types, the returned object will be of the appropriate type.
        /// </summary>
        /// <param name="blocktype">Block type idenfifier.</param>
        /// <param name="data">Array containing the block payload data, or <value>null</value> for no payload.</param>
        /// <param name="offset">Offset into the data array of first byte of block payload data.</param>
        /// <param name="length">Size of the block payload data.</param>
        /// <param name="checksum">Block checksum.</param>
        /// <returns>Dragon tape block object.</returns>
        public static DragonTapeBlock CreateBlock(DragonTapeBlockType blocktype, byte[] data, int offset, int length, int checksum)
        {
            DragonTapeBlock block = null;

            switch (blocktype)
            {
            case DragonTapeBlockType.Header:
                block = new DragonTapeHeaderBlock(data, offset, length, checksum);
                break;

            case DragonTapeBlockType.Data:
                block = new DragonTapeDataBlock(data, offset, length, checksum);
                break;

            case DragonTapeBlockType.EndOfFile:
                block = new DragonTapeEofBlock(data, offset, length, checksum);
                break;

            default:
                block = new DragonTapeBlock(blocktype);
                block.SetData(data, offset, length);
                block.Checksum = checksum;
                break;
            }

            return(block);
        }
Ejemplo n.º 2
0
        private void WriteDataBlocks(DragonFile file)
        {
            int  blocks     = (file.Length + 254) / 255;            // number of data blocks to write
            int  offset     = 0;
            bool firstblock = true;                                 // make sure to create a long leader for the first data block

            for (int i = 0; i < blocks; i++)
            {
                var block = new DragonTapeDataBlock(file.GetData(), offset, Math.Min(255, file.Length - offset));
                block.WriteBlock(Tape, !(firstblock || file.IsGapped));
                offset    += 255;
                firstblock = false;
            }
        }