public static ICommandData CreateCommand(RavenJObject jsonCommand) { var key = jsonCommand["Key"].Value <string>(); switch (jsonCommand.Value <string>("Method")) { case "PUT": var putCommand = new PutCommandData { Key = key, Etag = GetEtagFromCommand(jsonCommand), Document = jsonCommand["Document"] as RavenJObject, Metadata = jsonCommand["Metadata"] as RavenJObject, }; ValidateMetadataKeys(putCommand.Metadata); return(putCommand); case "DELETE": return(new DeleteCommandData { Key = key, Etag = GetEtagFromCommand(jsonCommand), }); case "PATCH": return(new PatchCommandData { Key = key, Etag = GetEtagFromCommand(jsonCommand), Metadata = jsonCommand["Metadata"] as RavenJObject, Patches = jsonCommand .Value <RavenJArray>("Patches") .Cast <RavenJObject>() .Select(PatchRequest.FromJson) .ToArray(), PatchesIfMissing = jsonCommand["PatchesIfMissing"] == null ? null : jsonCommand .Value <RavenJArray>("PatchesIfMissing") .Cast <RavenJObject>() .Select(PatchRequest.FromJson) .ToArray(), SkipPatchIfEtagMismatch = jsonCommand.ContainsKey("SkipPatchIfEtagMismatch") && jsonCommand.Value <bool>("SkipPatchIfEtagMismatch") }); case "EVAL": var debug = jsonCommand["DebugMode"].Value <bool>(); return(new ScriptedPatchCommandData { Key = key, Metadata = jsonCommand["Metadata"] as RavenJObject, Etag = GetEtagFromCommand(jsonCommand), Patch = ScriptedPatchRequest.FromJson(jsonCommand.Value <RavenJObject>("Patch")), PatchIfMissing = jsonCommand["PatchIfMissing"] == null ? null : ScriptedPatchRequest.FromJson(jsonCommand.Value <RavenJObject>("PatchIfMissing")), DebugMode = debug }); default: throw new ArgumentException("Batching only supports PUT, PATCH, EVAL and DELETE."); } }
public async Task <HttpResponseMessage> BulkEval(string id) { using (var cts = new CancellationTokenSource()) using (var timeout = cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatbaseOperationTimeout)) { var databaseBulkOperations = new DatabaseBulkOperations(Database, GetRequestTransaction(), cts.Token, timeout); var advPatchRequestJson = await ReadJsonObjectAsync <RavenJObject>(); var advPatch = ScriptedPatchRequest.FromJson(advPatchRequestJson); return(OnBulkOperation((index, query, allowStale) => databaseBulkOperations.UpdateByIndex(index, query, advPatch, allowStale), id)); } }
public async Task <HttpResponseMessage> DocEval(string docId) { var advPatchRequestJson = await ReadJsonObjectAsync <RavenJObject>(); var advPatch = ScriptedPatchRequest.FromJson(advPatchRequestJson); bool testOnly; bool.TryParse(GetQueryStringValue("test"), out testOnly); var advPatchResult = Database.Patches.ApplyPatch(docId, GetEtag(), advPatch, GetRequestTransaction(), testOnly); return(ProcessPatchResult(docId, advPatchResult.Item1.PatchResult, advPatchResult.Item2, advPatchResult.Item1.Document)); }
public static ICommandData CreateCommand(RavenJObject jsonCommand, TransactionInformation transactionInformation) { var key = jsonCommand["Key"].Value <string>(); switch (jsonCommand.Value <string>("Method")) { case "PUT": return(new PutCommandData { Key = key, Etag = GetEtagFromCommand(jsonCommand), Document = jsonCommand["Document"] as RavenJObject, Metadata = jsonCommand["Metadata"] as RavenJObject, TransactionInformation = transactionInformation }); case "DELETE": return(new DeleteCommandData { Key = key, Etag = GetEtagFromCommand(jsonCommand), TransactionInformation = transactionInformation }); case "PATCH": return(new PatchCommandData { Key = key, Etag = GetEtagFromCommand(jsonCommand), TransactionInformation = transactionInformation, Patches = jsonCommand .Value <RavenJArray>("Patches") .Cast <RavenJObject>() .Select(PatchRequest.FromJson) .ToArray() }); case "EVAL": var debug = jsonCommand["DebugMode"].Value <bool>(); return(new ScriptedPatchCommandData { Key = key, Etag = GetEtagFromCommand(jsonCommand), TransactionInformation = transactionInformation, Patch = ScriptedPatchRequest.FromJson(jsonCommand.Value <RavenJObject>("Patch")), DebugMode = debug }); default: throw new ArgumentException("Batching only supports PUT, PATCH, EVAL and DELETE."); } }
public async Task <HttpResponseMessage> BulkEval(string id) { // we don't use using because execution is async var cts = new CancellationTokenSource(); var timeout = cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout); var databaseBulkOperations = new DatabaseBulkOperations(Database, GetRequestTransaction(), cts, timeout); var advPatchRequestJson = await ReadJsonObjectAsync <RavenJObject>(); var advPatch = ScriptedPatchRequest.FromJson(advPatchRequestJson); return(OnBulkOperation((index, query, options) => databaseBulkOperations.UpdateByIndex(index, query, advPatch, options), id, cts)); }
public async Task <HttpResponseMessage> BulkEval(string id) { RavenJObject advPatchRequestJson; try { advPatchRequestJson = await ReadJsonObjectAsync <RavenJObject>().ConfigureAwait(false); } catch (InvalidOperationException e) { if (Log.IsDebugEnabled) { Log.DebugException("Failed to deserialize document batch request.", e); } return(GetMessageWithObject(new { Message = "Could not understand json, please check its validity." }, (HttpStatusCode)422)); //http code 422 - Unprocessable entity } catch (InvalidDataException e) { if (Log.IsDebugEnabled) { Log.DebugException("Failed to deserialize document batch request.", e); } return(GetMessageWithObject(new { e.Message }, (HttpStatusCode)422)); //http code 422 - Unprocessable entity } // we don't use using because execution is async var cts = new CancellationTokenSource(); var timeout = cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout); var databaseBulkOperations = new DatabaseBulkOperations(Database, GetRequestTransaction(), cts, timeout); var advPatch = ScriptedPatchRequest.FromJson(advPatchRequestJson); return(OnBulkOperation((index, query, options, reportProgress) => databaseBulkOperations.UpdateByIndex(index, query, advPatch, options, reportProgress), id, timeout)); }
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, null); break; case "EVAL": var advPatchRequestJson = context.ReadJsonObject <RavenJObject>(); var advPatch = ScriptedPatchRequest.FromJson(advPatchRequestJson); bool testOnly; bool.TryParse(context.Request.QueryString["test"], out testOnly); var advPatchResult = Database.ApplyPatch(docId, context.GetEtag(), advPatch, GetRequestTransaction(context), testOnly); ProcessPatchResult(context, docId, advPatchResult.Item1.PatchResult, advPatchResult.Item2, advPatchResult.Item1.Document); break; } }