/// <summary> /// Read in all of the rows that have been cached /// </summary> /// <returns></returns> public List <object[]> ReadCachedRows() { AssertMx.IsTrue(File.Exists(CacheFilePath), "CacheFilePath doesn't exist"); FileStream fs = File.Open(CacheFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryReader br = new BinaryReader(fs); List <object[]> cachedRows = new List <object[]>(); // in-memory buffer list of rows for (int ri = 0; ri < RowsWrittenToCache; ri++) { object[] vo = VoArray.ReadBinaryVoArray(br, VoaLength); cachedRows.Add(vo); } br.Close(); // close reader and the underlying stream return(cachedRows); }
/// <summary> /// Try to get the row at the given index from the buffer or cache /// </summary> /// <param name="ri"></param> /// <returns></returns> /// public object[] GetRow( int ri) { object[] vo = null; if (ri < 0 || ri >= TotalRowCount) { string msg = string.Format("Row {0} not in cache or buffer (cacheSize: {1}, bufferSize: {2})", ri, RowsWrittenToCache, RowBuffer.Count); throw new InvalidDataException(msg); } // See if in buffer if (ri >= RowsWrittenToCache) { vo = (object[])RowBuffer[ri - RowsWrittenToCache]; if (DebugCaching) { DebugLog.Message(string.Format("Row: {0} in Buffer (cacheSize: {1}, bufferSize: {2})", ri, RowsWrittenToCache, RowBuffer.Count)); } return(vo); } // Get from cache if (ri < CacheReaderPosition + 1) // if already read past this then close current cursor { CloseCacheReader(); } if (CacheReader == null) // need to open reader? { AssertMx.IsNotNull(CacheWriter, "CacheWriter"); AssertMx.IsTrue(File.Exists(CacheFilePath), "CacheFilePath doesn't exist"); FileStream fs = File.Open(CacheFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); CacheReader = new BinaryReader(fs); CacheReaderPosition = -1; if (DebugCaching) { DebugLog.Message("Opening cache reader"); } } while (CacheReaderPosition + 1 <= ri) // read rows until we get the one we want { vo = VoArray.ReadBinaryVoArray(CacheReader, VoaLength); CacheReaderPosition++; } CacheReaderPosition = ri; if (DebugCaching) { DebugLog.Message(string.Format("Row: {0} in Cache (cacheSize: {1}, bufferSize: {2})", ri, RowsWrittenToCache, RowBuffer.Count)); } return(vo); }