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


C# IHttpContext.SetStatusToNonAuthoritativeInformation方法代码示例

本文整理汇总了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);
    		});
    	}
开发者ID:VirtueMe,项目名称:ravendb,代码行数:42,代码来源:DocumentBatch.cs

示例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);
        }
开发者ID:925coder,项目名称:ravendb,代码行数:33,代码来源:Index.cs

示例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);
				});
		}
开发者ID:robinminto,项目名称:ravendb,代码行数:33,代码来源:Document.cs

示例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);
		}
开发者ID:robinminto,项目名称:ravendb,代码行数:16,代码来源:Document.cs

示例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);
		}
开发者ID:robinminto,项目名称:ravendb,代码行数:25,代码来源:Document.cs

示例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);
		}
开发者ID:bstrausser,项目名称:ravendb,代码行数:29,代码来源:Index.cs


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