本文整理汇总了C#中Raven.Database.Config.RavenConfiguration.CustomizeValuesForTenant方法的典型用法代码示例。如果您正苦于以下问题:C# RavenConfiguration.CustomizeValuesForTenant方法的具体用法?C# RavenConfiguration.CustomizeValuesForTenant怎么用?C# RavenConfiguration.CustomizeValuesForTenant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Raven.Database.Config.RavenConfiguration
的用法示例。
在下文中一共展示了RavenConfiguration.CustomizeValuesForTenant方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Restore
public async Task<HttpResponseMessage> Restore()
{
if (EnsureSystemDatabase() == false)
return GetMessageWithString("Restore is only possible from the system database", HttpStatusCode.BadRequest);
var restoreStatus = new RestoreStatus{Messages = new List<string>()};
var restoreRequest = await ReadJsonObjectAsync<RestoreRequest>();
DatabaseDocument databaseDocument = null;
var databaseDocumentPath = Path.Combine(restoreRequest.BackupLocation, "Database.Document");
if (File.Exists(databaseDocumentPath))
{
var databaseDocumentText = File.ReadAllText(databaseDocumentPath);
databaseDocument = RavenJObject.Parse(databaseDocumentText).JsonDeserialization<DatabaseDocument>();
}
var databaseName = !string.IsNullOrWhiteSpace(restoreRequest.DatabaseName) ? restoreRequest.DatabaseName
: databaseDocument == null ? null : databaseDocument.Id;
if (string.IsNullOrWhiteSpace(databaseName))
{
var errorMessage = (databaseDocument == null || String.IsNullOrWhiteSpace(databaseDocument.Id))
? "Database.Document file is invalid - database name was not found and not supplied in the request (Id property is missing or null). This is probably a bug - should never happen."
: "A database name must be supplied if the restore location does not contain a valid Database.Document file";
restoreStatus.Messages.Add(errorMessage);
DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null, RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
return GetMessageWithString(errorMessage,HttpStatusCode.BadRequest);
}
if (databaseName == Constants.SystemDatabase)
return GetMessageWithString("Cannot do an online restore for the <system> database", HttpStatusCode.BadRequest);
var ravenConfiguration = new RavenConfiguration
{
DatabaseName = databaseName,
IsTenantDatabase = true
};
if (databaseDocument != null)
{
foreach (var setting in databaseDocument.Settings)
{
ravenConfiguration.Settings[setting.Key] = setting.Value;
}
}
if (File.Exists(Path.Combine(restoreRequest.BackupLocation, Voron.Impl.Constants.DatabaseFilename)))
ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Voron.TransactionalStorage).AssemblyQualifiedName;
else if (Directory.Exists(Path.Combine(restoreRequest.BackupLocation, "new")))
ravenConfiguration.DefaultStorageTypeName = typeof (Raven.Storage.Esent.TransactionalStorage).AssemblyQualifiedName;
ravenConfiguration.CustomizeValuesForTenant(databaseName);
ravenConfiguration.Initialize();
string documentDataDir;
ravenConfiguration.DataDirectory = ResolveTenantDataDirectory(restoreRequest.DatabaseLocation, databaseName, out documentDataDir);
restoreRequest.DatabaseLocation = ravenConfiguration.DataDirectory;
DatabasesLandlord.SystemDatabase.Documents.Delete(RestoreStatus.RavenRestoreStatusDocumentKey, null, null);
bool defrag;
if (bool.TryParse(GetQueryStringValue("defrag"), out defrag))
restoreRequest.Defrag = defrag;
await Task.Factory.StartNew(() =>
{
MaintenanceActions.Restore(ravenConfiguration,restoreRequest,
msg =>
{
restoreStatus.Messages.Add(msg);
DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
RavenJObject.FromObject(restoreStatus), new RavenJObject(), null);
});
if (databaseDocument == null)
return;
databaseDocument.Settings[Constants.RavenDataDir] = documentDataDir;
if (restoreRequest.IndexesLocation != null)
databaseDocument.Settings[Constants.RavenIndexPath] = restoreRequest.IndexesLocation;
if (restoreRequest.JournalsLocation != null)
databaseDocument.Settings[Constants.RavenTxJournalPath] = restoreRequest.JournalsLocation;
databaseDocument.Id = databaseName;
DatabasesLandlord.Protect(databaseDocument);
DatabasesLandlord.SystemDatabase.Documents.Put("Raven/Databases/" + databaseName, null, RavenJObject.FromObject(databaseDocument),
new RavenJObject(), null);
restoreStatus.Messages.Add("The new database was created");
DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
RavenJObject.FromObject(restoreStatus), new RavenJObject(), null);
}, TaskCreationOptions.LongRunning);
return GetEmptyMessage();
}
示例2: RespondToAdmin
public override void RespondToAdmin(IHttpContext context)
{
if (EnsureSystemDatabase(context) == false)
return;
var restoreRequest = context.ReadJsonObject<RestoreRequest>();
DatabaseDocument databaseDocument = null;
if (File.Exists(Path.Combine(restoreRequest.RestoreLocation, "Database.Document")))
{
var databaseDocumentText = File.ReadAllText(Path.Combine(restoreRequest.RestoreLocation, "Database.Document"));
databaseDocument = RavenJObject.Parse(databaseDocumentText).JsonDeserialization<DatabaseDocument>();
}
var databaseName = !string.IsNullOrWhiteSpace(restoreRequest.DatabaseName) ? restoreRequest.DatabaseName
: databaseDocument == null ? null : databaseDocument.Id;
if (string.IsNullOrWhiteSpace(databaseName))
{
context.SetStatusToBadRequest();
context.WriteJson(new
{
Error = "A database name must be supplied if the restore location does not contain a valid Database.Document file"
});
return;
}
var ravenConfiguration = new RavenConfiguration()
{
DatabaseName = databaseName,
IsTenantDatabase = true
};
if(databaseDocument != null)
{
foreach (var setting in databaseDocument.Settings)
{
ravenConfiguration.Settings[setting.Key] = setting.Value;
}
}
if (File.Exists(Path.Combine(restoreRequest.RestoreLocation, "Raven.ravendb")))
{
ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Managed.TransactionalStorage).AssemblyQualifiedName;
}
else if (Directory.Exists(Path.Combine(restoreRequest.RestoreLocation, "new")))
{
ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Esent.TransactionalStorage).AssemblyQualifiedName;
}
ravenConfiguration.CustomizeValuesForTenant(databaseName);
ravenConfiguration.Initialize();
string documentDataDir;
ravenConfiguration.DataDirectory = ResolveTenantDataDirectory(restoreRequest.DatabaseLocation, databaseName, out documentDataDir);
var restoreStatus = new List<string>();
SystemDatabase.Delete(RestoreStatus.RavenRestoreStatusDocumentKey, null, new TransactionInformation());
var defrag = "true".Equals(context.Request.QueryString["defrag"], StringComparison.InvariantCultureIgnoreCase);
DocumentDatabase.Restore(ravenConfiguration, restoreRequest.RestoreLocation, null,
msg =>
{
restoreStatus.Add(msg);
SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
RavenJObject.FromObject(new {restoreStatus}), new RavenJObject(), null);
}, defrag);
if (databaseDocument == null)
return;
databaseDocument.Settings[Constants.RavenDataDir] = documentDataDir;
databaseDocument.Id = databaseName;
SystemDatabase.Put("Raven/Databases/" + databaseName, null, RavenJObject.FromObject(databaseDocument), new RavenJObject(), null);
restoreStatus.Add("The new database was created");
SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
}
示例3: Restore
public async Task<HttpResponseMessage> Restore()
{
if (EnsureSystemDatabase() == false)
return GetMessageWithString("Restore is only possible from the system database", HttpStatusCode.BadRequest);
var restoreStatus = new RestoreStatus { Messages = new List<string>() };
var restoreRequest = await ReadJsonObjectAsync<FilesystemRestoreRequest>();
FileSystemDocument filesystemDocument = null;
var fileSystemDocumentPath = FindFilesystemDocument(restoreRequest.BackupLocation);
if (!File.Exists(fileSystemDocumentPath))
{
throw new InvalidOperationException("Cannot restore when the Filesystem.Document file is missing in the backup folder: " + restoreRequest.BackupLocation);
}
var filesystemDocumentText = File.ReadAllText(fileSystemDocumentPath);
filesystemDocument = RavenJObject.Parse(filesystemDocumentText).JsonDeserialization<FileSystemDocument>();
var filesystemName = !string.IsNullOrWhiteSpace(restoreRequest.FilesystemName) ? restoreRequest.FilesystemName
: filesystemDocument == null ? null : filesystemDocument.Id;
if (string.IsNullOrWhiteSpace(filesystemName))
{
var errorMessage = (filesystemDocument == null || String.IsNullOrWhiteSpace(filesystemDocument.Id))
? BackupMethods.FilesystemDocumentFilename + " file is invalid - filesystem name was not found and not supplied in the request (Id property is missing or null). This is probably a bug - should never happen."
: "A filesystem name must be supplied if the restore location does not contain a valid " + BackupMethods.FilesystemDocumentFilename + " file";
restoreStatus.Messages.Add(errorMessage);
DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenFilesystemRestoreStatusDocumentKey(filesystemName), null, RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
return GetMessageWithString(errorMessage, HttpStatusCode.BadRequest);
}
var ravenConfiguration = new RavenConfiguration
{
DatabaseName = filesystemName,
IsTenantDatabase = true
};
if (filesystemDocument != null)
{
foreach (var setting in filesystemDocument.Settings)
{
ravenConfiguration.Settings[setting.Key] = setting.Value;
}
}
if (File.Exists(Path.Combine(restoreRequest.BackupLocation, BackupMethods.Filename)))
ravenConfiguration.FileSystem.DefaultStorageTypeName = InMemoryRavenConfiguration.VoronTypeName;
else if (Directory.Exists(Path.Combine(restoreRequest.BackupLocation, "new")))
ravenConfiguration.FileSystem.DefaultStorageTypeName = InMemoryRavenConfiguration.EsentTypeName;
ravenConfiguration.CustomizeValuesForTenant(filesystemName);
ravenConfiguration.Initialize();
string documentDataDir;
ravenConfiguration.FileSystem.DataDirectory = ResolveTenantDataDirectory(restoreRequest.FilesystemLocation, filesystemName, out documentDataDir);
restoreRequest.FilesystemLocation = ravenConfiguration.FileSystem.DataDirectory;
DatabasesLandlord.SystemDatabase.Documents.Delete(RestoreStatus.RavenFilesystemRestoreStatusDocumentKey(filesystemName), null, null);
bool defrag;
if (bool.TryParse(GetQueryStringValue("defrag"), out defrag))
restoreRequest.Defrag = defrag;
//TODO: add task to pending task list like in ImportDatabase
Task.Factory.StartNew(() =>
{
if (!string.IsNullOrWhiteSpace(restoreRequest.FilesystemLocation))
{
ravenConfiguration.FileSystem.DataDirectory = restoreRequest.FilesystemLocation;
}
using (var transactionalStorage = RavenFileSystem.CreateTransactionalStorage(ravenConfiguration))
{
transactionalStorage.Restore(restoreRequest, msg =>
{
restoreStatus.Messages.Add(msg);
DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenFilesystemRestoreStatusDocumentKey(filesystemName), null,
RavenJObject.FromObject(restoreStatus), new RavenJObject(), null);
});
}
if (filesystemDocument == null)
return;
filesystemDocument.Settings["Raven/FileSystem/DataDir"] = documentDataDir;
if (restoreRequest.IndexesLocation != null)
filesystemDocument.Settings[Constants.RavenIndexPath] = restoreRequest.IndexesLocation;
if (restoreRequest.JournalsLocation != null)
filesystemDocument.Settings[Constants.RavenTxJournalPath] = restoreRequest.JournalsLocation;
filesystemDocument.Id = filesystemName;
DatabasesLandlord.SystemDatabase.Documents.Put("Raven/FileSystems/" + filesystemName, null, RavenJObject.FromObject(filesystemDocument),
new RavenJObject(), null);
restoreStatus.Messages.Add("The new filesystem was created");
DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenFilesystemRestoreStatusDocumentKey(filesystemName), null,
//.........这里部分代码省略.........
示例4: Restore
public async Task<HttpResponseMessage> Restore()
{
if (EnsureSystemDatabase() == false)
return GetMessageWithString("Restore is only possible from the system database", HttpStatusCode.BadRequest);
var restoreStatus = new RestoreStatus { Messages = new List<string>() };
var restoreRequest = await ReadJsonObjectAsync<FilesystemRestoreRequest>();
FileSystemDocument filesystemDocument = null;
var fileSystemDocumentPath = FindFilesystemDocument(restoreRequest.BackupLocation);
if (!File.Exists(fileSystemDocumentPath))
{
throw new InvalidOperationException("Cannot restore when the Filesystem.Document file is missing in the backup folder: " + restoreRequest.BackupLocation);
}
var filesystemDocumentText = File.ReadAllText(fileSystemDocumentPath);
filesystemDocument = RavenJObject.Parse(filesystemDocumentText).JsonDeserialization<FileSystemDocument>();
var filesystemName = !string.IsNullOrWhiteSpace(restoreRequest.FilesystemName) ? restoreRequest.FilesystemName
: filesystemDocument == null ? null : filesystemDocument.Id;
if (string.IsNullOrWhiteSpace(filesystemName))
{
var errorMessage = (filesystemDocument == null || String.IsNullOrWhiteSpace(filesystemDocument.Id))
? Constants.FilesystemDocumentFilename + " file is invalid - filesystem name was not found and not supplied in the request (Id property is missing or null). This is probably a bug - should never happen."
: "A filesystem name must be supplied if the restore location does not contain a valid " + Constants.FilesystemDocumentFilename + " file";
restoreStatus.Messages.Add(errorMessage);
DatabasesLandlord.SystemDatabase.Documents.Put(RestoreStatus.RavenFilesystemRestoreStatusDocumentKey(filesystemName), null, RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
return GetMessageWithString(errorMessage, HttpStatusCode.BadRequest);
}
var ravenConfiguration = new RavenConfiguration
{
DatabaseName = filesystemName,
IsTenantDatabase = true
};
if (filesystemDocument != null)
{
foreach (var setting in filesystemDocument.Settings)
{
ravenConfiguration.Settings[setting.Key] = setting.Value;
}
}
if (File.Exists(Path.Combine(restoreRequest.BackupLocation, BackupMethods.Filename)))
ravenConfiguration.FileSystem.DefaultStorageTypeName = InMemoryRavenConfiguration.VoronTypeName;
else if (Directory.Exists(Path.Combine(restoreRequest.BackupLocation, "new")))
ravenConfiguration.FileSystem.DefaultStorageTypeName = InMemoryRavenConfiguration.EsentTypeName;
ravenConfiguration.CustomizeValuesForTenant(filesystemName);
ravenConfiguration.Initialize();
string documentDataDir;
ravenConfiguration.FileSystem.DataDirectory = ResolveTenantDataDirectory(restoreRequest.FilesystemLocation, filesystemName, out documentDataDir);
restoreRequest.FilesystemLocation = ravenConfiguration.FileSystem.DataDirectory;
string anotherRestoreResourceName;
if (IsAnotherRestoreInProgress(out anotherRestoreResourceName))
{
if (restoreRequest.RestoreStartTimeout.HasValue)
{
try
{
using (var cts = new CancellationTokenSource())
{
cts.CancelAfter(TimeSpan.FromSeconds(restoreRequest.RestoreStartTimeout.Value));
var token = cts.Token;
do
{
await Task.Delay(500, token);
}
while (IsAnotherRestoreInProgress(out anotherRestoreResourceName));
}
}
catch (OperationCanceledException)
{
return GetMessageWithString(string.Format("Another restore is still in progress (resource name = {0}). Waited {1} seconds for other restore to complete.", anotherRestoreResourceName, restoreRequest.RestoreStartTimeout.Value), HttpStatusCode.ServiceUnavailable);
}
}
else
{
return GetMessageWithString(string.Format("Another restore is in progress (resource name = {0})", anotherRestoreResourceName), HttpStatusCode.ServiceUnavailable);
}
}
Database.Documents.Put(RestoreInProgress.RavenRestoreInProgressDocumentKey, null, RavenJObject.FromObject(new RestoreInProgress
{
Resource = filesystemName
}), new RavenJObject(), null);
DatabasesLandlord.SystemDatabase.Documents.Delete(RestoreStatus.RavenFilesystemRestoreStatusDocumentKey(filesystemName), null, null);
bool defrag;
if (bool.TryParse(GetQueryStringValue("defrag"), out defrag))
restoreRequest.Defrag = defrag;
//.........这里部分代码省略.........
示例5: RespondToAdmin
public override void RespondToAdmin(IHttpContext context)
{
if (EnsureSystemDatabase(context) == false)
return;
var restoreRequest = context.ReadJsonObject<RestoreRequest>();
var restoreStatus = new List<string>();
SystemDatabase.Delete(RestoreStatus.RavenRestoreStatusDocumentKey, null, null);
DatabaseDocument databaseDocument = null;
if (File.Exists(Path.Combine(restoreRequest.RestoreLocation, "Database.Document")))
{
var databaseDocumentText = File.ReadAllText(Path.Combine(restoreRequest.RestoreLocation, "Database.Document"));
databaseDocument = RavenJObject.Parse(databaseDocumentText).JsonDeserialization<DatabaseDocument>();
}
var databaseName = !string.IsNullOrWhiteSpace(restoreRequest.DatabaseName) ? restoreRequest.DatabaseName
: databaseDocument == null ? null : databaseDocument.Id;
if (string.IsNullOrWhiteSpace(databaseName))
{
context.SetStatusToBadRequest();
var errorMessage = (databaseDocument == null || String.IsNullOrWhiteSpace(databaseDocument.Id))
? "Database.Document file is invalid - database name was not found and not supplied in the request (Id property is missing or null). This is probably a bug - should never happen."
: "A database name must be supplied if the restore location does not contain a valid Database.Document file";
context.WriteJson(new
{
Error = errorMessage
});
restoreStatus.Add(errorMessage);
SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
return;
}
if (databaseName == Constants.SystemDatabase)
{
context.SetStatusToBadRequest();
context.WriteJson(new
{
Error = "Cannot do an online restore for the <system> database"
});
restoreStatus.Add("Cannot do an online restore for the <system> database");
SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
return;
}
var ravenConfiguration = new RavenConfiguration
{
DatabaseName = databaseName,
IsTenantDatabase = true
};
if(databaseDocument != null)
{
foreach (var setting in databaseDocument.Settings)
{
ravenConfiguration.Settings[setting.Key] = setting.Value;
}
}
if (File.Exists(Path.Combine(restoreRequest.RestoreLocation, "Raven.ravendb")))
{
ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Managed.TransactionalStorage).AssemblyQualifiedName;
}
else if (Directory.Exists(Path.Combine(restoreRequest.RestoreLocation, "new")))
{
ravenConfiguration.DefaultStorageTypeName = typeof(Raven.Storage.Esent.TransactionalStorage).AssemblyQualifiedName;
}
ravenConfiguration.CustomizeValuesForTenant(databaseName);
ravenConfiguration.Initialize();
string documentDataDir;
ravenConfiguration.DataDirectory = ResolveTenantDataDirectory(restoreRequest.DatabaseLocation, databaseName, out documentDataDir);
var defrag = "true".Equals(context.Request.QueryString["defrag"], StringComparison.InvariantCultureIgnoreCase);
Task.Factory.StartNew(() =>
{
DocumentDatabase.Restore(ravenConfiguration, restoreRequest.RestoreLocation, null,
msg =>
{
restoreStatus.Add(msg);
SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
RavenJObject.FromObject(new {restoreStatus}), new RavenJObject(), null);
}, defrag);
if (databaseDocument == null)
{
//.........这里部分代码省略.........