本文整理汇总了C#中Jint.Engine.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# Engine.Execute方法的具体用法?C# Engine.Execute怎么用?C# Engine.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Jint.Engine
的用法示例。
在下文中一共展示了Engine.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessMessage
public void ProcessMessage(object source, Message message)
{
string jsonScript = "var msg = " + JsonConvert.SerializeXmlNode(message.GetXmlDocument(), Formatting.Indented, true);
Engine engine = new Engine();
engine.SetValue("message", message);
engine.Execute(jsonScript);
engine.Execute(Script);
engine.Execute("var jsonMsg = JSON.stringify(msg);");
JsValue obj = engine.GetValue("jsonMsg");
string jsonString = obj.AsString();
var document = JsonConvert.DeserializeXNode(jsonString, "HL7Message");
message.SetValueFrom(document);
}
示例2: CreateEngine
private Engine CreateEngine(ScriptedPatchRequest patch)
{
var scriptWithProperLines = NormalizeLineEnding(patch.Script);
// NOTE: we merged few first lines of wrapping script to make sure {0} is at line 0.
// This will all us to show proper line number using user lines locations.
var wrapperScript = String.Format(@"function ExecutePatchScript(docInner){{ (function(doc){{ {0} }}).apply(docInner); }};", scriptWithProperLines);
var jintEngine = new Engine(cfg =>
{
#if DEBUG
cfg.AllowDebuggerStatement();
#else
cfg.AllowDebuggerStatement(false);
#endif
cfg.LimitRecursion(1024);
cfg.MaxStatements(maxSteps);
});
AddScript(jintEngine, "Raven.Database.Json.lodash.js");
AddScript(jintEngine, "Raven.Database.Json.ToJson.js");
AddScript(jintEngine, "Raven.Database.Json.RavenDB.js");
jintEngine.Execute(wrapperScript, new ParserOptions
{
Source = "main.js"
});
return jintEngine;
}
示例3: UpdateKcInfo
private static Task UpdateKcInfo(double cacheHour = 1)
{
return Task.Run(() => {
infoLock.EnterUpgradeableReadLock();
if((DateTimeOffset.Now - lastUpdate).TotalHours < cacheHour) {
infoLock.ExitUpgradeableReadLock();
return;
}
infoLock.EnterWriteLock();
try {
if((DateTimeOffset.Now - lastUpdate).TotalHours < cacheHour) {
return;
}
Engine interpreter = new Engine(cfg => cfg
.LocalTimeZone(TimeZoneInfo.FindSystemTimeZoneById("Tokyo Standard Time"))
.Culture(System.Globalization.CultureInfo.GetCultureInfo("ja-JP"))
.MaxStatements(100)
.LimitRecursion(2));
var hwr = Forwarder.CreateRequest(KcsConstantsJs);
hwr.Method = "GET";
using(var resp = hwr.GetResponse())
using(var jsRdr = new StreamReader(resp.GetResponseStream()))
interpreter.Execute(jsRdr.ReadToEnd());
var urlInfo = interpreter.GetValue("ConstURLInfo");
kcLoginUrl = interpreter.GetValue(urlInfo, "LoginURL").AsString();
//kcTokenUrl = interpreter.GetValue(urlInfo, "GetTokenURL").AsString();
kcWorldUrl = interpreter.GetValue(urlInfo, "GetUserWorldURL").AsString();
var maintenanceInfo = interpreter.GetValue("MaintenanceInfo");
maintenanceOngoing = interpreter.GetValue(maintenanceInfo, "IsDoing").AsNumber() != 0;
maintenanceStart = UnixTimestamp.MillisecondTimestampToDateTimeOffset(interpreter.GetValue(maintenanceInfo, "StartDateTime").AsNumber());
maintenanceEnd = UnixTimestamp.MillisecondTimestampToDateTimeOffset(interpreter.GetValue(maintenanceInfo, "EndDateTime").AsNumber());
servers.Clear();
var serverInfo = interpreter.GetValue("ConstServerInfo");
foreach(var kv in serverInfo.AsObject().GetOwnProperties()) {
if(kv.Value.Value?.IsString() != true) continue;
servers.Add(kv.Key, kv.Value.Value.Value.AsString());
}
lastUpdate = DateTimeOffset.UtcNow;
} finally {
infoLock.ExitWriteLock();
infoLock.ExitUpgradeableReadLock();
}
});
}
示例4: PrepareEngine
static Engine PrepareEngine(string code)
{
Engine e = new Engine(f => f.AllowClr(typeof(CDSData).Assembly));
e.SetValue("Log", new Action<Object>(Console.WriteLine)); //change to write data to a node rather than to console later
e.Execute("var CDSCommon = importNamespace('CDS.Common');");
e.Execute(code);
return e;
}
示例5: CoffeeScriptPluginLoader
/// <summary>
/// Initializes a new instance of the CoffeeScriptPluginLoader class
/// </summary>
/// <param name="engine"></param>
public CoffeeScriptPluginLoader(Engine engine)
{
JavaScriptEngine = engine;
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(compilerResourcePath))
using (var reader = new StreamReader(stream))
engine.Execute(reader.ReadToEnd(), new ParserOptions { Source = "CoffeeScriptCompiler" });
engine.Execute("function __CompileScript(name){return CoffeeScript.compile(name+\"=\\n\"+__CoffeeSource.replace(/^/gm, ' '),{bare: true})}");
}
示例6: FuncTest
public void FuncTest()
{
var engine = new Engine()
.SetValue("hello", (Func<string, string>)(a => a));
engine.Execute(@"
function getWord(word) {
return hello(word);
};
getWord('Hello World');");
var value = engine.GetCompletionValue().ToObject();
Assert.AreEqual("Hello World", value);
engine.Execute("getWord('worldbye')");
value = engine.GetCompletionValue().ToObject();
Assert.AreEqual("worldbye", value);
}
示例7: loop
public void loop()
{
string loopscript = File.ReadAllText("scripts/loop.js");
Jint.Engine jsint = new Jint.Engine();
jsint.SetValue("debuglog", new Action<object>(Console.WriteLine));
jsint.Execute(loopscript);
}
示例8: TestToDateStrings
public void TestToDateStrings()
{
var testDates = new[] { new DateTime(2000,1,1), new DateTime(2000, 1, 1, 0, 15, 15, 15), new DateTime(1900, 1, 1, 0, 15, 15, 15), new DateTime(1999, 6, 1, 0, 15, 15, 15) };
foreach(var tzId in new[] { "Pacific Standard Time", "New Zealand Standard Time", "India Standard Time" })
{
Debug.WriteLine(tzId);
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(tzId);
var engine = new Engine(ctx => ctx.LocalTimeZone(tzi));
foreach (var d in testDates)
{
var td = new DateTimeOffset(d, tzi.GetUtcOffset(d));
engine.Execute(
string.Format("var d = new Date({0},{1},{2},{3},{4},{5},{6});", td.Year, td.Month - 1, td.Day, td.Hour, td.Minute, td.Second, td.Millisecond));
Assert.AreEqual(td.ToString("ddd MMM dd yyyy HH:mm:ss 'GMT'zzz"), engine.Execute("d.toString();").GetCompletionValue().ToString());
Assert.AreEqual(td.UtcDateTime.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'"), engine.Execute("d.toISOString();").GetCompletionValue().ToString());
}
}
}
示例9: Evaluate
public bool Evaluate(object source, Message message)
{
Engine engine = new Engine();
engine.SetValue("message", message);
engine.Execute(Script);
if (!engine.GetCompletionValue().IsBoolean())
{
return false;
}
return engine.GetCompletionValue().AsBoolean();
}
示例10: ActionTest
public void ActionTest()
{
var engine = new Engine()
.SetValue("log", new Action<object>(Console.WriteLine))
;
engine.Execute(@"
function hello() {
log('Hello World');
};
hello();
");
}
示例11: CompileMap
public MapDelegate CompileMap(string source, string language)
{
if(!language.Equals("javascript")) {
return null;
}
source = source.Replace("function", "function _f1");
return (doc, emit) =>
{
var engine = new Engine().SetValue("log", new Action<object>((line) => Log.I("JSViewCompiler", line.ToString())));
engine.SetValue("emit", emit);
engine.Execute(source).Invoke("_f1", doc);
};
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:15,代码来源:JSViewCompiler.cs
示例12: Initialize
public void Initialize(SmugglerDatabaseOptions databaseOptions)
{
if (databaseOptions == null || string.IsNullOrEmpty(databaseOptions.TransformScript))
return;
jint = new Engine(cfg =>
{
cfg.AllowDebuggerStatement(false);
cfg.MaxStatements(databaseOptions.MaxStepsForTransformScript);
});
jint.Execute(string.Format(@"
function Transform(docInner){{
return ({0}).apply(this, [docInner]);
}};", databaseOptions.TransformScript));
}
示例13: ScriptContext
object IScriptingProvider.Execute(string script, ScriptExecutionOptions options)
{
ScriptContext context = new ScriptContext(options);
Engine eng = new Engine(_ => _.Strict());
eng.SetValue("context", context);
object v = eng.Execute(script);
if (context.ret != null)
{
return context.ret;
}
return v;
}
示例14: ProcessWithJint
private object ProcessWithJint(string model, object attrs)
{
var engine = new Engine();
// engine.SetValue("model", stream.ToString());
engine.SetValue("console", new
{
log = new Action<object>(Logger.Log)
});
// throw exception when execution fails
engine.Execute(_script);
var value = engine.Invoke("transform", model, JsonUtility.Serialize(attrs)).ToObject();
// var value = engine.GetValue("model").ToObject();
// The results generated
return value;
}
示例15: ValidateCustomFunctions
private void ValidateCustomFunctions(RavenJObject document)
{
var engine = new Engine(cfg =>
{
cfg.AllowDebuggerStatement();
cfg.MaxStatements(1000);
});
engine.Execute(string.Format(@"
var customFunctions = function() {{
var exports = {{ }};
{0};
return exports;
}}();
for(var customFunction in customFunctions) {{
this[customFunction] = customFunctions[customFunction];
}};", document.Value<string>("Functions")));
}