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


C# Json.ScriptedJsonPatcher类代码示例

本文整理汇总了C#中Raven.Database.Json.ScriptedJsonPatcher的典型用法代码示例。如果您正苦于以下问题:C# ScriptedJsonPatcher类的具体用法?C# ScriptedJsonPatcher怎么用?C# ScriptedJsonPatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: PatcherCanOutputObjectsCorrectly

        public void PatcherCanOutputObjectsCorrectly()
        {
            var doc = RavenJObject.Parse("{}");
            const string script = @"output(undefined);
                                output(true);
                                output(2);
                                output(2.5);
                                output('string');
                                output(null);
                                output([2, 'c']);
                                output({'a': 'c', 'f': { 'x' : 2}});"
                                ;

            var patch = new ScriptedPatchRequest()
            {
                Script = script
            };
            using (var scope = new DefaultScriptedJsonPatcherOperationScope())
            {
                var patcher = new ScriptedJsonPatcher();
                patcher.Apply(scope, doc, patch);
                Assert.Equal(8, patcher.Debug.Count);
                Assert.Equal("undefined", patcher.Debug[0]);
                Assert.Equal("True", patcher.Debug[1]);
                Assert.Equal("2", patcher.Debug[2]);
                Assert.Equal("2.5", patcher.Debug[3]);
                Assert.Equal("string", patcher.Debug[4]);
                Assert.Equal("null", patcher.Debug[5]);
                Assert.Equal("[2,\"c\"]", patcher.Debug[6]);
                Assert.Equal("{\"a\":\"c\",\"f\":{\"x\":2}}", patcher.Debug[7]);
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:32,代码来源:RavenDB_3264.cs

示例2: CanProcess

		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);"
				});
			}
		}
开发者ID:GorelH,项目名称:ravendb,代码行数:33,代码来源:UseX2JsScript.cs

示例3: ShouldWork

		public void ShouldWork()
		{
			var scriptedJsonPatcher = new ScriptedJsonPatcher();
			var result = scriptedJsonPatcher.Apply(new RavenJObject {{"Val", double.NaN}}, new ScriptedPatchRequest
			{
				Script = @"this.Finite = isFinite(this.Val);"
			});

			Assert.False(result.Value<bool>("Finite"));
		}
开发者ID:925coder,项目名称:ravendb,代码行数:10,代码来源:PatchingWithNaNAndIsFinite.cs

示例4: CanUseTrim

		public void CanUseTrim()
		{
			var doc = RavenJObject.Parse("{\"Email\":' [email protected] '}");
			const string script = "this.Email = this.Email.trim();";
			var patch = new ScriptedPatchRequest()
			{
				Script = script,
			};
			var result = new ScriptedJsonPatcher().Apply(doc, patch);
			Assert.Equal(result["Email"].Value<string>(), "[email protected]");
		}
开发者ID:robashton,项目名称:ravendb,代码行数:11,代码来源:AdvancedPatching.cs

示例5: Manual

 public void Manual()
 {
     var doc = RavenJObject.FromObject(new Product
     {
         Tags = new string[0],
     });
     var resultJson = new ScriptedJsonPatcher().Apply(doc, new ScriptedPatchRequest
     {
         Script = "this.Tags2 = this.Tags.Map(function(value) { return value; });",
     });
     Assert.Equal(0, resultJson.Value<RavenJArray>("Tags2").Length);
 }
开发者ID:925coder,项目名称:ravendb,代码行数:12,代码来源:LoDash.cs

示例6: ComplexVariableTest2

		public void ComplexVariableTest2()
		{
			const string email = "[email protected]";
			var doc = RavenJObject.Parse("{\"Contact\":null}");
			const string script = "this.Contact = contact;";
			var patch = new ScriptedPatchRequest()
			{
				Script = script,
				Values = { { "contact", new { Email = email } } }
			};
			var result = new ScriptedJsonPatcher().Apply(doc, patch);
			Assert.NotNull(result["Contact"]);
		}
开发者ID:arelee,项目名称:ravendb,代码行数:13,代码来源:AdvancedPatching.cs

示例7: ComplexVariableTest

		public void ComplexVariableTest()
		{
			const string email = "[email protected]";
			var doc = RavenJObject.Parse("{\"Email\":null}");
			const string script = "this.Email = data.Email;";
			var patch = new ScriptedPatchRequest()
			{
				Script = script,
				Values = { { "data", new { Email = email } } }
			};
			var result = new ScriptedJsonPatcher().Apply(doc, patch);
			Assert.Equal(result["Email"].Value<string>(),email);
		}
开发者ID:robashton,项目名称:ravendb,代码行数:13,代码来源:AdvancedPatching.cs

示例8: CanApplyBasicScriptAsPatch

		public void CanApplyBasicScriptAsPatch()
		{
			var doc = RavenJObject.FromObject(test);
			var resultJson = new ScriptedJsonPatcher().Apply(doc, new ScriptedPatchRequest { Script = sampleScript });
			var result = JsonConvert.DeserializeObject<CustomType>(resultJson.ToString());

			Assert.Equal("Something new", result.Id);
			Assert.Equal(2, result.Comments.Count);
			Assert.Equal("one test", result.Comments[0]);
			Assert.Equal("two", result.Comments[1]);
			Assert.Equal(12144, result.Value);
			Assert.Equal("err!!", resultJson["newValue"]);
		}
开发者ID:robashton,项目名称:ravendb,代码行数:13,代码来源:AdvancedPatching.cs

