/// <summary> /// Updates the data index located in the data index file. /// </summary> /// <param name="dataIndex">The changed data index to update.</param> public void UpdateIndex(BlobIndex dataIndex) { // add the index to the dataindex file. _binaryWriter.BaseStream.Position = dataIndex.Position; _binaryWriter.Write(dataIndex.GetBytes()); _binaryWriter.Flush(); _cache.Clear(); }
/// <summary> /// Adds the Data Index to the Data Index file. /// WARNING: This function does not check for duplicates and can cause problems with duplicate Data Index's. /// Only use AddIndex if you have some other method of making sure the Data Index's being stored are unique. /// e.g Using an Auto incrementing Search Key (Primary Key). Using AddIndexCheckForDuplicate is slower but makes sure there is no duplicates. /// Note: The Data Index is the pointer to the record in the entites data file. /// </summary> public void AddIndex(BlobIndex dataIndex) { // add the index to the dataindex file. _binaryWriter.BaseStream.Position = this.FileSize; _binaryWriter.Write(dataIndex.GetBytes()); _binaryWriter.Flush(); // advance the file size on. its better that we do it than call the length all the time as its quicker. this.FileSize += 32; //_cache.Clear(); }
/// <summary> /// Adds an index to the Data Index file. /// Overwrites the first data index found with a 0 for its document key. /// </summary> public void AddIndexOverwriteDeleted(BlobIndex dataIndex) { // add the index to the dataindex file. _binaryReader.BaseStream.Position = 0; while (_binaryReader.BaseStream.Position < this.FileSize) { // load the bytes, convert to index object and return byte[] dataIndexBytes = _binaryReader.ReadBytes(32); var existingBlobIndex = BlobIndex.Parse(dataIndexBytes); // check if null if (existingBlobIndex.DocumentKey == 0) { _binaryWriter.BaseStream.Position = _binaryReader.BaseStream.Position; _binaryWriter.Write(dataIndex.GetBytes()); _binaryWriter.Flush(); return; } } // not found so add to end. AddIndex(dataIndex); }