public PackedFile(string documentsPath, string metadataPath, JournalWriter journalWriter, IFileSystem fileSystem) { memStream = new MemoryStream(); memWriter = new BinaryWriter(memStream); this.documentsPath = documentsPath; pagesPath = metadataPath; this.journalWriter = journalWriter; this.fileSystem = fileSystem; documentsStream = fileSystem.OpenFileStream(documentsPath); pagesStream = fileSystem.OpenFileStream(pagesPath); if (pagesStream.Length >= 1) { if (documentsStream.Length < 1) { throw new CorruptionException("Documents is empty but metadata isn't"); } ReadFileHeader(pagesStream); ReadFileHeader(documentsStream); } else { documentsStream.WriteByte(0); pagesStream.WriteByte(0); } documentsReader = new BinaryReader(documentsStream); pagesReader = new BinaryReader(pagesStream); }
public DocumentCollection(PackedFile packedFile, IndexFactory indexFactory, byte[] key, JournalPlayer journalPlayer, JournalWriter journalWriter) { transactionLockObject = new object(); EnsureValidKey(key); documentType = typeof(TDocument); try { journalPlayer.Play(); SerializerReflectionCache.AddTypes(typeof(MetadataDocument), documentType); this.packedFile = packedFile; this.journalPlayer = journalPlayer; this.journalWriter = journalWriter; byte[] initializationVector; if (packedFile.IsEmpty) { initializationVector = CryptoRandomNumberGenerator.GenerateBytes(16u); journalWriter.Start(); WriteMetadataDocument(initializationVector); journalWriter.Finish(); journalPlayer.Play(); } else { KeyValuePair <uint, byte[]> keyValuePair = packedFile.Documents.First(); metadataDocumentId = keyValuePair.Key; MetadataDocument metadataDocument = BinarySerializer.Deserialize <MetadataDocument>(keyValuePair.Value); initializationVector = metadataDocument.InitializationVector; } encryptor = new Aes256Encryptor(key, initializationVector); fieldIndexes = new FieldIndexes <TDocument>(indexFactory, encryptor); } catch (Exception) { journalWriter.Discard(); throw; } }
public Index(string path, IFixedSizeIndexValueType <TEntryValue> valueType, Aes256Encryptor encryptor, IFileSystem fileSystem, JournalWriter journalWriter) { this.path = path; this.valueType = valueType; this.encryptor = encryptor; this.fileSystem = fileSystem; this.journalWriter = journalWriter; uint size = valueType.Size; entrySize = 4 + size; fileStream = fileSystem.OpenFileStream(path); serializedBytes = new byte[entrySize]; serializerStream = new MemoryStream(serializedBytes); serializerWriter = new BinaryWriter(serializerStream); if (fileStream.Length >= 1) { int num = fileStream.ReadByte(); if (num != 0) { throw new CorruptionException("Unsupported format version: " + num); } uint num2 = (uint)(fileStream.Length - 1); Count = num2 / entrySize; if (num2 % entrySize != 0) { uint entryPosition = GetEntryPosition(Count); fileStream.SetLength(entryPosition); } } else { fileStream.SetLength(1L); fileStream.WriteByte(0); } fileStreamReader = new BinaryReader(fileStream); }
public IndexFactory(string dir, JournalWriter journalWriter, IFileSystem fileSystem) { this.dir = dir; this.journalWriter = journalWriter; this.fileSystem = fileSystem; }