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


C# IHttpContext.WriteETag方法代码示例

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


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

示例1: Respond

		public override void Respond(IHttpContext context)
		{
			var match = urlMatcher.Match(context.GetRequestUrl());
			var index = match.Groups[1].Value;

			var indexQuery = context.GetIndexQueryFromHttpContext(Database.Configuration.MaxPageSize);
			var facetStart = context.GetFacetStartFromHttpContext();
			var facetPageSize = context.GetFacetPageSizeFromHttpContext();

		    List<Facet> facets;

		    Etag etag;

            if (TryGetFacets(context, index, out etag, out facets) == false) 
				return;

			if (context.MatchEtag(etag))
			{
				context.SetStatusToNotModified();
				return;
			}

            context.WriteETag(etag);

            context.WriteJson(Database.ExecuteGetTermsQuery(index, indexQuery, facets, facetStart, facetPageSize));
		}
开发者ID:samueldjack,项目名称:ravendb,代码行数:26,代码来源:Facets.cs

示例2: Respond

		public override void Respond(IHttpContext context)
		{
			var match = urlMatcher.Match(context.GetRequestUrl());
			var index = match.Groups[1].Value;

			var facetSetupDoc = context.GetFacetSetupDocFromHttpContext();
			var indexQuery = context.GetIndexQueryFromHttpContext(Database.Configuration.MaxPageSize);

			var jsonDocument = Database.Get(facetSetupDoc, null);
			if(jsonDocument == null)
			{
				context.SetStatusToNotFound();
				context.Write("Could not find facet document: " + facetSetupDoc);
				return;
			}

			var etag = GetFacetsEtag(jsonDocument, index);

			if(context.MatchEtag(etag))
			{
				context.SetStatusToNotModified();
				return;
			}
			context.WriteETag(etag);
			context.WriteJson(Database.ExecuteGetTermsQuery(index, indexQuery, facetSetupDoc));
		}
开发者ID:remcoros,项目名称:ravendb,代码行数:26,代码来源:Facets.cs

示例3: Respond

		public override void Respond(IHttpContext context)
		{
			var match = urlMatcher.Match(context.GetRequestUrl());
			var filename = match.Groups[1].Value;
			var etag = context.GetEtag();
			switch (context.Request.HttpMethod)
			{
				case "GET":
					Database.TransactionalStorage.Batch(_=> // have to keep the session open for reading of the attachment stream
					{
						var attachmentAndHeaders = Database.GetStatic(filename);
						if (attachmentAndHeaders == null)
						{
							context.SetStatusToNotFound();
							return;
						}
						if (context.MatchEtag(attachmentAndHeaders.Etag))
						{
							context.SetStatusToNotModified();
							return;
						}
						context.WriteHeaders(attachmentAndHeaders.Metadata, attachmentAndHeaders.Etag);
						using (var stream = attachmentAndHeaders.Data())
						{
							stream.CopyTo(context.Response.OutputStream);
						}
					});
					break;
				case "HEAD":
					Database.TransactionalStorage.Batch(_ => // have to keep the session open for reading of the attachment stream
					{
						var attachmentAndHeaders = Database.GetStatic(filename);
						if (attachmentAndHeaders == null)
						{
							context.SetStatusToNotFound();
							return;
						}
						if (context.MatchEtag(attachmentAndHeaders.Etag))
						{
							context.SetStatusToNotModified();
							return;
						}
						context.WriteHeaders(attachmentAndHeaders.Metadata, attachmentAndHeaders.Etag);
						context.Response.ContentLength64 = attachmentAndHeaders.Size;
					});
					break;
				case "PUT":
					var newEtag = Database.PutStatic(filename, context.GetEtag(), context.Request.InputStream,
					                                 context.Request.Headers.FilterHeaders(isServerDocument:false));

					context.WriteETag(newEtag);
					context.SetStatusToCreated("/static/" + filename);
					break;
				case "DELETE":
					Database.DeleteStatic(filename, etag);
					context.SetStatusToDeleted();
					break;
			}
		}
开发者ID:royra,项目名称:ravendb,代码行数:59,代码来源:Static.cs

