public SequentialReaderStream(ArchiveList <TKey, TValue> archiveList, SortedTreeEngineReaderOptions readerOptions = null, SeekFilterBase <TKey> keySeekFilter = null, MatchFilterBase <TKey, TValue> keyMatchFilter = null, WorkerThreadSynchronization workerThreadSynchronization = null) { if (readerOptions is null) { readerOptions = SortedTreeEngineReaderOptions.Default; } if (keySeekFilter is null) { keySeekFilter = new SeekFilterUniverse <TKey>(); } if (keyMatchFilter is null) { keyMatchFilter = new MatchFilterUniverse <TKey, TValue>(); } if (workerThreadSynchronization is null) { m_ownsWorkerThreadSynchronization = true; workerThreadSynchronization = new WorkerThreadSynchronization(); } m_workerThreadSynchronization = workerThreadSynchronization; m_pointCount = 0; m_keySeekFilter = keySeekFilter; m_keyMatchFilter = keyMatchFilter; m_keyMatchIsUniverse = m_keyMatchFilter as MatchFilterUniverse <TKey, TValue> != null; if (readerOptions.Timeout.Ticks > 0) { m_timeout = new TimeoutOperation(); m_timeout.RegisterTimeout(readerOptions.Timeout, () => m_timedOut = true); } m_snapshot = archiveList.CreateNewClientResources(); m_snapshot.UpdateSnapshot(); m_tablesOrigList = new List <BufferedArchiveStream <TKey, TValue> >(); for (int x = 0; x < m_snapshot.Tables.Count(); x++) { ArchiveTableSummary <TKey, TValue> table = m_snapshot.Tables[x]; if (table != null) { if (table.Contains(keySeekFilter.StartOfRange, keySeekFilter.EndOfRange)) { try { m_tablesOrigList.Add(new BufferedArchiveStream <TKey, TValue>(x, table)); } catch (Exception e) { //ToDo: Make sure firstkey.tostring doesn't ever throw an exception. StringBuilder sb = new StringBuilder(); sb.AppendLine($"Archive ID {table.FileId}"); sb.AppendLine($"First Key {table.FirstKey.ToString()}"); sb.AppendLine($"Last Key {table.LastKey.ToString()}"); sb.AppendLine($"File Size {table.SortedTreeTable.BaseFile.ArchiveSize}"); sb.AppendLine($"File Name {table.SortedTreeTable.BaseFile.FilePath}"); Log.Publish(MessageLevel.Error, "Error while reading file", sb.ToString(), null, e); } } else { m_snapshot.Tables[x] = null; } } } m_sortedArchiveStreams = new CustomSortHelper <BufferedArchiveStream <TKey, TValue> >(m_tablesOrigList, IsLessThan); m_keySeekFilter.Reset(); if (m_keySeekFilter.NextWindow()) { SeekToKey(m_keySeekFilter.StartOfFrame); } else { Dispose(); } }
public SequentialReaderStream(ArchiveList <TKey, TValue> archiveList, SortedTreeEngineReaderOptions readerOptions = null, SeekFilterBase <TKey> keySeekFilter = null, MatchFilterBase <TKey, TValue> keyMatchFilter = null, WorkerThreadSynchronization workerThreadSynchronization = null) { if (readerOptions == null) { readerOptions = SortedTreeEngineReaderOptions.Default; } if (keySeekFilter == null) { keySeekFilter = new SeekFilterUniverse <TKey>(); } if (keyMatchFilter == null) { keyMatchFilter = new MatchFilterUniverse <TKey, TValue>(); } if (workerThreadSynchronization == null) { m_ownsWorkerThreadSynchronization = true; workerThreadSynchronization = new WorkerThreadSynchronization(); } m_workerThreadSynchronization = workerThreadSynchronization; m_pointCount = 0; m_keySeekFilter = keySeekFilter; m_keyMatchFilter = keyMatchFilter; m_keyMatchIsUniverse = (m_keyMatchFilter as MatchFilterUniverse <TKey, TValue>) != null; if (readerOptions.Timeout.Ticks > 0) { m_timeout = new TimeoutOperation(); m_timeout.RegisterTimeout(readerOptions.Timeout, () => m_timedOut = true); } m_snapshot = archiveList.CreateNewClientResources(); m_snapshot.UpdateSnapshot(); m_tablesOrigList = new List <BufferedArchiveStream <TKey, TValue> >(); for (int x = 0; x < m_snapshot.Tables.Count(); x++) { ArchiveTableSummary <TKey, TValue> table = m_snapshot.Tables[x]; if (table != null) { if (table.Contains(keySeekFilter.StartOfRange, keySeekFilter.EndOfRange)) { m_tablesOrigList.Add(new BufferedArchiveStream <TKey, TValue>(x, table)); } else { m_snapshot.Tables[x] = null; } } } m_sortedArchiveStreams = new CustomSortHelper <BufferedArchiveStream <TKey, TValue> >(m_tablesOrigList, IsLessThan); m_keySeekFilter.Reset(); if (m_keySeekFilter.NextWindow()) { SeekToKey(m_keySeekFilter.StartOfFrame); } else { Dispose(); } }