コード例 #1
0
		public override void InitPlugin()
		{
			var actions = RegisterScriptCommands();

			scriptHost = new ScriptHost(actions, Logger, ExecuteScriptByName);
			scriptEvents = RegisterScriptEvents(Context.GetAllPlugins(), Logger);
		}
コード例 #2
0
		/// <summary>
		/// Запуск скрипта
		/// </summary>
		private static void ExecuteScript(UserScript script, ScriptHost scriptHost, Logger logger, object[] args)
		{
			//Debugger.Launch();
			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);
			}
		}