本文整理汇总了C#中IHttpContext.SetStatusToNonAuthoritativeInformation方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpContext.SetStatusToNonAuthoritativeInformation方法的具体用法?C# IHttpContext.SetStatusToNonAuthoritativeInformation怎么用?C# IHttpContext.SetStatusToNonAuthoritativeInformation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpContext
的用法示例。
在下文中一共展示了IHttpContext.SetStatusToNonAuthoritativeInformation方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
});
}
示例2: GetIndexQueryResult
private void GetIndexQueryResult(IHttpContext context, string index)
{
Etag indexEtag;
QueryResultWithIncludes queryResult;
using (var cts = new CancellationTokenSource())
{
cts.TimeoutAfter(Settings.DatbaseOperationTimeout);
queryResult = ExecuteQuery(context, index, cts.Token, out indexEtag);
}
if (queryResult == null)
return;
var includes = context.Request.QueryString.GetValues("include") ?? new string[0];
var loadedIds = new HashSet<string>(
queryResult.Results
.Where(x => x["@metadata"] != null)
.Select(x => x["@metadata"].Value<string>("@id"))
.Where(x => x != null)
);
var command = new AddIncludesCommand(Database, GetRequestTransaction(context),
(etag, doc) => queryResult.Includes.Add(doc), includes, loadedIds);
foreach (var result in queryResult.Results)
{
command.Execute(result);
}
command.AlsoInclude(queryResult.IdsToInclude);
context.WriteETag(indexEtag);
if (queryResult.NonAuthoritativeInformation)
context.SetStatusToNonAuthoritativeInformation();
context.WriteJson(queryResult);
}
示例3: Get
private void Get(IHttpContext context, string docId)
{
context.Response.AddHeader("Content-Type", "application/json; charset=utf-8");
if (string.IsNullOrEmpty(context.Request.Headers["If-None-Match"]))
{
GetDocumentDirectly(context, docId);
return;
}
Database.TransactionalStorage.Batch(
_ => // we are running this here to ensure transactional safety for the two operations
{
var transactionInformation = GetRequestTransaction(context);
var documentMetadata = Database.GetDocumentMetadata(docId, transactionInformation);
if (documentMetadata == null)
{
context.SetStatusToNotFound();
return;
}
Debug.Assert(documentMetadata.Etag != null);
if (context.MatchEtag(documentMetadata.Etag.Value) && documentMetadata.NonAuthoritativeInformation == false)
{
context.SetStatusToNotModified();
return;
}
if (documentMetadata.NonAuthoritativeInformation != null && documentMetadata.NonAuthoritativeInformation.Value)
{
context.SetStatusToNonAuthoritativeInformation();
}
GetDocumentDirectly(context, docId);
});
}
示例4: GetDocumentDirectly
private void GetDocumentDirectly(IHttpContext context, string docId)
{
var doc = Database.Get(docId, GetRequestTransaction(context));
if (doc == null)
{
context.SetStatusToNotFound();
return;
}
if (doc.NonAuthoritativeInformation != null && doc.NonAuthoritativeInformation.Value)
{
context.SetStatusToNonAuthoritativeInformation();
}
Debug.Assert(doc.Etag != null);
doc.Metadata[Constants.LastModified] = doc.LastModified;
context.WriteData(doc.DataAsJson, doc.Metadata, doc.Etag.Value);
}
示例5: Head
private void Head(IHttpContext context, string docId)
{
context.Response.AddHeader("Content-Type", "application/json; charset=utf-8");
var transactionInformation = GetRequestTransaction(context);
var documentMetadata = Database.GetDocumentMetadata(docId, transactionInformation);
if (documentMetadata == null)
{
context.SetStatusToNotFound();
return;
}
Debug.Assert(documentMetadata.Etag != null);
if (context.MatchEtag(documentMetadata.Etag.Value) && documentMetadata.NonAuthoritativeInformation == false)
{
context.SetStatusToNotModified();
return;
}
if (documentMetadata.NonAuthoritativeInformation != null && documentMetadata.NonAuthoritativeInformation.Value)
{
context.SetStatusToNonAuthoritativeInformation();
}
documentMetadata.Metadata[Constants.LastModified] = documentMetadata.LastModified; //HACK ? to get the document's last modified value into the response headers
context.WriteHeaders(documentMetadata.Metadata, documentMetadata.Etag.Value);
}
示例6: GetIndexQueryRessult
private void GetIndexQueryRessult(IHttpContext context, string index)
{
Guid indexEtag;
var queryResult = ExecuteQuery(context, index, out indexEtag);
if (queryResult == null)
return;
var includes = context.Request.QueryString.GetValues("include") ?? new string[0];
var loadedIds = new HashSet<string>(
queryResult.Results
.Where(x => x["@metadata"] != null)
.Select(x => x["@metadata"].Value<string>("@id"))
.Where(x => x != null)
);
var command = new AddIncludesCommand(Database, GetRequestTransaction(context),
(etag, doc) => queryResult.Includes.Add(doc), includes, loadedIds);
foreach (var result in queryResult.Results)
{
command.Execute(result);
}
command.AlsoInclude(queryResult.IdsToInclude);
context.Response.AddHeader("ETag", indexEtag.ToString());
if(queryResult.NonAuthoritativeInformation)
context.SetStatusToNonAuthoritativeInformation();
context.WriteJson(queryResult);
}