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


C# IHttpContext.ReadJsonObject方法代码示例

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


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

示例1: RespondToAdmin

		public override void RespondToAdmin(IHttpContext context)
		{
			if (EnsureSystemDatabase(context) == false)
				return;

			var restoreRequest = context.ReadJsonObject<RestoreRequest>();

			var ravenConfiguration = new RavenConfiguration();
			if (File.Exists(Path.Combine(restoreRequest.RestoreLocation, "Raven.ravendb")))
			{
				ravenConfiguration.DefaultStorageTypeName = "Raven.Storage.Managed.TransactionalStorage, Raven.Storage.Managed";
			}
			else if (Directory.Exists(Path.Combine(restoreRequest.RestoreLocation, "new")))
			{
				ravenConfiguration.DefaultStorageTypeName = "Raven.Storage.Esent.TransactionalStorage, Raven.Storage.Esent";
			}
			var restoreDoc = new List<string>();

			// Commented out unfinished code to get it to compile
			//		    DocumentDatabase.Restore(ravenConfiguration, restoreRequest.RestoreLocation, restoreRequest.DatabaseLocation,
			//		                             msg =>
			//		                             {
			//
			//		                             });
			//            SystemDatabase.
		}
开发者ID:denno-secqtinstien,项目名称:ravendb,代码行数:26,代码来源:AdminRestore.cs

示例2: RespondToAdmin

		public override void RespondToAdmin(IHttpContext context)
		{
			var backupRequest = context.ReadJsonObject<BackupRequest>();
			var incrementalString = context.Request.QueryString["incremental"];
			bool incrementalBackup;
			if (bool.TryParse(incrementalString, out incrementalBackup) == false)
				incrementalBackup = false;
			if (backupRequest.DatabaseDocument == null && Database.Name != null)
			{
				if (Database.Name.Equals(Constants.SystemDatabase, StringComparison.OrdinalIgnoreCase))
				{
					backupRequest.DatabaseDocument = new DatabaseDocument {Id = Constants.SystemDatabase};
				}
				else
				{
					var jsonDocument = SystemDatabase.Get("Raven/Databases/" + Database.Name, null);
					if (jsonDocument != null)
					{
						backupRequest.DatabaseDocument = jsonDocument.DataAsJson.JsonDeserialization<DatabaseDocument>();
						server.Unprotect(backupRequest.DatabaseDocument);
						backupRequest.DatabaseDocument.Id = Database.Name;
					}
				}
			}
			Database.StartBackup(backupRequest.BackupLocation, incrementalBackup, backupRequest.DatabaseDocument);
			context.SetStatusToCreated(BackupStatus.RavenBackupStatusDocumentKey);
		}
开发者ID:925coder,项目名称:ravendb,代码行数:27,代码来源:AdminBackup.cs

示例3: HandlePut

	    private void HandlePut(IHttpContext context, string transformer)
	    {
	        var data = context.ReadJsonObject<TransformerDefinition>();
	        if (data == null || string.IsNullOrEmpty(data.TransformResults))
	        {
	            context.SetStatusToBadRequest();
	            context.Write("Expected json document with 'TransformResults' property");
	            return;
	        }

	        try
	        {
	            var transformerName = Database.PutTransform(transformer, data);
	            context.SetStatusToCreated("/transformers");
	            context.WriteJson(new {Transformer = transformerName});
	        }
            catch (Exception ex)
            {
                context.SetStatusToBadRequest();
                context.WriteJson(new
                {
                    Message = ex.Message,
                    Error = ex.ToString()
                });
            }
	    }
开发者ID:nzaugg,项目名称:ravendb,代码行数:26,代码来源:Transformers.cs

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

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

示例6: RespondToAdmin

		public override void RespondToAdmin(IHttpContext context)
		{
			var backupRequest = context.ReadJsonObject<BackupRequest>();
			var incrementalString = context.Request.QueryString["incremental"];
			bool incrementalBackup;
			if (bool.TryParse(incrementalString, out incrementalBackup) == false)
				incrementalBackup = false;
			Database.StartBackup(backupRequest.BackupLocation, incrementalBackup, backupRequest.DatabaseDocument);
			context.SetStatusToCreated(BackupStatus.RavenBackupStatusDocumentKey);
		}
开发者ID:nberardi,项目名称:ravendb,代码行数:10,代码来源:AdminBackup.cs

