本文整理汇总了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.
}
示例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);
}
示例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()
});
}
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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) });
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例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;
}
}
示例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);
}