public Get ( string key, Raven.Abstractions.Data.TransactionInformation transactionInformation ) : JsonDocument | ||
key | string | |
transactionInformation | Raven.Abstractions.Data.TransactionInformation | |
Résultat | JsonDocument |
public void AfterIncrementalBackupRestoreCanReadDocument() { db.Put("ayende", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), new RavenJObject(), null); db.StartBackup(BackupDir, false, new DatabaseDocument()); WaitForBackup(db, true); db.Put("itamar", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), new RavenJObject(), null); db.StartBackup(BackupDir, true, new DatabaseDocument()); WaitForBackup(db, true); db.Dispose(); IOExtensions.DeleteDirectory(DataDir); DocumentDatabase.Restore(new RavenConfiguration { Settings = { {"Raven/Esent/CircularLog", "false"} } }, BackupDir, DataDir, s => { }); db = new DocumentDatabase(new RavenConfiguration { DataDirectory = DataDir }); var jObject = db.Get("ayende", null).ToJson(); Assert.Equal("*****@*****.**", jObject.Value<string>("email")); jObject = db.Get("itamar", null).ToJson(); Assert.Equal("*****@*****.**", jObject.Value<string>("email")); }
public void Execute(DocumentDatabase database) { _database = database; var configDoc = _database.Get(ClocksConfig.Id, null); if (configDoc == null) return; var config = configDoc.DataAsJson.JsonDeserialization<ClocksConfig>(); Configure(config); }
public void AfterBackupRestoreCanReadDocument() { db.Put("ayende", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), new RavenJObject(), null); db.StartBackup(BackupDir, false, new DatabaseDocument()); WaitForBackup(db, true); db.Dispose(); IOExtensions.DeleteDirectory(DataDir); DocumentDatabase.Restore(new RavenConfiguration(), BackupDir, DataDir, s => { }, defrag: true); db = new DocumentDatabase(new RavenConfiguration {DataDirectory = DataDir}); var jObject = db.Get("ayende", null).ToJson(); Assert.Equal("*****@*****.**", jObject.Value<string>("email")); }
public void AfterBackupRestoreCanReadDocument() { db.Put("ayende", null, JObject.Parse("{'email':'*****@*****.**'}"), new JObject(), null); db.StartBackup("raven.db.test.backup"); WaitForBackup(); db.Dispose(); DeleteIfExists("raven.db.test.esent"); DocumentDatabase.Restore(new RavenConfiguration(), "raven.db.test.backup", "raven.db.test.esent"); db = new DocumentDatabase(new RavenConfiguration { DataDirectory = "raven.db.test.esent"}); var jObject = db.Get("ayende", null).ToJson(); Assert.Equal("*****@*****.**", jObject.Value<string>("email")); }
public bool Authenticate(DocumentDatabase currentStore, string username, string password, out AccessTokenBody.DatabaseAccess[] allowedDatabases) { allowedDatabases = new AccessTokenBody.DatabaseAccess[0]; var jsonDocument = currentStore.Get("Raven/Users/" + username, null); if (jsonDocument == null) { return false; } var user = jsonDocument.DataAsJson.JsonDeserialization<AuthenticationUser>(); var validatePassword = user.ValidatePassword(password); if (!validatePassword) return false; var dbs = Enumerable.Empty<AccessTokenBody.DatabaseAccess>(); if (user.AllowedDatabases != null) { var accesses = user.AllowedDatabases.Select(tenantId => new AccessTokenBody.DatabaseAccess { TenantId = tenantId, Admin = user.Admin, ReadOnly = false }); dbs = dbs.Concat(accesses); } if (user.Databases != null) { var accesses = user.Databases.Select(x => new AccessTokenBody.DatabaseAccess { Admin = user.Admin | x.Admin, ReadOnly = x.ReadOnly, TenantId = x.Name }); dbs = dbs.Concat(accesses); } allowedDatabases = dbs.ToArray(); return true; }
protected void WaitForBackup(DocumentDatabase db, bool checkError) { while (true) { var jsonDocument = db.Get(BackupStatus.RavenBackupStatusDocumentKey, null); if (jsonDocument == null) break; var backupStatus = jsonDocument.DataAsJson.JsonDeserialization<BackupStatus>(); if (backupStatus.IsRunning == false) { if (checkError) { var firstOrDefault = backupStatus.Messages.FirstOrDefault(x => x.Severity == BackupStatus.BackupMessageSeverity.Error); if (firstOrDefault != null) Assert.False(true, firstOrDefault.Message); } return; } Thread.Sleep(50); } }
/// <summary> /// Uses an encrypted document to verify that the encryption key is correct and decodes it to the right value. /// </summary> public static void VerifyEncryptionKey(DocumentDatabase database, EncryptionSettings settings) { JsonDocument doc; try { doc = database.Get(Constants.InDatabaseKeyVerificationDocumentName, null); } catch (CryptographicException e) { throw new ConfigurationErrorsException("The database is encrypted with a different key and/or algorithm than the ones " + "currently in the configuration file.", e); } if (doc != null) { var ravenJTokenEqualityComparer = new RavenJTokenEqualityComparer(); if (!ravenJTokenEqualityComparer.Equals(doc.DataAsJson,Constants.InDatabaseKeyVerificationDocumentContents)) throw new ConfigurationErrorsException("The database is encrypted with a different key and/or algorithm than the ones " + "currently in the configuration file."); } else { // This is the first time the database is loaded. if (EncryptedDocumentsExist(database)) throw new InvalidOperationException("The database already has existing documents, you cannot start using encryption now."); database.Put(Constants.InDatabaseKeyVerificationDocumentName, null, Constants.InDatabaseKeyVerificationDocumentContents, new RavenJObject(), null); } }
protected void WaitForBackup(DocumentDatabase db, bool checkError) { WaitForBackup(key => db.Get(key, null), checkError); }
public void AfterIncrementalBackupRestoreCanReadDocument() { DeleteIfExists("raven.db.test.backup"); // for full backups, we can't have anything in the target dir db.Put("ayende", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), new RavenJObject(), null); db.StartBackup("raven.db.test.backup", false); WaitForBackup(true); db.Put("itamar", null, RavenJObject.Parse("{'email':'*****@*****.**'}"), new RavenJObject(), null); db.StartBackup("raven.db.test.backup", true); WaitForBackup(true); db.Dispose(); DeleteIfExists("raven.db.test.esent"); DocumentDatabase.Restore(new RavenConfiguration { Settings = { {"Raven/Esent/CircularLog", "false"} } }, "raven.db.test.backup", "raven.db.test.esent"); db = new DocumentDatabase(new RavenConfiguration { DataDirectory = "raven.db.test.esent" }); var jObject = db.Get("ayende", null).ToJson(); Assert.Equal("*****@*****.**", jObject.Value<string>("email")); jObject = db.Get("itamar", null).ToJson(); Assert.Equal("*****@*****.**", jObject.Value<string>("email")); }
protected void WaitForBackup(DocumentDatabase db, bool checkError) { var done = SpinWait.SpinUntil(() => { var jsonDocument = db.Get(BackupStatus.RavenBackupStatusDocumentKey, null); if (jsonDocument == null) return true; var backupStatus = jsonDocument.DataAsJson.JsonDeserialization<BackupStatus>(); if (backupStatus.IsRunning == false) { if (checkError) { var firstOrDefault = backupStatus.Messages.FirstOrDefault(x => x.Severity == BackupStatus.BackupMessageSeverity.Error); if (firstOrDefault != null) Assert.False(true, firstOrDefault.Message); } return true; } return false; }, TimeSpan.FromMinutes(15)); Assert.True(done); }