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


C# IHttpContext.GetIndexQueryFromHttpContext方法代码示例

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


在下文中一共展示了IHttpContext.GetIndexQueryFromHttpContext方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

示例4: 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);

			context.WriteJson(Database.ExecuteGetTermsQuery(index, indexQuery, facetSetupDoc));
		}
开发者ID:DBCooper2012,项目名称:ravendb,代码行数:10,代码来源:Facets.cs

示例5: Respond

		public override void Respond(IHttpContext context)
		{
			using (context.Response.Streaming())
			{
				context.Response.ContentType = "application/json; charset=utf-8";

				var match = urlMatcher.Match(context.GetRequestUrl());
				var index = match.Groups[1].Value;

				var query = context.GetIndexQueryFromHttpContext(int.MaxValue);
				if (string.IsNullOrEmpty(context.Request.QueryString["pageSize"]))
					query.PageSize = int.MaxValue;
				var isHeadRequest = context.Request.HttpMethod == "HEAD";
				if (isHeadRequest)
					query.PageSize = 0;

				using (var writer = GetOutputWriter(context))
				{
					// we may be sending a LOT of documents to the user, and most 
					// of them aren't going to be relevant for other ops, so we are going to skip
					// the cache for that, to avoid filling it up very quickly
					using (DocumentCacher.SkipSettingDocumentsInDocumentCache())
					using (var cts = new CancellationTokenSource())
					using(var timeout = cts.TimeoutAfter(Settings.DatbaseOperationTimeout))
					{
						Database.Query(index, query, cts.Token, information =>
						{
							context.Response.AddHeader("Raven-Result-Etag", information.ResultEtag.ToString());
							context.Response.AddHeader("Raven-Index-Etag", information.IndexEtag.ToString());
							context.Response.AddHeader("Raven-Is-Stale", information.IsStable ? "true" : "false");
							context.Response.AddHeader("Raven-Index", information.Index);
							context.Response.AddHeader("Raven-Total-Results", information.TotalResults.ToString(CultureInfo.InvariantCulture));
							context.Response.AddHeader("Raven-Index-Timestamp",
													   information.IndexTimestamp.ToString(Default.DateTimeFormatsToWrite,
																						   CultureInfo.InvariantCulture));

							if (isHeadRequest)
								return;
							writer.WriteHeader();
						}, o =>
						{
							timeout.Delay();
                            Database.WorkContext.UpdateFoundWork();
							writer.Write(o);
						});
					}
				}
			}
		}
开发者ID:925coder,项目名称:ravendb,代码行数:49,代码来源:QueryStreams.cs

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

示例7: Respond

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

			var query = context.GetIndexQueryFromHttpContext(int.MaxValue);
			if (string.IsNullOrEmpty(context.Request.QueryString["pageSize"]))
				query.PageSize = int.MaxValue;
			var isHeadRequest = context.Request.HttpMethod == "HEAD";
			if (isHeadRequest)
				query.PageSize = 0;
			JsonWriter writer = null;
			Database.Query(index, query, information =>
			{
				context.Response.AddHeader("Raven-Result-Etag", information.ResultEtag.ToString());
				context.Response.AddHeader("Raven-Index-Etag", information.IndexEtag.ToString());
				context.Response.AddHeader("Raven-Is-Stale", information.IsStable ? "true" : "false");
				context.Response.AddHeader("Raven-Index", information.Index);
				context.Response.AddHeader("Raven-Total-Results", information.TotalResults.ToString(CultureInfo.InvariantCulture));
				context.Response.AddHeader("Raven-Index-Timestamp",
				                           information.IndexTimestamp.ToString(Default.DateTimeFormatsToWrite,
				                                                               CultureInfo.InvariantCulture));

				if (isHeadRequest)
					return;

				writer = new JsonTextWriter(new StreamWriter(context.Response.OutputStream));
				writer.WriteStartObject();
				writer.WritePropertyName("Results");
				writer.WriteStartArray();
			}, result => result.WriteTo(writer, Default.Converters));

			if (isHeadRequest)
				return;

			writer.WriteEndArray();
			writer.WriteEndObject();
			if (writer != null)
			{
				writer.Flush();
				writer.Close();
			}

		}
开发者ID:samueldjack,项目名称:ravendb,代码行数:46,代码来源:QueryStreams.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: ExecuteQuery

		private QueryResult ExecuteQuery(IHttpContext context, string index, out Guid indexEtag)
		{
			var indexQuery = context.GetIndexQueryFromHttpContext(Database.Configuration.MaxPageSize);

			return index.StartsWith("dynamic", StringComparison.InvariantCultureIgnoreCase) ? 
				PerformQueryAgainstDynamicIndex(context, index, indexQuery, out indexEtag) : 
				PerformQueryAgainstExistingIndex(context, index, indexQuery, out indexEtag);
		}
