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


C# IHttpContext.ReadJsonArray方法代码示例

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


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

示例1: Respond

		public override void Respond(IHttpContext context)
		{
			JArray itemsToLoad;
			if(context.Request.HttpMethod == "POST")
				itemsToLoad = context.ReadJsonArray();
			else
				itemsToLoad = new JArray(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);
			Database.TransactionalStorage.Batch(actions =>
			{
				var addIncludesCommand = new AddIncludesCommand(Database, transactionInformation, result.Includes.Add, includes, loadedIds);
				foreach (JToken item in itemsToLoad)
				{
					var value = item.Value<string>();
					if(loadedIds.Add(value)==false)
						continue;
					var documentByKey = actions.Documents.DocumentByKey(value,
                        transactionInformation);
					if (documentByKey == null)
						continue;
					result.Results.Add(documentByKey.ToJson());

					addIncludesCommand.Execute(documentByKey.DataAsJson);
				}
            });
			context.WriteJson(result);
		}
开发者ID:ajaishankar,项目名称:ravendb,代码行数:30,代码来源:Queries.cs

示例2: Respond

		public override void Respond(IHttpContext context)
		{
			var match = urlMatcher.Match(context.GetRequestUrl());
			var docId = match.Groups[1].Value;
			switch (context.Request.HttpMethod)
			{
				case "GET":
					Get(context, docId);
					break;
				case "DELETE":
					Database.Delete(docId, context.GetEtag(), GetRequestTransaction(context));
					context.SetStatusToDeleted();
					break;
				case "PUT":
					Put(context, docId);
					break;
				case "PATCH":
					var patchRequestJson = context.ReadJsonArray();
					var patchRequests = patchRequestJson.Cast<RavenJObject>().Select(PatchRequest.FromJson).ToArray();
					var patchResult = Database.ApplyPatch(docId, context.GetEtag(), patchRequests, GetRequestTransaction(context));
					switch (patchResult)
					{
						case PatchResult.DocumentDoesNotExists:
							context.SetStatusToNotFound();
							break;
						case PatchResult.Patched:
							context.Response.AddHeader("Location", Database.Configuration.GetFullUrl("/docs/" + docId));
							context.WriteJson(new {Patched = true});
							break;
						default:
							throw new ArgumentOutOfRangeException("Value " + patchResult + " is not understood");
					}
					break;
			}
		}
开发者ID:wbinford,项目名称:ravendb,代码行数:35,代码来源:Document.cs

示例3: Batch

		private void Batch(IHttpContext context)
		{
			var jsonCommandArray = context.ReadJsonArray();

			var transactionInformation = GetRequestTransaction(context);
			var commands = (from RavenJObject jsonCommand in jsonCommandArray
			                select CommandDataFactory.CreateCommand(jsonCommand, transactionInformation))
				.ToArray();

			context.Log(log => log.Debug(()=>
			{
				if(commands.Length > 15) // this is probably an import method, we will input minimal information, to avoid filling up the log
				{
					return "\tExecuted " + string.Join(", ", commands.GroupBy(x => x.Method).Select(x => string.Format("{0:#,#} {1} operations", x.Count(), x.Key)));
				}

				var sb = new StringBuilder();
				foreach (var commandData in commands)
				{
					sb.AppendFormat("\t{0} {1}{2}", commandData.Method, commandData.Key, Environment.NewLine);
				}
				return sb.ToString();
			}));

			var batchResult = Database.Batch(commands);
			context.WriteJson(batchResult);
		}
开发者ID:JPT123,项目名称:ravendb,代码行数:27,代码来源:DocumentBatch.cs

