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


C# IHttpContext.SetStatusToNotAvailable方法代码示例

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


在下文中一共展示了IHttpContext.SetStatusToNotAvailable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OutputDatabaseOpenFailure

		private static void OutputDatabaseOpenFailure(IHttpContext ctx, string tenantId, Exception e)
		{
			var msg = "Could not open database named: " + tenantId;
			logger.WarnException(msg, e);
			ctx.SetStatusToNotAvailable();
			ctx.WriteJson(new
			{
				Error = msg,
				Reason = e.ToString()
			});
		}
开发者ID:urbanfly,项目名称:ravendb,代码行数:11,代码来源:HttpServer.cs

示例2: HandleActualRequest

		public void HandleActualRequest(IHttpContext ctx)
		{
			var isReadLockHeld = disposerLock.IsReadLockHeld;
			if (isReadLockHeld == false)
			{
				if (disposerLock.TryEnterReadLock(TimeSpan.FromSeconds(10)) == false)
				{
					ctx.SetStatusToNotAvailable();
					ctx.FinalizeResponse();
					logger.Warn("Could not enter disposer lock, probably disposing server, aborting request");
					return;
				}
			}
			try
			{
				if (disposed)
					return;

				var sw = Stopwatch.StartNew();
				bool ravenUiRequest = false;
				try
				{
					ravenUiRequest = DispatchRequest(ctx);
				}
				catch (Exception e)
				{
					ExceptionHandler.TryHandleException(ctx, e);
					if (ShouldLogException(e))
						logger.WarnException("Error on request", e);
				}
				finally
				{
					try
					{
						FinalizeRequestProcessing(ctx, sw, ravenUiRequest);
					}
					catch (Exception e)
					{
						logger.ErrorException("Could not finalize request properly", e);
					}
				}
			}
			finally
			{
				if (isReadLockHeld == false)
					disposerLock.ExitReadLock();
			}
		}
开发者ID:Nakro,项目名称:ravendb,代码行数:48,代码来源:HttpServer.cs

示例3: SetupRequestToProperDatabase

		private bool SetupRequestToProperDatabase(IHttpContext ctx)
		{
			var requestUrl = ctx.GetRequestUrlForTenantSelection();
			var match = databaseQuery.Match(requestUrl);
			var onBeforeRequest = BeforeRequest;
			if (match.Success == false)
			{
				currentTenantId.Value = Constants.SystemDatabase;
				currentDatabase.Value = SystemDatabase;
				currentConfiguration.Value = SystemConfiguration;
				databaseLastRecentlyUsed.AddOrUpdate("System", SystemTime.UtcNow, (s, time) => SystemTime.UtcNow);
				if (onBeforeRequest != null)
				{
					var args = new BeforeRequestEventArgs
					{
						Context = ctx,
						IgnoreRequest = false,
						TenantId = "System",
						Database = SystemDatabase
					};
					onBeforeRequest(this, args);
					if (args.IgnoreRequest)
						return false;
				}

				return true;
			}
			var tenantId = match.Groups[1].Value;
			Task<DocumentDatabase> resourceStoreTask;
			bool hasDb;
			try
			{
				hasDb = TryGetOrCreateResourceStore(tenantId, out resourceStoreTask);
			}
			catch (Exception e)
			{
				OutputDatabaseOpenFailure(ctx, tenantId, e);
				return false;
			}
			if (hasDb)
			{
				try
				{
					if (resourceStoreTask.Wait(TimeSpan.FromSeconds(30)) == false)
					{
						ctx.SetStatusToNotAvailable();
						ctx.WriteJson(new
						{
							Error = "The database " + tenantId + " is currently being loaded, but after 30 seconds, this request has been aborted. Please try again later, database loading continues.",
						});
						return false;
					}
					if (onBeforeRequest != null)
					{
						var args = new BeforeRequestEventArgs
						{
							Context = ctx,
							IgnoreRequest = false,
							TenantId = tenantId,
							Database = resourceStoreTask.Result
						};
						onBeforeRequest(this, args);
						if (args.IgnoreRequest)
							return false;
					}
				}
				catch (Exception e)
				{
					OutputDatabaseOpenFailure(ctx, tenantId, e);
					return false;
				}
				var resourceStore = resourceStoreTask.Result;

				databaseLastRecentlyUsed.AddOrUpdate(tenantId, SystemTime.UtcNow, (s, time) => SystemTime.UtcNow);

				if (string.IsNullOrEmpty(Configuration.VirtualDirectory) == false && Configuration.VirtualDirectory != "/")
				{
					ctx.AdjustUrl(Configuration.VirtualDirectory + match.Value);
				}
				else
				{
					ctx.AdjustUrl(match.Value);
				}
				currentTenantId.Value = tenantId;
				currentDatabase.Value = resourceStore;
				currentConfiguration.Value = resourceStore.Configuration;
			}
			else
			{
				ctx.SetStatusToNotFound();
				ctx.WriteJson(new
				{
					Error = "Could not find a database named: " + tenantId
				});
				return false;
			}
			return true;
		}