开发者ID:MikeEast,项目名称:ravendb,代码行数:8,代码来源:Index.cs

示例10: ExecuteQuery

        private QueryResultWithIncludes ExecuteQuery(IHttpContext context, string index, CancellationToken token, out Etag indexEtag)
        {
            var indexQuery = context.GetIndexQueryFromHttpContext(Database.Configuration.MaxPageSize);
            RewriteDateQueriesFromOldClients(context, indexQuery);

            var sp = Stopwatch.StartNew();
            var result = index.StartsWith("dynamic/", StringComparison.OrdinalIgnoreCase) || index.Equals("dynamic", StringComparison.OrdinalIgnoreCase) ?
                PerformQueryAgainstDynamicIndex(context, index, indexQuery, token, out indexEtag) :
                PerformQueryAgainstExistingIndex(context, index, indexQuery, token, out indexEtag);

            sp.Stop();

            context.Log(log => log.Debug(() =>
            {
                var sb = new StringBuilder("\tQuery: ")
                    .Append(indexQuery.Query)
                    .AppendLine();
                sb.Append("\t").AppendFormat("Time: {0:#,#;;0} ms", sp.ElapsedMilliseconds).AppendLine();

                if (result == null)
                    return sb.ToString();

                sb.Append("\tIndex: ")
                    .AppendLine(result.IndexName);
                sb.Append("\t").AppendFormat("Results: {0:#,#;;0} returned out of {1:#,#;;0} total.", result.Results.Count, result.TotalResults).AppendLine();

                return sb.ToString();
            }));

            return result;
        }
开发者ID:925coder,项目名称:ravendb,代码行数:31,代码来源:Index.cs

示例11: GetExplanation

        private void GetExplanation(IHttpContext context, string index)
        {
            var dynamicIndex = index.StartsWith("dynamic/", StringComparison.OrdinalIgnoreCase) ||
                               index.Equals("dynamic", StringComparison.OrdinalIgnoreCase);

            if (dynamicIndex == false)
            {
                context.SetStatusToBadRequest();
                context.WriteJson(new
                                {
                                    Error = "Explain can only work on dynamic indexes"
                                });
                return;
            }

            var indexQuery = context.GetIndexQueryFromHttpContext(Database.Configuration.MaxPageSize);
            string entityName = null;
            if (index.StartsWith("dynamic/", StringComparison.OrdinalIgnoreCase))
                entityName = index.Substring("dynamic/".Length);

            var explanations = Database.ExplainDynamicIndexSelection(entityName, indexQuery);

            context.WriteJson(explanations);
        }
开发者ID:925coder,项目名称:ravendb,代码行数:24,代码来源:Index.cs

示例12: GetIndexEntries

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

            var isDynamic = index.StartsWith("dynamic/", StringComparison.OrdinalIgnoreCase)
                            || index.Equals("dynamic", StringComparison.OrdinalIgnoreCase);

            if (isDynamic)
            {
                GetIndexEntriesForDynamicIndex(context, index, indexQuery, totalResults);
            }
            else
            {
                GetIndexEntriesForExistingIndex(context, index, indexQuery, totalResults);
            }
        }
开发者ID:925coder,项目名称:ravendb,代码行数:17,代码来源:Index.cs

示例13: OnGet

		private void OnGet(IHttpContext context, string index)
		{
			var definition = context.Request.QueryString["definition"];
		    if ("yes".Equals(definition, StringComparison.InvariantCultureIgnoreCase))
		    {
		    	var indexDefinition = Database.GetIndexDefinition(index);
				if(indexDefinition == null)
				{
					context.SetStatusToNotFound();
					return;
				}
		    	context.WriteJson(new {Index = indexDefinition});
		    }
		    else
            {
				var indexQuery = context.GetIndexQueryFromHttpContext(Database.Configuration.MaxPageSize);
            	var queryResult = Database.Query(index, indexQuery);
            	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), queryResult.Includes.Add,includes, loadedIds);
            	foreach (var result in queryResult.Results)
            	{
            		command.Execute(result);
            	}
            	context.WriteJson(queryResult);
			}
		}
开发者ID:ajaishankar,项目名称:ravendb,代码行数:32,代码来源:Index.cs

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