示例4: Respond

		public override void Respond(IHttpContext context)
		{
			var match = urlMatcher.Match(context.GetRequestUrl());
			var docId = Uri.UnescapeDataString(match.Groups[1].Value);
			switch (context.Request.HttpMethod)
			{
				case "HEAD":
					Head(context, docId);
					break;
				case "GET":
					Get(context, docId);
					break;
				case "DELETE":
					Database.Delete(docId, context.GetEtag(), GetRequestTransaction(context));
					context.SetStatusToDeleted();
					break;
				case "PUT":
					Put(context, docId);
					break;
				case "PATCH":
					var patchRequestJson = context.ReadJsonArray();
					var patchRequests = patchRequestJson.Cast<RavenJObject>().Select(PatchRequest.FromJson).ToArray();
					var patchResult = Database.ApplyPatch(docId, context.GetEtag(), patchRequests, GetRequestTransaction(context));
					ProcessPatchResult(context, docId, patchResult.PatchResult, null);
					break;
				case "EVAL":
					var advPatchRequestJson = context.ReadJsonObject<RavenJObject>();
					var advPatch = ScriptedPatchRequest.FromJson(advPatchRequestJson);
					var advPatchResult = Database.ApplyPatch(docId, context.GetEtag(), advPatch, GetRequestTransaction(context), true);
					ProcessPatchResult(context, docId, advPatchResult.Item1.PatchResult, advPatchResult.Item2);
					break;
			}
		}
开发者ID:shiranGinige,项目名称:ravendb,代码行数:33,代码来源:Document.cs

示例5: Respond

        public override void Respond(IHttpContext context)
        {
            switch (context.Request.HttpMethod)
            {                
                case "POST":
                    Batch(context);
                    break;
				case "DELETE":
					OnBulkOperation(context, (docId, tx) =>
					{
						Database.Delete(docId, null, tx);
						return new { Document = docId, Deleted = true };
				
					} );
            		break;
				case "PATCH":
					var patchRequestJson = context.ReadJsonArray();
					var patchRequests = patchRequestJson.Cast<JObject>().Select(PatchRequest.FromJson).ToArray();
					OnBulkOperation(context, (docId, tx) =>
					{
						var patchResult = Database.ApplyPatch(docId, null, patchRequests, tx);
						return new {Document = docId, Result = patchResult};
					});
            		break;
            }
        }
开发者ID:VirtueMe,项目名称:ravendb,代码行数:26,代码来源:DocumentBatch.cs

示例6: Respond

		public override void Respond(IHttpContext context)
		{
			var databaseBulkOperations = new DatabaseBulkOperations(Database, GetRequestTransaction(context));
			switch (context.Request.HttpMethod)
			{                
				case "POST":
					Batch(context);
					break;
				case "DELETE":
					OnBulkOperation(context, databaseBulkOperations.DeleteByIndex);
					break;
				case "PATCH":
					var patchRequestJson = context.ReadJsonArray();
					var patchRequests = patchRequestJson.Cast<RavenJObject>().Select(PatchRequest.FromJson).ToArray();
					OnBulkOperation(context, (index, query, allowStale) =>
						databaseBulkOperations.UpdateByIndex(index, query, patchRequests, allowStale));
					break;
				case "EVAL":
					var advPatchRequestJson = context.ReadJsonObject<RavenJObject>();
					var advPatch = ScriptedPatchRequest.FromJson(advPatchRequestJson);
					OnBulkOperation(context, (index, query, allowStale) =>
						databaseBulkOperations.UpdateByIndex(index, query, advPatch, allowStale));
					break;
			}
		}
开发者ID:robashton,项目名称:ravendb,代码行数:25,代码来源:DocumentBatch.cs

示例7: 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 =>
			{
				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);
				}

				var addIncludesCommand = new AddIncludesCommand(Database, transactionInformation, (etag, includedDoc) =>
				{
					includedEtags.AddRange(etag.ToByteArray());
					result.Includes.Add(includedDoc);
				}, includes, loadedIds);

				foreach (var item in result.Results.Where(item => item != null))
				{
					addIncludesCommand.Execute(item);
				}
			});

			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:nberardi,项目名称:ravendb,代码行数:60,代码来源:Queries.cs

