Raven.Database.Json.ScriptedJsonPatcher.Apply C# (CSharp) 메소드

Apply() 공개 메소드

public Apply ( RavenJObject document, Raven.Abstractions.Data.ScriptedPatchRequest patch, int size, string docId = null ) : RavenJObject
document RavenJObject
patch Raven.Abstractions.Data.ScriptedPatchRequest
size int
docId string
리턴 RavenJObject
		public RavenJObject Apply(RavenJObject document, ScriptedPatchRequest patch, int size = 0, string docId = null)
		{
			if (document == null)
				return null;

			if (String.IsNullOrEmpty(patch.Script))
				throw new InvalidOperationException("Patch script must be non-null and not empty");

			var resultDocument = ApplySingleScript(document, patch, size, docId);
			if (resultDocument != null)
				document = resultDocument;
			return document;
		}

Usage Example

예제 #1
0
		public void CanProcess()
		{
			var document = new RavenJObject
			{
				{
					"Data", new RavenJObject
					{
						{"Title", "Hi"}
					}
				}
			};

			const string name = @"Raven.Tests.Patching.x2js.js";
			var manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
			var code = new StreamReader(manifestResourceStream).ReadToEnd();

			var jsonPatcher = new ScriptedJsonPatcher();
			using (var scope = new DefaultScriptedJsonPatcherOperationScope())
			{
				scope.CustomFunctions = new JsonDocument
				{
					DataAsJson = new RavenJObject
					{
						{"Functions", code}
					}
				};

				jsonPatcher.Apply(scope, document, new ScriptedPatchRequest
				{
					Script = "this.Xml = js2x(this.Data);"
				});
			}
		}
All Usage Examples Of Raven.Database.Json.ScriptedJsonPatcher::Apply