示例4: Respond

		/// <summary>
		/// Responds the specified context.
		/// </summary>
		/// <param name="context">The context.</param>
		public override void Respond(IHttpContext context)
		{
			var match = urlMatcher.Match(context.GetRequestUrl());
			var index = match.Groups[1].Value;

			var indexEtag = Database.GetIndexEtag(index, null);
			if (context.MatchEtag(indexEtag))
			{
				context.SetStatusToNotModified();
				return;
			}

			var term = context.Request.QueryString["term"];
			var field = context.Request.QueryString["field"];

			StringDistanceTypes distanceTypes;
			int numOfSuggestions;
			float accuracy;

			if (Enum.TryParse(context.Request.QueryString["distance"], true, out distanceTypes) == false)
				distanceTypes = StringDistanceTypes.Default;

			if (distanceTypes == StringDistanceTypes.None)
			{
				context.SetStatusToBadRequest();
				context.WriteJson(new
				{
					Error = "Suggestion is disabled since you specified the Distance value as 'StringDistanceTypes.None'."
				});
				return;
			}

			if (int.TryParse(context.Request.QueryString["max"], out numOfSuggestions) == false)
				numOfSuggestions = 10;

			if (float.TryParse(context.Request.QueryString["accuracy"], out accuracy) == false)
				accuracy = 0.5f;

			bool popularity;
			if (bool.TryParse(context.Request.QueryString["popularity"], out popularity) == false)
				popularity = false;

			var query = new SuggestionQuery
			{
				Distance = distanceTypes,
				Field = field,
				MaxSuggestions = numOfSuggestions,
				Term = term,
				Accuracy = accuracy,
				Popularity = popularity
			};

			var suggestionQueryResult = Database.ExecuteSuggestionQuery(index, query);
			context.WriteETag(Database.GetIndexEtag(index, null));
			context.WriteJson(suggestionQueryResult);
		}
开发者ID:nberardi,项目名称:ravendb,代码行数:60,代码来源:SuggestionResponder.cs

示例5: Respond

		public override void Respond(IHttpContext context)
		{
			RavenJArray itemsToLoad;
			if(context.Request.HttpMethod == "POST")
				itemsToLoad = context.ReadJsonArray();
			else
				itemsToLoad = new RavenJArray(context.Request.QueryString.GetValues("id"));
			var result = new MultiLoadResult();
			var loadedIds = new HashSet<string>();
			var includes = context.Request.QueryString.GetValues("include") ?? new string[0];
			var transactionInformation = GetRequestTransaction(context);
		    var includedEtags = new List<byte>();
			Database.TransactionalStorage.Batch(actions =>
			{
				var addIncludesCommand = new AddIncludesCommand(Database, transactionInformation, (etag, includedDoc) =>
				{
					includedEtags.AddRange(etag.ToByteArray());
				    result.Includes.Add(includedDoc);
				}, includes, loadedIds);
				foreach (RavenJToken item in itemsToLoad)
				{
					var value = item.Value<string>();
					if(loadedIds.Add(value)==false)
						continue;
					var documentByKey = Database.Get(value, transactionInformation);
					if (documentByKey == null)
						continue;
					result.Results.Add(documentByKey.ToJson());

					if (documentByKey.Etag != null)
					{
						includedEtags.AddRange(documentByKey.Etag.Value.ToByteArray());
					}
					includedEtags.Add((documentByKey.NonAuthoritativeInformation ?? false) ? (byte)0 : (byte)1);
					addIncludesCommand.Execute(documentByKey.DataAsJson);
				}
			});

			Guid computedEtag;

			using (var md5 = MD5.Create())
			{
				var computeHash = md5.ComputeHash(includedEtags.ToArray());
				computedEtag = new Guid(computeHash);
			}

			if (context.MatchEtag(computedEtag))
			{
				context.SetStatusToNotModified();
				return;
			}

			context.WriteETag(computedEtag);
			context.WriteJson(result);
		}
开发者ID:royra,项目名称:ravendb,代码行数:55,代码来源:Queries.cs