示例8: Respond

		public override void Respond(IHttpContext context)
		{
			var src = context.Request.QueryString["from"];
			if (string.IsNullOrEmpty(src))
			{
				context.SetStatusToBadRequest();
				return;
			}
			while (src.EndsWith("/"))
				src = src.Substring(0, src.Length - 1);// remove last /, because that has special meaning for Raven
			if (string.IsNullOrEmpty(src))
			{
				context.SetStatusToBadRequest();
				return;
			}
			var array = context.ReadJsonArray();
			if (ReplicationTask != null) 
				ReplicationTask.HandleHeartbeat(src);
			using (Database.DisableAllTriggersForCurrentThread())
			{
				Database.TransactionalStorage.Batch(actions =>
				{
					string lastEtag = Guid.Empty.ToString();
					foreach (RavenJObject document in array)
					{
						var metadata = document.Value<RavenJObject>("@metadata");
						if (metadata[Constants.RavenReplicationSource] == null)
						{
							// not sure why, old document from when the user didn't have replciation
							// that we suddenly decided to replicate, choose the source for that
							metadata[Constants.RavenReplicationSource] = RavenJToken.FromObject(src);
						}
						lastEtag = metadata.Value<string>("@etag");
						var id = metadata.Value<string>("@id");
						document.Remove("@metadata");
						ReplicateDocument(actions, id, metadata, document, src);
					}

					var replicationDocKey = Constants.RavenReplicationSourcesBasePath + "/" + src;
					var replicationDocument = Database.Get(replicationDocKey, null);
					var lastAttachmentId = Guid.Empty;
					if (replicationDocument != null)
					{
						lastAttachmentId =
							replicationDocument.DataAsJson.JsonDeserialization<SourceReplicationInformation>().
								LastAttachmentEtag;
					}
					Database.Put(replicationDocKey, null,
								 RavenJObject.FromObject(new SourceReplicationInformation
								 {
									 Source = src,
									 LastDocumentEtag = new Guid(lastEtag),
									 LastAttachmentEtag = lastAttachmentId,
									 ServerInstanceId = Database.TransactionalStorage.Id
								 }),
								 new RavenJObject(), null);
				});
			}
		}
开发者ID:remcoros,项目名称:ravendb,代码行数:59,代码来源:DocumentReplicationResponder.cs

示例9: Batch

        private void Batch(IHttpContext context)
        {
            var jsonCommandArray = context.ReadJsonArray();

            var transactionInformation = GetRequestTransaction(context);
            var commands = (from JObject jsonCommand in jsonCommandArray
                            select CommandDataFactory.CreateCommand(jsonCommand, transactionInformation)).ToList();

            var batchResult = Database.Batch(commands);
            context.WriteJson(batchResult);
        }
开发者ID:vinone,项目名称:ravendb,代码行数:11,代码来源:DocumentBatch.cs

示例10: Respond

		public override void Respond(IHttpContext context)
		{
			var match = urlMatcher.Match(context.GetRequestUrl());
			var docId = match.Groups[1].Value;
			switch (context.Request.HttpMethod)
			{
				case "GET":
					context.Response.Headers["Content-Type"] = "application/json; charset=utf-8";
					var doc = Database.Get(docId,GetRequestTransaction(context));
					if (doc == null)
					{
						context.SetStatusToNotFound();
						return;
					}
					if(doc.NonAuthoritiveInformation)
					{
						context.SetStatusToNonAuthoritiveInformation();
					}
					if (context.MatchEtag(doc.Etag))
					{
						context.SetStatusToNotModified();
						return;
					}
					doc.Metadata["Last-Modified"] = doc.LastModified.ToString("r");
					context.WriteData(doc.DataAsJson, doc.Metadata, doc.Etag);
					break;
				case "DELETE":
					Database.Delete(docId, context.GetEtag(), GetRequestTransaction(context));
					context.SetStatusToDeleted();
					break;
				case "PUT":
					Put(context, docId);
					break;
				case "PATCH":
					var patchRequestJson = context.ReadJsonArray();
					var patchRequests = patchRequestJson.Cast<JObject>().Select(PatchRequest.FromJson).ToArray();
					var patchResult = Database.ApplyPatch(docId, context.GetEtag(), patchRequests, GetRequestTransaction(context));
					switch (patchResult)
					{
						case PatchResult.DocumentDoesNotExists:
							context.SetStatusToNotFound();
							break;
						case PatchResult.Patched:
							context.Response.Headers["Location"] = Database.Configuration.GetFullUrl("/docs/" + docId);
							context.WriteJson(new {Patched = true});
							break;
						default:
							throw new ArgumentOutOfRangeException("Value " + patchResult + " is not understood");
					}
					break;
			}
		}
开发者ID:ajaishankar,项目名称:ravendb,代码行数:52,代码来源:Document.cs

示例11: Batch

        private void Batch(IHttpContext context)
        {
            var jsonCommandArray = context.ReadJsonArray();
            var commands = new List<ICommandData>();

            var transactionInformation = GetRequestTransaction(context);
            foreach (JObject jsonCommand in jsonCommandArray)
            {
                commands.Add(CommandDataFactory.CreateCommand(jsonCommand, transactionInformation));
            }

            var batchResult = Database.Batch(commands);
            context.WriteJson(batchResult);
        }
