//-------------------------------------------------
        public bool ReadBlock(Guid BlockID_in, ref Hashtable BlockTags_out, ref byte[] Bytes_out)
        {
            if ((this._Stream == null))
            {
                return(false);
            }
            if ((this._Blocks == null))
            {
                return(false);
            }
            int ndx = 0;

            if (!this.Internal_FindBlock(BlockID_in, ref ndx))
            {
                return(false);
            }
            StreamControlBlock BLK = (StreamControlBlock)this._Blocks[ndx];

            BlockTags_out = BlockStream.CloneObject <Hashtable>(BLK.Tags);
            try
            {
                this._Stream.Seek(this._Header.DataOffset + BLK.Offset, SeekOrigin.Begin);
                byte[] inbytes = new byte[BLK.Length];
                this._Stream.Read(inbytes, 0, inbytes.Length);
                if (!this._DecodeBytes(BlockTags_out, inbytes, ref Bytes_out))
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(true);
        }
 //-------------------------------------------------
 public StreamControlBlock(Guid ID_in, long Offset_in, int Length_in, Hashtable Tags_in)
 {
     this.ID     = ID_in;
     this.Offset = Offset_in;
     this.Length = Length_in;
     this.Tags   = BlockStream.CloneObject <Hashtable>(Tags_in);
     return;
 }
        //-------------------------------------------------
        public bool WriteBlock(Guid BlockID_in, Hashtable BlockTags_in, byte[] Bytes_in)
        {
            if ((this._Stream == null))
            {
                return(false);
            }
            if (!this._Stream.CanWrite)
            {
                return(false);
            }
            if ((this._Blocks == null))
            {
                return(false);
            }
            int ndx = 0;

            if (this.Internal_FindBlock(BlockID_in, ref ndx))
            {
                // Free Existing Block
                if (!this.Internal_FreeBlock(ndx))
                {
                    return(false);
                }
            }
            // Encode Block
            byte[] outbytes = { };
            if (!this._EncodeBytes(BlockTags_in, Bytes_in, ref outbytes))
            {
                return(false);
            }
            // Allocate a New Block
            if (!this.Internal_AllocateBlock(BlockID_in, outbytes.Length, ref ndx))
            {
                return(false);
            }
            StreamControlBlock BLK = (StreamControlBlock)this._Blocks[ndx];

            try
            {
                this._Stream.Seek(this._Header.DataOffset + BLK.Offset, SeekOrigin.Begin);
                this._Stream.Write(outbytes, 0, outbytes.Length);
                BLK.Tags          = BlockStream.CloneObject <Hashtable>(BlockTags_in);
                this._BlocksDirty = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(true);
        }
        //-------------------------------------------------
        public void SetBlockTags(Guid BlockID_in, Hashtable Tags_in)
        {
            int ndx = 0;
            StreamControlBlock BLK;

            if (!Internal_FindBlock(BlockID_in, ref ndx))
            {
                return;
            }
            BLK               = (StreamControlBlock)this._Blocks[ndx];
            BLK.Tags          = BlockStream.CloneObject <Hashtable>(Tags_in);
            this._BlocksDirty = true;
            return;
        }
Ejemplo n.º 5
0
 //---------------------------------------------------------------------
 public BlockStreamFileSystem(string ThisFileName)
 {
     this._BlockStream = new BlockStream();
     this._BlockStream.OpenFile(ThisFileName);
     return;
 }