示例7: Put

		private void Put(IHttpContext context, string index)
		{
			var data = context.ReadJsonObject<IndexDefinition>();
			if (data == null || (data.Map == null && (data.Maps == null || data.Maps.Count == 0)))
			{
				context.SetStatusToBadRequest();
				context.Write("Expected json document with 'Map' or 'Maps' property");
				return;
			}
			context.SetStatusToCreated("/indexes/" + index);
			context.WriteJson(new { Index = Database.PutIndex(index, data) });
		}
开发者ID:MikeEast,项目名称:ravendb,代码行数:12,代码来源:Index.cs

示例8: RespondToAdmin

		public override void RespondToAdmin(IHttpContext context)
		{
			var backupRequest = context.ReadJsonObject<BackupRequest>();
			var incrementalString = context.Request.QueryString["incremental"];
			bool incrementalBackup;
			if (bool.TryParse(incrementalString, out incrementalBackup) == false)
				incrementalBackup = false;
			if (backupRequest.DatabaseDocument == null)
			{
				backupRequest.DatabaseDocument = SystemDatabase.Get("Raven/Databases/" + Database.Name, null).DataAsJson.JsonDeserialization<DatabaseDocument>();
			}
			Database.StartBackup(backupRequest.BackupLocation, incrementalBackup, backupRequest.DatabaseDocument);
			context.SetStatusToCreated(BackupStatus.RavenBackupStatusDocumentKey);
		}
开发者ID:robashton,项目名称:ravendb,代码行数:14,代码来源:AdminBackup.cs

示例9: Respond

		public override void Respond(IHttpContext context)
		{
			var results = new List<GetResponse>();
			var requests = context.ReadJsonObject<GetRequest[]>();
			Database.TransactionalStorage.Batch(accessor => // ensure all queries are transactionally the same
			{
				foreach (var req in requests)
				{
					var ctx = new MultiGetHttpContext(Settings, context, req);
					server.HandleActualRequest(ctx);
					results.Add(ctx.Complete());
				}
			});
			context.WriteJson(results);
		}
开发者ID:larsudengaard,项目名称:ravendb,代码行数:15,代码来源:MultiGet.cs

示例10: Respond

		public override void Respond(IHttpContext context)
		{
			if(context.IsAdministrator() == false)
			{
				context.SetStatusToUnauthorized();
				context.WriteJson(new
				{
					Error = "Only administrators can initiate a backup procedure"
				});
			    return;
			}

			var backupRequest = context.ReadJsonObject<BackupRequest>();
			Database.StartBackup(backupRequest.BackupLocation);
			context.SetStatusToCreated(BackupStatus.RavenBackupStatusDocumentKey);
		}
开发者ID:JPT123,项目名称:ravendb,代码行数:16,代码来源:AdminBackup.cs

示例11: Respond

		public override void Respond(IHttpContext context)
		{
			if(context.User.Identity.IsAuthenticated == false ||
				context.User.IsInRole("Administrators"))
			{
				context.SetStatusToForbidden();
				context.WriteJson(new
				{
					Error = "Only administrators can initiate a backup procedure"
				});
			}

			var backupRequest = context.ReadJsonObject<BackupRequest>();
			Database.StartBackup(backupRequest.BackupLocation);
			context.SetStatusToCreated(BackupStatus.RavenBackupStatusDocumentKey);
		}
开发者ID:dplaskon,项目名称:ravendb,代码行数:16,代码来源:AdminBackup.cs

示例12: RespondToAdmin

		public override void RespondToAdmin(IHttpContext context)
		{
			if (EnsureSystemDatabase(context) == false)
				return;

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

			DatabaseDocument dbDoc;
			var docKey = "Raven/Databases/" + db;
			switch (context.Request.HttpMethod)
			{
				case "GET":
					var document = Database.Get(docKey, null);
					if (document == null)
					{
						context.SetStatusToNotFound();
						return;
					}
					dbDoc = document.DataAsJson.JsonDeserialization<DatabaseDocument>();
					dbDoc.Id = db;	
					server.Unprotect(dbDoc);
					context.WriteJson(dbDoc);
					break;
				case "PUT":
					dbDoc = context.ReadJsonObject<DatabaseDocument>();
					server.Protect(dbDoc);
					var json = RavenJObject.FromObject(dbDoc);
					json.Remove("Id");

					Database.Put(docKey, null, json, new RavenJObject(), null);
					break;
				case "DELETE":
					var configuration = server.CreateTenantConfiguration(db);
					if (configuration == null)
						return;
					Database.Delete(docKey, null, null);
					bool result;
					if(bool.TryParse(context.Request.QueryString["hard-delete"], out result) && result)
					{
						IOExtensions.DeleteDirectory(configuration.DataDirectory);	
					}
					break;
			}
		}
