本文整理汇总了C#中Jint.Engine类的典型用法代码示例。如果您正苦于以下问题:C# Engine类的具体用法?C# Engine怎么用?C# Engine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Engine类属于Jint命名空间,在下文中一共展示了Engine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Plugin
public Plugin(DirectoryInfo directory, string name, string code)
{
Name = name;
Code = code;
RootDirectory = directory;
Timers = new Dictionary<String, TimedEvent>();
Engine = new Engine(cfg => cfg.AllowClr(typeof(UnityEngine.GameObject).Assembly,
typeof(uLink.NetworkPlayer).Assembly,
typeof(PlayerInventory).Assembly))
.SetValue("Server", Server.GetServer())
.SetValue("DataStore", DataStore.GetInstance())
.SetValue("Util", Util.GetUtil())
.SetValue("World", World.GetWorld())
.SetValue("Lookup", LookUp.GetLookUp())
.SetValue("Plugin", this)
.Execute(code);
Logger.LogDebug(string.Format("{0} AllowClr for Assemblies: {1} {2} {3}", brktname,
typeof(UnityEngine.GameObject).Assembly.GetName().Name,
typeof(uLink.NetworkPlayer).Assembly.GetName().Name,
typeof(PlayerInventory).Assembly.GetName().Name));
try {
Engine.Invoke("On_PluginInit");
} catch {
}
}
示例2: CheckinScript
public void CheckinScript(ScriptedPatchRequest request, Engine context, RavenJObject customFunctions)
{
CachedResult cacheByCustomFunctions;
var patchRequestAndCustomFunctionsTuple = new ScriptedPatchRequestAndCustomFunctionsToken(request, customFunctions);
if (cacheDic.TryGetValue(patchRequestAndCustomFunctionsTuple, out cacheByCustomFunctions))
{
if (cacheByCustomFunctions.Queue.Count > 20)
return;
cacheByCustomFunctions.Queue.Enqueue(context);
return;
}
cacheDic.AddOrUpdate(patchRequestAndCustomFunctionsTuple, patchRequest =>
{
var queue = new ConcurrentQueue<Engine>();
return new CachedResult
{
Queue = queue,
Timestamp = SystemTime.UtcNow,
Usage = 1
};
}, (patchRequest, result) =>
{
result.Queue.Enqueue(context);
return result;
});
}
示例3: JavaScriptPlugin
/// <summary>
/// Initializes a new instance of the JavaScriptPlugin class
/// </summary>
/// <param name="filename"></param>
/// <param name="engine"></param>
/// <param name="watcher"></param>
internal JavaScriptPlugin(string filename, Engine engine, FSWatcher watcher)
{
// Store filename
Filename = filename;
JavaScriptEngine = engine;
this.watcher = watcher;
}
示例4: Initialize
public bool Initialize(UserGameInfo game, GameProfile profile)
{
this.userGame = game;
this.profile = profile;
// see if we have any save game to backup
gen = game.Game as GenericGameInfo;
if (gen == null)
{
// you fucked up
return false;
}
engine = new Engine();
engine.SetValue("Options", profile.Options);
data = new Dictionary<string, string>();
data.Add(NucleusFolderEnum.GameFolder.ToString(), Path.GetDirectoryName(game.ExePath));
if (gen.SaveType == GenericGameSaveType.None)
{
return true;
}
string saveFile = ProcessPath(gen.SavePath);
GameManager.Instance.BeginBackup(game.Game);
GameManager.Instance.BackupFile(game.Game, saveFile);
return true;
}
示例5: ObjectFromConfig
/// <summary>
/// Copies and translates the contents of the specified config file into the specified object
/// </summary>
/// <param name="config"></param>
/// <param name="engine"></param>
/// <returns></returns>
public static ObjectInstance ObjectFromConfig(DynamicConfigFile config, Engine engine)
{
var objInst = new ObjectInstance(engine) {Extensible = true};
foreach (var pair in config)
{
objInst.FastAddProperty(pair.Key, JsValueFromObject(pair.Value, engine), true, true, true);
}
return objInst;
}
示例6: PutDocument
public override void PutDocument(string documentKey, object data, object meta, Engine engine)
{
if (forbiddenDocuments.Contains(documentKey))
throw new InvalidOperationException(string.Format("Cannot PUT document '{0}' to prevent infinite indexing loop. Avoid modifying documents that could be indirectly referenced by index.", documentKey));
base.PutDocument(documentKey, data, meta, engine);
}
示例7: PlexBinding
public PlexBinding(string username, string password)
{
_username = username;
_password = password;
this.PlayBack = new PlaybackApiBinding(Plexito.JavaScriptLogic.Scripts.PlaybackApi);
_scripts = new Engine(cfg => cfg.AllowClr(typeof(XMLHttpRequest).Assembly)).Execute(Plexito.JavaScriptLogic.Scripts.PlexApi);
}
示例8: CheckinScript
public void CheckinScript(ScriptedPatchRequest request, Engine context)
{
CachedResult value;
if (cacheDic.TryGetValue(request, out value))
{
if (value.Queue.Count > 20)
return;
value.Queue.Enqueue(context);
return;
}
cacheDic.AddOrUpdate(request, patchRequest =>
{
var queue = new ConcurrentQueue<Engine>();
queue.Enqueue(context);
return new CachedResult
{
Queue = queue,
Timestamp = SystemTime.UtcNow,
Usage = 1
};
}, (patchRequest, result) =>
{
result.Queue.Enqueue(context);
return result;
});
}
示例9: 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);
}
示例10: JavaScriptRunner
public JavaScriptRunner(IFeedback<LogEntry> log, ICommandProcessor commandProcessor, IEntityContextConnection entityContextConnection)
{
if (log == null)
throw new ArgumentNullException(nameof(log));
if (commandProcessor == null)
throw new ArgumentNullException(nameof(commandProcessor));
if (entityContextConnection == null)
throw new ArgumentNullException(nameof(entityContextConnection));
Log = log;
CommandProcessor = commandProcessor;
EntityContextConnection = entityContextConnection;
log.Source = "JavaScript Runner";
JintEngine = new Engine(cfg =>
{
cfg.AllowClr();
cfg.AllowDebuggerStatement(JavascriptDebugEnabled);
});
//JintEngine.Step += async (s, info) =>
//{
// await Log.ReportInfoFormatAsync(CancellationToken.None, "{1} {2}",
// info.CurrentStatement.Source.Start.Line,
// info.CurrentStatement.Source.Code.Replace(Environment.NewLine, ""));
//};
}
示例11: JSEngine
public JSEngine(Engine engine)
{
if (engine == null)
throw new ArgumentNullException(nameof(engine));
_engine = engine;
}
示例12: Run
private static void Run(string[] args)
{
var engine = new Engine(cfg => cfg.AllowClr())
.SetValue("print", new Action<object>(Print))
.SetValue("ac", _acDomain);
var filename = args.Length > 0 ? args[0] : "";
if (!String.IsNullOrEmpty(filename))
{
if (!File.Exists(filename))
{
Console.WriteLine(@"Could not find file: {0}", filename);
}
var script = File.ReadAllText(filename);
var result = engine.GetValue(engine.Execute(script).GetCompletionValue());
return;
}
Welcome();
var defaultColor = Console.ForegroundColor;
while (true)
{
Console.ForegroundColor = defaultColor;
Console.Write(@"anycmd> ");
var input = Console.ReadLine();
if (input == "exit")
{
return;
}
if (input == "clear")
{
Console.Clear();
Welcome();
continue;
}
try
{
var result = engine.GetValue(engine.Execute(string.Format("print({0})", input)).GetCompletionValue());
if (result.Type != Types.None && result.Type != Types.Null && result.Type != Types.Undefined)
{
var str = TypeConverter.ToString(engine.Json.Stringify(engine.Json, Arguments.From(result, Undefined.Instance, " ")));
Console.WriteLine(@"=> {0}", str);
}
}
catch (JavaScriptException je)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(je.ToString());
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(e.Message);
}
}
}
示例13: JavascriptContext
public JavascriptContext(string script, string errorMessageContext)
{
_engine = new Engine();
_errorMessageContext = errorMessageContext;
_initialJavascript = script;
Initialize(_initialJavascript);
}
示例14: Echo
private static int Echo(Engine scriptScope, object echoStr)
{
var response = (ClientHttpResponse) scriptScope.GetValue("response").ToObject();
if (!response.HasFinishedSendingHeaders)
response.SendDefaultHeaders();
response.OutputStream.WriteLine(echoStr.ToString());
return 0;
}
示例15: 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;
}