示例#1
0
 public void WriteByte(long index, byte value)
 {
     try
     {
         long            num;
         DataBlock       dataBlock = this.GetDataBlock(index, out num);
         MemoryDataBlock block2    = dataBlock as MemoryDataBlock;
         if (block2 != null)
         {
             block2.Data[(int)((IntPtr)(index - num))] = value;
         }
         else
         {
             FileDataBlock block = (FileDataBlock)dataBlock;
             if ((num == index) && (dataBlock.PreviousBlock != null))
             {
                 MemoryDataBlock previousBlock = dataBlock.PreviousBlock as MemoryDataBlock;
                 if (previousBlock != null)
                 {
                     previousBlock.AddByteToEnd(value);
                     block.RemoveBytesFromStart(1L);
                     if (block.Length == 0L)
                     {
                         this._dataMap.Remove(block);
                     }
                     return;
                 }
             }
             if ((((num + block.Length) - 1L) == index) && (dataBlock.NextBlock != null))
             {
                 MemoryDataBlock nextBlock = dataBlock.NextBlock as MemoryDataBlock;
                 if (nextBlock != null)
                 {
                     nextBlock.AddByteToStart(value);
                     block.RemoveBytesFromEnd(1L);
                     if (block.Length == 0L)
                     {
                         this._dataMap.Remove(block);
                     }
                     return;
                 }
             }
             FileDataBlock newBlock = null;
             if (index > num)
             {
                 newBlock = new FileDataBlock(block.FileOffset, index - num);
             }
             FileDataBlock block7 = null;
             if (index < ((num + block.Length) - 1L))
             {
                 block7 = new FileDataBlock(((block.FileOffset + index) - num) + 1L, block.Length - ((index - num) + 1L));
             }
             dataBlock = this._dataMap.Replace(dataBlock, new MemoryDataBlock(value));
             if (newBlock != null)
             {
                 this._dataMap.AddBefore(dataBlock, newBlock);
             }
             if (block7 != null)
             {
                 this._dataMap.AddAfter(dataBlock, block7);
             }
         }
     }
     finally
     {
         this.OnChanged(EventArgs.Empty);
     }
 }
示例#2
0
 public void WriteByte(long index, byte value)
 {
     try
     {
         long            blockOffset;
         DataBlock       dataBlock        = GetDataBlock(index, out blockOffset);
         MemoryDataBlock memoryDataBlock1 = dataBlock as MemoryDataBlock;
         if (memoryDataBlock1 != null)
         {
             memoryDataBlock1.Data[index - blockOffset] = value;
         }
         else
         {
             FileDataBlock fileDataBlock1 = (FileDataBlock)dataBlock;
             if (blockOffset == index && dataBlock.PreviousBlock != null)
             {
                 MemoryDataBlock memoryDataBlock2 = dataBlock.PreviousBlock as MemoryDataBlock;
                 if (memoryDataBlock2 != null)
                 {
                     memoryDataBlock2.AddByteToEnd(value);
                     fileDataBlock1.RemoveBytesFromStart(1L);
                     if (fileDataBlock1.Length != 0L)
                     {
                         return;
                     }
                     _dataMap.Remove((DataBlock)fileDataBlock1);
                     return;
                 }
             }
             if (blockOffset + fileDataBlock1.Length - 1L == index && dataBlock.NextBlock != null)
             {
                 MemoryDataBlock memoryDataBlock2 = dataBlock.NextBlock as MemoryDataBlock;
                 if (memoryDataBlock2 != null)
                 {
                     memoryDataBlock2.AddByteToStart(value);
                     fileDataBlock1.RemoveBytesFromEnd(1L);
                     if (fileDataBlock1.Length != 0L)
                     {
                         return;
                     }
                     _dataMap.Remove((DataBlock)fileDataBlock1);
                     return;
                 }
             }
             FileDataBlock fileDataBlock2 = (FileDataBlock)null;
             if (index > blockOffset)
             {
                 fileDataBlock2 = new FileDataBlock(fileDataBlock1.FileOffset, index - blockOffset);
             }
             FileDataBlock fileDataBlock3 = (FileDataBlock)null;
             if (index < blockOffset + fileDataBlock1.Length - 1L)
             {
                 fileDataBlock3 = new FileDataBlock(fileDataBlock1.FileOffset + index - blockOffset + 1L, fileDataBlock1.Length - (index - blockOffset + 1L));
             }
             DataBlock block = _dataMap.Replace(dataBlock, (DataBlock) new MemoryDataBlock(value));
             if (fileDataBlock2 != null)
             {
                 _dataMap.AddBefore(block, (DataBlock)fileDataBlock2);
             }
             if (fileDataBlock3 == null)
             {
                 return;
             }
             _dataMap.AddAfter(block, (DataBlock)fileDataBlock3);
         }
     }
     finally
     {
         OnChanged(EventArgs.Empty);
     }
 }