本文整理汇总了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
});
}
示例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);
}
示例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);
});
}