示例6: Respond

		public override void Respond(IHttpContext context)
		{
			context.WriteETag(typeof (ClientAccessPolicy).FullName);
			context.Response.SetPublicCachability();
			context.Response.ContentType = "text/xml";
			context.Write(@"<?xml version='1.0' encoding='utf-8'?>
<access-policy>
 <cross-domain-access>
   <policy>
	 <allow-from http-methods='*' http-request-headers='*'>
	   <domain uri='*' />
	 </allow-from>
	 <grant-to>
	   <resource include-subpaths='true' path='/' />
	 </grant-to>
   </policy>
 </cross-domain-access>
</access-policy>");
		}
开发者ID:royra,项目名称:ravendb,代码行数:19,代码来源:ClientAccessPolicy.cs

示例7: Respond

		public override void Respond(IHttpContext context)
		{
			var match = urlMatcher.Match(context.GetRequestUrl());
			var index = match.Groups[1].Value;

			var indexEtag = Database.GetIndexEtag(index, null);
			if (context.MatchEtag(indexEtag))
			{
				context.SetStatusToNotModified();
				return;
			}
			
			var executeGetTermsQuery = Database.ExecuteGetTermsQuery(index, 
			                                                         context.Request.QueryString["field"],
			                                                         context.Request.QueryString["fromValue"],
																	 context.GetPageSize(Database.Configuration.MaxPageSize)
				);
			context.WriteETag(Database.GetIndexEtag(index, null));
			context.WriteJson(executeGetTermsQuery);
		}
开发者ID:925coder,项目名称:ravendb,代码行数:20,代码来源:Terms.cs

示例8: Respond

		public override void Respond(IHttpContext context)
		{
			var match = urlMatcher.Match(context.GetRequestUrl());
			var index = match.Groups[1].Value;

			var indexQuery = context.GetIndexQueryFromHttpContext(Database.Configuration.MaxPageSize);
			var facetStart = context.GetFacetStartFromHttpContext();
			var facetPageSize = context.GetFacetPageSizeFromHttpContext();

		    List<Facet> facets;

		    Etag etag;

            if (TryGetFacets(context, index, out etag, out facets) == false) 
				return;

			if (context.MatchEtag(etag))
			{
				context.SetStatusToNotModified();
				return;
			}

            context.WriteETag(etag);

		    try
		    {
		        context.WriteJson(Database.ExecuteGetTermsQuery(index, indexQuery, facets, facetStart, facetPageSize));
		    }
		    catch (Exception ex)
		    {
		        if (ex is ArgumentException || ex is InvalidOperationException)
		        {
		            throw new BadRequestException(ex.Message, ex);
		        }

		        throw;
		    }
		}
开发者ID:925coder,项目名称:ravendb,代码行数:38,代码来源:Facets.cs

示例9: 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

示例10: GetIndexEntriesForExistingIndex

        private void GetIndexEntriesForExistingIndex(IHttpContext context, string index, IndexQuery indexQuery, Reference<int> totalResults)
        {
            var results = Database
                    .IndexStorage
                    .IndexEntires(index, indexQuery, Database.IndexQueryTriggers, totalResults)
                    .ToArray();

            Tuple<DateTime, Etag> indexTimestamp = null;
            bool isIndexStale = false;
	        
	        Database.TransactionalStorage.Batch(
                accessor =>
                {
	                isIndexStale = accessor.Staleness.IsIndexStale(index, indexQuery.Cutoff, indexQuery.CutoffEtag);
					if (isIndexStale == false && indexQuery.Cutoff == null && indexQuery.CutoffEtag == null)
					{
						var indexInstance = Database.IndexStorage.GetIndexInstance(index);
						isIndexStale = isIndexStale || (indexInstance != null && indexInstance.IsMapIndexingInProgress);
					}

                    indexTimestamp = accessor.Staleness.IndexLastUpdatedAt(index);
                });
            var indexEtag = Database.GetIndexEtag(index, null, indexQuery.ResultsTransformer);
            context.WriteETag(indexEtag);
            context.WriteJson(
                new
                {
                    Count = results.Length,
                    Results = results,
                    Includes = new string[0],
                    IndexTimestamp = indexTimestamp.Item1,
                    IndexEtag = indexTimestamp.Item2,
                    TotalResults = totalResults.Value,
                    SkippedResults = 0,
                    NonAuthoritativeInformation = false,
                    ResultEtag = indexEtag,
                    IsStale = isIndexStale,
                    IndexName = index,
                    LastQueryTime = Database.IndexStorage.GetLastQueryTime(index)
                });
        }
开发者ID:925coder,项目名称:ravendb,代码行数:41,代码来源:Index.cs

示例11: GetIndexEntries

		private void GetIndexEntries(IHttpContext context, string index)
		{
			var indexQuery = context.GetIndexQueryFromHttpContext(Database.Configuration.MaxPageSize);
			var totalResults = new Reference<int>();
			var results = Database.IndexStorage
								.IndexEntires(index, indexQuery,Database.IndexQueryTriggers, totalResults )
								.ToArray();


			Tuple<DateTime, Guid> indexTimestamp = null;
			bool isIndexStale = false;
			Database.TransactionalStorage.Batch(accessor =>
			{
				isIndexStale = accessor.Staleness.IsIndexStale(index, indexQuery.Cutoff, indexQuery.CutoffEtag);
				indexTimestamp = accessor.Staleness.IndexLastUpdatedAt(index);
			});
			var indexEtag = Database.GetIndexEtag(index, null);
			context.WriteETag(indexEtag);
			context.WriteJson(new
			{
				Count = results.Length,
				Results = results,
				Includes = new string[0],
				IndexTimestamp = indexTimestamp.Item1,
				IndexEtag = indexTimestamp.Item2,
				TotalResults = totalResults.Value,
				SkippedResults = 0,
				NonAuthoritativeInformation = false,
				ResultEtag = indexEtag,
				IsStale = isIndexStale,
				IndexName = index,
				LastQueryTime = Database.IndexStorage.GetLastQueryTime(index)
			});
		}
开发者ID:shiranGinige,项目名称:ravendb,代码行数:34,代码来源:Index.cs


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