public void CreateDataIndexGetBytesLengthOf32() { var dataIndex = new DataIndex(1, 1, 1, 50); var bytes = dataIndex.GetBytes(); int count = bytes.Length; Assert.AreEqual(32, count); }
public void CreateDataIndexGetBytesAndConvertBackToDataIndex() { // create the initial index and convert to bytes. var dataIndex = new DataIndex(1, 1, 1, 50); var bytes = dataIndex.GetBytes(); // convert the bytes back into a data index structure var newDataIndex = DataIndex.Parse(bytes); Assert.AreEqual(dataIndex.DocumentKey, newDataIndex.DocumentKey); Assert.AreEqual(dataIndex.Pointer, newDataIndex.Pointer); Assert.AreEqual(dataIndex.RecordLength, newDataIndex.RecordLength); }
/// <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(DataIndex dataIndex) { // add the index to the dataindex file. _binaryWriter.BaseStream.Position = dataIndex.Position; _binaryWriter.Write(dataIndex.GetBytes()); _binaryWriter.Flush(); _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(DataIndex 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 existingDataIndex = DataIndex.Parse(dataIndexBytes); // check if null if (existingDataIndex.DocumentKey == 0){ _binaryWriter.BaseStream.Position = _binaryReader.BaseStream.Position; _binaryWriter.Write(dataIndex.GetBytes()); _binaryWriter.Flush(); return; } } // not found so add to end. AddIndex(dataIndex); }
/// <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(DataIndex 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(); }