开发者ID:urbanfly,项目名称:ravendb,代码行数:98,代码来源:HttpServer.cs

示例4: SetupRequestToProperDatabase

		private bool SetupRequestToProperDatabase(IHttpContext ctx)
		{
			var requestUrl = ctx.GetRequestUrlForTenantSelection();
			var match = databaseQuery.Match(requestUrl);
			var onBeforeRequest = BeforeRequest;
			if (match.Success == false)
			{
				currentTenantId.Value = Constants.SystemDatabase;
				currentDatabase.Value = SystemDatabase;
				currentConfiguration.Value = SystemConfiguration;
				SystemDatabase.WorkContext.UpdateFoundWork();
				if (onBeforeRequest != null)
				{
					var args = new BeforeRequestEventArgs
					{
						Context = ctx,
						IgnoreRequest = false,
						TenantId = "System",
						Database = SystemDatabase
					};
					onBeforeRequest(this, args);
					if (args.IgnoreRequest)
						return false;
				}

				return true;
			}
			var tenantId = match.Groups[1].Value;
			Task<DocumentDatabase> resourceStoreTask;
			bool hasDb;
			try
			{
				hasDb = TryGetOrCreateResourceStore(tenantId, out resourceStoreTask);
			}
			catch (Exception e)
			{
				OutputDatabaseOpenFailure(ctx, tenantId, e);
				return false;
			}

			if (hasDb)
			{
				try
				{
					const int timeToWaitForDatabaseToLoad = 5;
					if (resourceStoreTask.IsCompleted == false && resourceStoreTask.IsFaulted == false)
					{
						if (_maxNumberOfThreadsForDatabaseToLoad.Wait(0) == false)
						{
							ctx.SetStatusToNotAvailable();
							ctx.WriteJson(new
							{
								Error =
									string.Format(
										"The database {0} is currently being loaded, but there are too many requests waiting for database load. Please try again later, database loading continues.",
										tenantId),
							});
							return false;
						}
						try
						{
							if (resourceStoreTask.Wait(TimeSpan.FromSeconds(timeToWaitForDatabaseToLoad)) == false)
							{
								ctx.SetStatusToNotAvailable();
								ctx.WriteJson(new
								{
									Error =
										string.Format(
											"The database {0} is currently being loaded, but after {1} seconds, this request has been aborted. Please try again later, database loading continues.",
											tenantId, timeToWaitForDatabaseToLoad),
								});
								return false;
							}
						}
						finally
						{
							_maxNumberOfThreadsForDatabaseToLoad.Release();
						}
					}
					if (onBeforeRequest != null)
					{
						var args = new BeforeRequestEventArgs
						{
							Context = ctx,
							IgnoreRequest = false,
							TenantId = tenantId,
							Database = resourceStoreTask.Result
						};
						onBeforeRequest(this, args);
						if (args.IgnoreRequest)
							return false;
					}
				}
				catch (Exception e)
				{
					OutputDatabaseOpenFailure(ctx, tenantId, e);
					return false;
				}
				var resourceStore = resourceStoreTask.Result;

//.........这里部分代码省略.........
开发者ID:jon-adams,项目名称:ravendb,代码行数:101,代码来源:HttpServer.cs


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