示例9: ShouldWork

        public void ShouldWork()
        {
            var scriptedJsonPatcher = new ScriptedJsonPatcher();
            using (var scope = new DefaultScriptedJsonPatcherOperationScope())
            { 
                var result = scriptedJsonPatcher.Apply(scope, new RavenJObject {{"Val", double.NaN}}, new ScriptedPatchRequest
                {
                    Script = @"this.Finite = isFinite(this.Val);"
                });

            Assert.False(result.Value<bool>("Finite"));
}
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:13,代码来源:PatchingWithNaNAndIsFinite.cs

示例10: ScriptPatchShouldGenerateNiceException

        public void ScriptPatchShouldGenerateNiceException()
        {
            using (var store = NewDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    session.Store(new SimpleUser { FirstName = "John", LastName = "Smith"});
                    session.SaveChanges();
                }

                store
                    .DatabaseCommands
                    .Put(
                        Constants.RavenJavascriptFunctions,
                        null,
                        RavenJObject.FromObject(new { Functions =
@"exports.a = function(value) { return  b(value); };
exports.b = function(v) { return c(v); }
exports.c = function(v) { throw 'oops'; }
"
                        }),
                        new RavenJObject());

                WaitForIndexing(store);

                var patcher = new ScriptedJsonPatcher(store.SystemDatabase);
                using (var scope = new ScriptedIndexResultsJsonPatcherScope(store.SystemDatabase, new HashSet<string>()))
                {
                    var e = Assert.Throws<InvalidOperationException>(() => patcher.Apply(scope, new RavenJObject(), new ScriptedPatchRequest
                    {
                        Script = @"var s = 1234; 
a(s);"
                    }));
                    Assert.Equal(@"Unable to execute JavaScript: 
var s = 1234; 
a(s);

Error: 
oops
Stacktrace:
[email protected]:3
[email protected]:2
[email protected]:1
[email protected]:2
anonymous [email protected]:1", e.Message);
                }
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:48,代码来源:RavenDB_3197.cs

示例11: CreateDocumentShouldThrowInvalidEtagException

		public void CreateDocumentShouldThrowInvalidEtagException()
		{
			var doc = RavenJObject.FromObject(test);
			var advancedJsonPatcher = new ScriptedJsonPatcher();
			var x = Assert.Throws<InvalidOperationException>(() => advancedJsonPatcher.Apply(doc, new ScriptedPatchRequest
			{
                Script = @"PutDocument('Items/1', { Property: 1}, {'@etag': 'invalid-etag' });"
			}));

			Assert.Contains("Invalid ETag value 'invalid-etag' for document 'Items/1'", x.InnerException.Message);
		}
开发者ID:robashton,项目名称:ravendb,代码行数:11,代码来源:AdvancedPatching.cs

示例12: CannotUseInfiniteLoop

		public void CannotUseInfiniteLoop()
		{
			var doc = RavenJObject.FromObject(test);
			var advancedJsonPatcher = new ScriptedJsonPatcher();
			var x = Assert.Throws<InvalidOperationException>(() => advancedJsonPatcher.Apply(doc, new ScriptedPatchRequest
																						{
																							Script = "while(true) {}"
																						}));

			Assert.Contains("Too many steps in script", x.Message);
		}
开发者ID:robashton,项目名称:ravendb,代码行数:11,代码来源:AdvancedPatching.cs

示例13: CanOutputDebugInformation

		public void CanOutputDebugInformation()
		{
			var doc = RavenJObject.FromObject(test);
			var advancedJsonPatcher = new ScriptedJsonPatcher();
			advancedJsonPatcher.Apply(doc, new ScriptedPatchRequest
			{
				Script = "output(this.Id)"
			});

			Assert.Equal("someId", advancedJsonPatcher.Debug[0]);
		}
开发者ID:robashton,项目名称:ravendb,代码行数:11,代码来源:AdvancedPatching.cs

示例14: CanOutputDebugInformation

        public void CanOutputDebugInformation()
        {
            var doc = RavenJObject.FromObject(test);
            using (var scope = new DefaultScriptedJsonPatcherOperationScope())
            {
                var advancedJsonPatcher = new ScriptedJsonPatcher();
                advancedJsonPatcher.Apply(scope, doc, new ScriptedPatchRequest
                {
                    Script = "output(this.Id)"
                });

                Assert.Equal("someId", advancedJsonPatcher.Debug[0]);
            }
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:14,代码来源:AdvancedPatching.cs

示例15: ApplyPatch

 public Tuple<PatchResultData, List<string>> ApplyPatch(string docId, Etag etag, ScriptedPatchRequest patch,
                                                TransactionInformation transactionInformation, bool debugMode = false)
 {
     ScriptedJsonPatcher scriptedJsonPatcher = null;
     var applyPatchInternal = ApplyPatchInternal(docId, etag, transactionInformation,
         jsonDoc =>
         {
             scriptedJsonPatcher = new ScriptedJsonPatcher(Database);
             return scriptedJsonPatcher.Apply(jsonDoc.ToJson(), patch, jsonDoc.SerializedSizeOnDisk, jsonDoc.Key);
         },
         () => null,
         () =>
         {
             if (scriptedJsonPatcher == null)
                 return null;
             return scriptedJsonPatcher
                 .GetPutOperations()
                 .ToList();
         }, debugMode);
     return Tuple.Create(applyPatchInternal, scriptedJsonPatcher == null ? new List<string>() : scriptedJsonPatcher.Debug);
 }
开发者ID:randacc,项目名称:ravendb,代码行数:21,代码来源:PatchActions.cs


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