public object AddScript(dynamic args) { var name = args.name; var body = args.body; using (var session = Context.OpenSession()) { var guid = Guid.NewGuid(); var script = new UserScript { Id = guid, Name = name, Body = body }; session.Save(script); session.Flush(); return guid; } }
private static void ExecuteScript(UserScript script, ScriptHost scriptHost, Logger logger, object[] args) { try { //var engine = new JScriptEngine(WindowsScriptEngineFlags.EnableDebugging); var engine = new JScriptEngine(); engine.AddHostObject("host", scriptHost); string initArgsScript = string.Format("var arguments = {0};", args.ToJson()); engine.Execute(initArgsScript); engine.Execute(script.Body); } catch (Exception ex) { var messge = string.Format("Error in user script {0}", script.Name); logger.ErrorException(messge, ex); } }
/// <summary> /// Запуск скриптов (для плагинов) /// </summary> /// <param name="script"></param> /// <param name="args"></param> public void ExecuteScript(UserScript script, params object[] args) { ExecuteScript(script, scriptHost, Logger, args); }