public void Insert(TDocument document)
 {
     lock (transactionLockObject)
     {
         if (isDisposed)
         {
             throw new ObjectDisposedException("Can't use Insert() after Dispose() or Delete()");
         }
         if (isFieldIndexesInUse)
         {
             throw new InvalidOperationException("Can't use Insert() before disposing the enumerable from a FindDocumentIds call");
         }
         if (document == null)
         {
             if (DebugLogHandler != null)
             {
                 DebugLogHandler("Insert: null");
             }
             throw new ArgumentException("Document to insert can't be null", "document");
         }
         if (DebugLogHandler != null)
         {
             if (fields == null)
             {
                 fields = documentType.GetFields();
             }
             StringBuilder stringBuilder = new StringBuilder("Insert: document=\n");
             FieldInfo[]   array         = fields;
             foreach (FieldInfo fieldInfo in array)
             {
                 stringBuilder.Append(fieldInfo.Name);
                 stringBuilder.Append(" = ");
                 stringBuilder.Append(fieldInfo.GetValue(document));
                 stringBuilder.Append('\n');
             }
             DebugLogHandler(stringBuilder.ToString());
         }
         if (document.Id != 0)
         {
             throw new ArgumentException("Document already has an ID. Update Update() instead.");
         }
         byte[] document2 = SerializeAndEncrypt(document);
         journalWriter.Start();
         try
         {
             document.Id = packedFile.Insert(document2);
             fieldIndexes.Insert(document);
             journalWriter.Finish();
             journalPlayer.Play();
         }
         catch (Exception)
         {
             journalWriter.Discard();
             throw;
         }
     }
 }
        public void WriteEntryValue(TEntryValue entryValue, BinaryWriter writer, Aes256Encryptor encryptor)
        {
            serializationStream.Position = 0L;
            indexValueType.WriteEntryValue(entryValue, serializationWriter, encryptor);
            byte[] document = encryptor.Encrypt(serializationStream.ToArray());
            uint   value    = packedFile.Insert(document);

            writer.Write(value);
        }