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


C# IHttpContext.GetAllowStale方法代码示例

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


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

示例1: OnBulkOperation

		private void OnBulkOperation(IHttpContext context, Func<string, IndexQuery, bool, RavenJArray> batchOperation)
		{
			var match = urlMatcher.Match(context.GetRequestUrl());
			var index = match.Groups[2].Value;
			if (string.IsNullOrEmpty(index))
			{
				context.SetStatusToBadRequest();
				return;
			}
			var allowStale = context.GetAllowStale();
			var indexQuery = context.GetIndexQueryFromHttpContext(maxPageSize: int.MaxValue);

		    var status = new BulkOperationStatus();
			var sp = Stopwatch.StartNew();
			long id = 0;

			var task = Task.Factory.StartNew(() =>
			{
				var array = batchOperation(index, indexQuery, allowStale);
			    status.State = array;
				status.Completed = true;

				context.Log(log => log.Debug("\tBatch Operation worked on {0:#,#;;0} documents in {1}, task #: {2}", array.Length, sp.Elapsed, id));
			});

			Database.AddTask(task, status, out id);

			context.WriteJson(new
			{
				OperationId = id
			});
		}
开发者ID:robashton,项目名称:ravendb,代码行数:32,代码来源:DocumentBatch.cs

示例2: OnBulkOperation

        private void OnBulkOperation(IHttpContext context, Func<string, IndexQuery, bool, JArray> batchOperation)
        {
            var match = urlMatcher.Match(context.GetRequestUrl());
            var index = match.Groups[2].Value;
            if (string.IsNullOrEmpty(index))
            {
                context.SetStatusToBadRequest();
                return;
            }
            var allowStale = context.GetAllowStale();
            var indexQuery = context.GetIndexQueryFromHttpContext(maxPageSize: int.MaxValue);

            var array = batchOperation(index, indexQuery, allowStale);

            context.WriteJson(array);
        }
开发者ID:vinone,项目名称:ravendb,代码行数:16,代码来源:DocumentBatch.cs

示例3: OnBulkOperation

    	private void OnBulkOperation(IHttpContext context, Func<string, TransactionInformation, object> batchOperation)
    	{
    		var match = urlMatcher.Match(context.GetRequestUrl());
    		var index = match.Groups[2].Value;
    		if (string.IsNullOrEmpty(index))
    		{
    			context.SetStatusToBadRequest();
    			return;
    		}
    		var allowStale = context.GetAllowStale();
    		Database.TransactionalStorage.Batch(actions =>
    		{
    			bool stale;
    			var queryResults = Database.QueryDocumentIds(index, new IndexQuery
    			{
    				Query = context.Request.QueryString["query"],
    				Start = context.GetStart(),
    				PageSize = int.MaxValue, // get all
    				Cutoff = context.GetCutOff(),
    				FieldsToFetch = new[] { "__document_id" }
    			}, out stale);

    			if (stale)
    			{
    				context.SetStatusToNonAuthoritativeInformation();
    				if (allowStale == false)
    				{
    					throw new InvalidOperationException(
    						"Bulk operation cancelled because the index is stale and allowStale is false");
    				}
    			}

				var transactionInformation = GetRequestTransaction(context);
    			var array = new JArray();
				foreach (var documentId in queryResults)
    			{
    				var result = batchOperation(documentId, transactionInformation);
					array.Add(JObject.FromObject(result, new JsonSerializer { Converters = { new JsonEnumConverter() } }));
    			}
    			context.WriteJson(array);
    		});
    	}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:42,代码来源:DocumentBatch.cs


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