开发者ID:arelee,项目名称:ravendb,代码行数:45,代码来源:AdminDatabases.cs

示例13: RespondToAdmin

		public override void RespondToAdmin(IHttpContext context)
		{
			if (EnsureSystemDatabase(context) == false)
				return;

			var restoreRequest = context.ReadJsonObject<RestoreRequest>();

			var ravenConfiguration = new RavenConfiguration();
			if (File.Exists(Path.Combine(restoreRequest.RestoreLocation, "Raven.ravendb")))
			{
				ravenConfiguration.DefaultStorageTypeName = "Raven.Storage.Managed.TransactionalStorage, Raven.Storage.Managed";
			}
			else if (Directory.Exists(Path.Combine(restoreRequest.RestoreLocation, "new")))
			{
				ravenConfiguration.DefaultStorageTypeName = "Raven.Storage.Esent.TransactionalStorage, Raven.Storage.Esent";
			}

			var restoreStatus = new List<string>();

			DocumentDatabase.Restore(ravenConfiguration, restoreRequest.RestoreLocation, restoreRequest.DatabaseLocation,
			                         msg =>
			                         {
				                         restoreStatus.Add(msg);
				                         SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
											 RavenJObject.FromObject(new {restoreStatus}), new RavenJObject(), null);
			                         });

			if (File.Exists(Path.Combine(restoreRequest.RestoreLocation, "Database.Document")))
			{
				var databaseDocumentText = File.ReadAllText(Path.Combine(restoreRequest.RestoreLocation, "Database.Document"));
				var databaseDocument = RavenJObject.Parse(databaseDocumentText).JsonDeserialization<DatabaseDocument>();
				if (databaseDocument == null)
					return;

				if (!string.IsNullOrWhiteSpace(restoreRequest.DatabaseLocation))
					databaseDocument.Settings[Constants.RavenDataDir] = restoreRequest.DatabaseLocation;
				if (!string.IsNullOrWhiteSpace(restoreRequest.DatabaseName))
					databaseDocument.Id = "Raven/Databases/" + restoreRequest.DatabaseName;
				SystemDatabase.Put(databaseDocument.Id, null, RavenJObject.FromObject(databaseDocument), new RavenJObject(), null);

				restoreStatus.Add("The new database was created");
				SystemDatabase.Put(RestoreStatus.RavenRestoreStatusDocumentKey, null,
					RavenJObject.FromObject(new { restoreStatus }), new RavenJObject(), null);
			}
		}
开发者ID:remcoros,项目名称:ravendb,代码行数:45,代码来源:AdminRestore.cs

示例14: Respond

		public override void Respond(IHttpContext context)
		{
			if (recursive.Value)
				throw new InvalidOperationException("Nested requests to multi_get are not supported");
			recursive.Value = true;
			try
			{
				var requests = context.ReadJsonObject<GetRequest[]>();
				var results = new GetResponse[requests.Length];

				Executerequests(context, Settings, results, requests);
				
				context.WriteJson(results);
			}
			finally
			{
				recursive.Value = false;
			}
		}
开发者ID:nhsevidence,项目名称:ravendb,代码行数:19,代码来源:MultiGet.cs

示例15: Respond

		public override void Respond(IHttpContext context)
		{
			if (context.User.IsAdministrator() == false)
			{
				context.SetStatusToUnauthorized();
				context.WriteJson(new
				{
					Error = "Only administrators can initiate a backup procedure"
				});
			    return;
			}

			var backupRequest = context.ReadJsonObject<BackupRequest>();
			var incrementalString = context.Request.QueryString["incremental"];
			bool incrementalBackup;
			if (bool.TryParse(incrementalString, out incrementalBackup) == false)
				incrementalBackup = false;
			Database.StartBackup(backupRequest.BackupLocation, incrementalBackup);
			context.SetStatusToCreated(BackupStatus.RavenBackupStatusDocumentKey);
		}
开发者ID:Korn1699,项目名称:ravendb,代码行数:20,代码来源:AdminBackup.cs


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