本文整理汇总了C#中Raven.Database.DocumentDatabase.Put方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentDatabase.Put方法的具体用法?C# DocumentDatabase.Put怎么用?C# DocumentDatabase.Put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Database.DocumentDatabase
的用法示例。
在下文中一共展示了DocumentDatabase.Put方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReplicateDatabaseCreation
public void ReplicateDatabaseCreation( DocumentDatabase database )
{
InstanceDescription self = null;
var replicationTargets = GetReplicationTargets(out self);
if (replicationTargets != null)
{
log.Info("Ensuring default database {0} is replicated from {2} at {3}",string.IsNullOrWhiteSpace(database.Name) ? "Default" : database.Name, self.Id, self.InternalUrl);
if (!string.IsNullOrWhiteSpace(database.Name))
{
EnsureDatabaseExists(replicationTargets,database.Name);
}
var documentId = new ReplicationDocument().Id;
var replicationDocument = new ReplicationDocument()
{
Destinations =
replicationTargets
.Select(i => new ReplicationDestination() { Url = GetReplicationUrl(database.Name,i) })
.ToList()
};
database.Put(documentId, null, RavenJObject.FromObject(replicationDocument), new RavenJObject(), null);
}
}
示例2: Execute
public void Execute(DocumentDatabase database)
{
if (string.IsNullOrEmpty(database.Name) == false)
return;// we don't care about tenant databases
if (string.Equals(database.Configuration.AuthenticationMode, "OAuth", StringComparison.InvariantCultureIgnoreCase) == false)
return; // we don't care if we aren't using oauth
var array = database.GetDocumentsWithIdStartingWith("Raven/Users/", 0, 1);
if (array.Length > 0)
return; // there is already at least one user in there
var pwd = Guid.NewGuid().ToString();
if (database.Configuration.RunInMemory == false)
{
var authConfigPath = Path.Combine(Path.GetDirectoryName(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile), "authentication.config");
File.WriteAllText(authConfigPath,
@"Since no users were found in the database, and the database authentication mode was set to OAuth, the following user was automatically created.
Username: Admin
Password: " + pwd + @"
You can use those credentials to login to RavenDB.");
logger.Info(@"Since no users were found, and the database authentication mode was set to OAuth, a default user was generated name 'Admin'.
Credentials for this user can be found in the following file: {0}", authConfigPath);
}
var ravenJTokenWriter = new RavenJTokenWriter();
JsonExtensions.CreateDefaultJsonSerializer().Serialize(ravenJTokenWriter, new AuthenticationUser
{
AllowedDatabases = new[] { "*" },
Name = "Admin",
Admin = true
}.SetPassword(pwd));
var userDoc = (RavenJObject)ravenJTokenWriter.Token;
userDoc.Remove("Id");
database.Put("Raven/Users/Admin", null,
userDoc,
new RavenJObject
{
{Constants.RavenEntityName, "AuthenticationUsers"},
{
Constants.RavenClrType,
typeof (AuthenticationUser).FullName + ", " + typeof (AuthenticationUser).Assembly.GetName().Name
}
}, null);
}
示例3: IncrementalBackupWithCircularLogThrows
public void IncrementalBackupWithCircularLogThrows()
{
db.Dispose();
db = new DocumentDatabase(new RavenConfiguration
{
DataDirectory = DataDir,
RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
});
db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
db.Put("ayende", null, RavenJObject.Parse("{'email':'[email protected]'}"), new RavenJObject(), null);
Assert.Throws<InvalidOperationException>(() => db.StartBackup(BackupDir, true, new DatabaseDocument()));
}
示例4: Main
private static void Main(string[] args)
{
if (args.Length != 2)
{
Console.WriteLine("Usage: importer.exe db-dir docs-dir");
return;
}
var files = Directory.GetFiles(args[1]);
Console.WriteLine("Parsing {0:#,#} docs", files.Length);
var array = files.Select(x => JObject.Parse(File.ReadAllText(x))).ToArray();
Console.WriteLine("Inserting {0:#,#} docs", files.Length);
var sw = Stopwatch.StartNew();
var count = 0;
using (var db = new DocumentDatabase(new RavenConfiguration {DataDirectory = args[0]}))
{
foreach (var doc in array)
{
count++;
db.Put(null, Guid.Empty, doc, new JObject(), null);
}
}
Console.WriteLine("{0} doc inserts in {1}", count, sw.Elapsed);
}
示例5: VerifyEncryptionKey
/// <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);
}
}
示例6: AfterFailedRestoreOfIndex_ShouldGenerateWarningAndResetIt
public void AfterFailedRestoreOfIndex_ShouldGenerateWarningAndResetIt()
{
using (var db = new DocumentDatabase(new RavenConfiguration
{
DataDirectory = DataDir,
RunInUnreliableYetFastModeThatIsNotSuitableForProduction = false,
Settings =
{
{"Raven/Esent/CircularLog", "false"}
}
}))
{
db.SpinBackgroundWorkers();
db.PutIndex(new RavenDocumentsByEntityName().IndexName, new RavenDocumentsByEntityName().CreateIndexDefinition());
db.Put("users/1", null, RavenJObject.Parse("{'Name':'Arek'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
db.Put("users/2", null, RavenJObject.Parse("{'Name':'David'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
WaitForIndexing(db);
db.StartBackup(BackupDir, false, new DatabaseDocument());
WaitForBackup(db, true);
db.Put("users/3", null, RavenJObject.Parse("{'Name':'Daniel'}"), RavenJObject.Parse("{'Raven-Entity-Name':'Users'}"), null);
WaitForIndexing(db);
db.StartBackup(BackupDir, true, new DatabaseDocument());
WaitForBackup(db, true);
}
IOExtensions.DeleteDirectory(DataDir);
var incrementalDirectories = Directory.GetDirectories(BackupDir, "Inc*");
// delete 'index-files.required-for-index-restore' to make backup corrupted according to the reported error
File.Delete(Path.Combine(incrementalDirectories.First(),
"Indexes\\Raven%2fDocumentsByEntityName\\index-files.required-for-index-restore"));
var sb = new StringBuilder();
DocumentDatabase.Restore(new RavenConfiguration(), BackupDir, DataDir, s => sb.Append(s), defrag: true);
Assert.Contains(
"Error: Index Raven%2fDocumentsByEntityName could not be restored. All already copied index files was deleted." +
" Index will be recreated after launching Raven instance",
sb.ToString());
using (var db = new DocumentDatabase(new RavenConfiguration {DataDirectory = DataDir}))
{
db.SpinBackgroundWorkers();
QueryResult queryResult;
do
{
queryResult = db.Query("Raven/DocumentsByEntityName", new IndexQuery
{
Query = "Tag:[[Users]]",
PageSize = 10
}, CancellationToken.None);
} while (queryResult.IsStale);
Assert.Equal(3, queryResult.Results.Count);
}
}