This repository was archived by the owner on Apr 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathJsDispatcher.cs
61 lines (52 loc) · 2.67 KB
/
JsDispatcher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//******************************************************************************
// <copyright file="license.md" company="RawCMS project (https://github.com/arduosoft/RawCMS)">
// Copyright (c) 2019 RawCMS project (https://github.com/arduosoft/RawCMS)
// RawCMS project is released under GPL3 terms, see LICENSE file on repository root at https://github.com/arduosoft/RawCMS .
// </copyright>
// <author>Daniele Fontani, Emanuele Bucarelli, Francesco Mina'</author>
// <autogenerated>true</autogenerated>
//******************************************************************************
using Jint;
using Newtonsoft.Json.Linq;
using RawCMS.Library.JavascriptClient;
using RawCMS.Library.Service;
using System;
using System.Collections.Generic;
namespace RawCMS.Library.Lambdas
{
public abstract class JsDispatcher : DataProcessLambda
{
public override string Name => "JsDispatcher";
public override string Description => "JsDispatcher";
protected readonly EntityService entityService;
private readonly CRUDService crudService;
public JsDispatcher(EntityService entityService, CRUDService crudService)
{
{
this.entityService = entityService;
this.crudService = crudService;
}
}
public override void Execute(string collection, ref JObject item, ref Dictionary<string, object> dataContext)
{
var eventName = Stage.ToString().Replace("Operation", string.Empty) + Operation.ToString();
var settings = this.entityService.GetByName(collection);
if (settings != null)
{
var eventScript = settings.Events?[eventName];
if (eventScript != null &&
!string.IsNullOrEmpty(Convert.ToString(eventScript)))
{
Dictionary<string, object> input = item.ToObject<Dictionary<string, object>>();
Engine engine = new Engine((x) => { x.AllowClr(typeof(JavascriptRestClient).Assembly); x.AllowClr(typeof(JavascriptRestClientRequest).Assembly); });
engine.SetValue("RAWCMSRestClient", Jint.Runtime.Interop.TypeReference.CreateTypeReference(engine, typeof(JavascriptRestClient)));
engine.SetValue("RAWCMSRestClientRequest", Jint.Runtime.Interop.TypeReference.CreateTypeReference(engine, typeof(JavascriptRestClientRequest)));
engine.SetValue("RAWCMSCrudService", crudService);
engine.SetValue("item", input);
engine.Execute(eventScript.ToString());
item = JObject.FromObject(input);
}
}
}
}
}