开发者ID:kenegozi,项目名称:ravendb,代码行数:14,代码来源:DocumentBatch.cs

示例12: Respond

 public override void Respond(IHttpContext context)
 {
     var itemsToLoad = context.ReadJsonArray();
     var results = new JArray();
     Database.TransactionalStorage.Batch(actions =>
     {
         foreach (JToken item in itemsToLoad)
         {
             var documentByKey = actions.DocumentByKey(item.Value<string>(),
                 GetRequestTransaction(context));
             if (documentByKey == null)
                 continue;
             results.Add(documentByKey.ToJson());
         }
     });
     context.WriteJson(results);
 }
开发者ID:kenegozi,项目名称:ravendb,代码行数:17,代码来源:Queries.cs

示例13: Respond

        public override void Respond(IHttpContext context)
        {
            var src = context.Request.QueryString["from"];
            if (string.IsNullOrEmpty(src))
            {
                context.SetStatusToBadRequest();
                return;
            }
            while (src.EndsWith("/"))
                src = src.Substring(0, src.Length - 1);// remove last /, because that has special meaning for Raven
            if (string.IsNullOrEmpty(src))
            {
                context.SetStatusToBadRequest();
                return;
            }
			var array = context.ReadJsonArray();
            using (ReplicationContext.Enter())
            {
                Database.TransactionalStorage.Batch(actions =>
                {
                    string lastEtag = Guid.Empty.ToString();
                    foreach (JObject document in array)
                    {
                        var metadata = document.Value<JObject>("@metadata");
                        if(metadata[ReplicationConstants.RavenReplicationSource] == null)
                        {
                            // not sure why, old document from when the user didn't have replciation
                            // that we suddenly decided to replicate, choose the source for that
                            metadata[ReplicationConstants.RavenReplicationSource] = JToken.FromObject(src);
                        }
                        lastEtag = metadata.Value<string>("@etag");
                        var id = metadata.Value<string>("@id");
                        document.Remove("@metadata");
                        ReplicateDocument(actions, id, metadata, document, src);
                    }

                    Database.Put(ReplicationConstants.RavenReplicationSourcesBasePath + "/" + src, null,
                                 JObject.FromObject(new SourceReplicationInformation {LastEtag = new Guid(lastEtag)}),
                                 new JObject(), null);
                });
            }
        }
开发者ID:Rationalle,项目名称:ravendb,代码行数:42,代码来源:ReplicationResponder.cs

示例14: Batch

    	private void Batch(IHttpContext context)
        {
            var jsonCommandArray = context.ReadJsonArray();

    		var transactionInformation = GetRequestTransaction(context);
    		var commands = (from RavenJObject jsonCommand in jsonCommandArray
    		                select CommandDataFactory.CreateCommand(jsonCommand, transactionInformation))
    			.ToArray();

			context.Log(log => log.Debug(()=>
			{
				var sb = new StringBuilder();
				foreach (var commandData in commands)
				{
					sb.AppendFormat("\t{0} {1}{2}", commandData.Method, commandData.Key, Environment.NewLine);
				}
				return sb.ToString();
			}));

    		var batchResult = Database.Batch(commands);
            context.WriteJson(batchResult);
        }
开发者ID:larsudengaard,项目名称:ravendb,代码行数:22,代码来源:DocumentBatch.cs

示例15: Batch

    	private void Batch(IHttpContext context)
        {
            var jsonCommandArray = context.ReadJsonArray();

    		var transactionInformation = GetRequestTransaction(context);
    		var commands = (from JObject jsonCommand in jsonCommandArray
    		                select CommandDataFactory.CreateCommand(jsonCommand, transactionInformation))
    			.ToArray();

			context.Log(log =>
			{
				if (log.IsDebugEnabled)
				{
					foreach (var commandData in commands)
					{
						log.DebugFormat("\t{0} {1}", commandData.Method, commandData.Key);
					}
				}
			});

    		var batchResult = Database.Batch(commands);
            context.WriteJson(batchResult);
        }
开发者ID:philiphoy,项目名称:ravendb,代码行数:23,代码来源:DocumentBatch.cs


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