当前位置: 首页>>代码示例>>C#>>正文


C# RavenConfiguration.CustomizeValuesForDatabaseTenant方法代码示例

本文整理汇总了C#中Raven.Database.Config.RavenConfiguration.CustomizeValuesForDatabaseTenant方法的典型用法代码示例。如果您正苦于以下问题:C# RavenConfiguration.CustomizeValuesForDatabaseTenant方法的具体用法?C# RavenConfiguration.CustomizeValuesForDatabaseTenant怎么用?C# RavenConfiguration.CustomizeValuesForDatabaseTenant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Raven.Database.Config.RavenConfiguration的用法示例。


在下文中一共展示了RavenConfiguration.CustomizeValuesForDatabaseTenant方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 { State = RestoreStatusState.Running, Messages = new List<string>() };

			var restoreRequest = await ReadJsonObjectAsync<DatabaseRestoreRequest>();

			DatabaseDocument databaseDocument = null;

			var databaseDocumentPath = MaintenanceActions.FindDatabaseDocument(restoreRequest.BackupLocation);
			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 existingDatabase = Database.Documents.GetDocumentMetadata("Raven/Databases/" + databaseName, null);
			if (existingDatabase != null)
				return GetMessageWithString("Cannot do an online restore for an existing database, delete the database " + databaseName + " and restore again.", 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, BackupMethods.Filename)))
				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.CustomizeValuesForDatabaseTenant(databaseName);
			ravenConfiguration.Initialize();

			string documentDataDir;
			ravenConfiguration.DataDirectory = ResolveTenantDataDirectory(restoreRequest.DatabaseLocation, databaseName, out documentDataDir);
			restoreRequest.DatabaseLocation = ravenConfiguration.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 = databaseName
																												}), new RavenJObject(), null);

			DatabasesLandlord.SystemDatabase.Documents.Delete(RestoreStatus.RavenRestoreStatusDocumentKey, null, null);
//.........这里部分代码省略.........
开发者ID:jrusbatch,项目名称:ravendb,代码行数:101,代码来源:AdminController.cs


注:本文中的Raven.Database.Config.RavenConfiguration.CustomizeValuesForDatabaseTenant方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。