private static bool EncryptedDocumentsExist(DocumentDatabase database)
        {
            const int pageSize = 10;
            int       index    = 0;

            while (true)
            {
                var array = database.Documents.GetDocuments(index, index + pageSize, null, CancellationToken.None);
                if (array.Length == 0)
                {
                    // We've gone over all the documents in the database, and none of them are encrypted.
                    return(false);
                }

                if (array.All(x => EncryptionSettings.DontEncrypt(x.Value <RavenJObject>("@metadata").Value <string>("@id"))))
                {
                    index += array.Length;
                    continue;
                }
                // Found a document which is encrypted
                return(true);
            }
        }
        private static bool EncryptedFileExist(RavenFileSystem fileSystem)
        {
            const int pageSize = 10;
            var       start    = Guid.Empty;

            bool foundEncryptedDoc = false;

            while (true)
            {
                var foundMoreDocs = false;

                fileSystem.Storage.Batch(accessor =>
                {
                    var fileHeaders = accessor.GetFilesAfter(start, pageSize);

                    foreach (var fileHeader in fileHeaders)
                    {
                        foundMoreDocs = true;

                        if (EncryptionSettings.DontEncrypt(fileHeader.Name) == false)
                        {
                            foundEncryptedDoc = true;
                            break;
                        }

                        start = fileHeader.Etag;
                    }
                });

                if (foundEncryptedDoc || foundMoreDocs == false)
                {
                    break;
                }
            }

            return(foundEncryptedDoc);
        }