private bool TryDeserialize(TKey key, FirkinStream stream, out TValue value) { if (stream.Length > _hash.MaxFileSize) { var error = string.Format("Stream for key '{0}' was too large, length: {1}. Dictionary is likely corrupted!", key, stream.Length); _log.Warn(error); throw new CorruptDictionaryException(error); } value = _valueSerializer.Deserialize(stream); return(true); }
public IEnumerator <KeyValuePair <TKey, FirkinStream> > GetEnumerator() { KeyValuePair <TKey, KeyInfo>[] pairs; lock (_indexSyncRoot) { pairs = _index.ToArray(); } foreach (var pair in pairs) { IFirkinFile file; FirkinStream stream = null; if (pair.Value.ValueSize == 0) { // key has been deleted, skip it continue; } try { stream = _files[pair.Value.FileId].ReadValue(pair.Value); } catch { // this may fail, and that's fine, just means we may have to degrade to Get() call } if (stream == null) { if (pair.Value.ValueSize == 0) { // key was deleted while we tried to get it, skip it continue; } // try to get the key via Get() stream = Get(pair.Key); } if (stream != null) { yield return(new KeyValuePair <TKey, FirkinStream>(pair.Key, stream)); } } }