public void ReloadScripts(ScriptExecutionCallback scriptExecutionCallback) { Shutdown(); ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup(); scriptRuntimeSetup.LanguageSetups.Add(new LanguageSetup("IronPython.Runtime.PythonContext, IronPython", "IronPython 2.6", new[] { "IronPython", "Python", "py" }, new[] { ".py" })); scriptRuntimeSetup.LanguageSetups.Add(new LanguageSetup("IronRuby.Runtime.RubyContext, IronRuby", "IronRuby 1.0", new[] { "IronRuby", "Ruby", "rb" }, new[] { ".rb" })); scriptRuntimeSetup.LanguageSetups[0].Options.Add("SearchPaths", @"Libraries\IronPython".Split(';')); scriptRuntimeSetup.LanguageSetups[1].Options.Add("SearchPaths", @"Libraries\IronRuby\IronRuby;Libraries\IronRuby\ruby;Libraries\IronRuby\ruby\site_ruby;Libraries\IronRuby\ruby\site_ruby\1.8;Libraries\IronRuby\ruby\1.8".Split(';')); scriptRuntimeSetup.LanguageSetups[1].Options.Add("LibraryPaths", @"Libraries\IronRuby\IronRuby;Libraries\IronRuby\ruby;Libraries\IronRuby\ruby\site_ruby;Libraries\IronRuby\ruby\site_ruby\1.8;Libraries\IronRuby\ruby\1.8".Split(';')); scriptRuntimeSetup.LanguageSetups[1].Options["KCode"] = RubyEncoding.KCodeUTF8; scriptRuntimeSetup.LanguageSetups[1].ExceptionDetail = true; _scriptRuntime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, scriptRuntimeSetup); foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) { _scriptRuntime.LoadAssembly(asm); } _scriptScopes = new Dictionary <string, ScriptScope>(); PrepareScriptScopeByPath("*Eval*"); _scriptRuntime.Globals.SetVariable("Session", _sessionProxy.GetTransparentProxy()); _scriptRuntime.Globals.SetVariable("Server", _serverProxy.GetTransparentProxy()); _scriptRuntime.Globals.SetVariable("CurrentSession", _sessionProxy.GetTransparentProxy()); _scriptRuntime.Globals.SetVariable("CurrentServer", _serverProxy.GetTransparentProxy()); // 共通のスクリプトを読む LoadScriptsFromDirectory(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "GlobalScripts"), scriptExecutionCallback); // ユーザごとのスクリプトを読む LoadScriptsFromDirectory(Path.Combine(CurrentSession.UserConfigDirectory, "Scripts"), scriptExecutionCallback); }
/// <summary> /// 指定したディレクトリ以下のスクリプトを読み込む /// </summary> /// <param name="rootDir"></param> /// <param name="scriptExecutionCallback"></param> private void LoadScriptsFromDirectory(String rootDir, ScriptExecutionCallback scriptExecutionCallback) { if (Directory.Exists(rootDir)) { foreach (var path in Directory.GetFiles(rootDir, "*.*", SearchOption.AllDirectories)) { ScriptEngine engine; if (_scriptRuntime.TryGetEngineByFileExtension(Path.GetExtension(path), out engine)) { try { String expression = File.ReadAllText(path, Encoding.UTF8); ScriptScope scriptScope = PrepareScriptScopeByPath(path); engine.Execute(expression, scriptScope); scriptExecutionCallback(path, null); } catch (Exception ex) { scriptExecutionCallback(path, ex); } } } } }
public void ReloadScripts(ScriptExecutionCallback scriptExecutionCallback) { Shutdown(); ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup(); scriptRuntimeSetup.LanguageSetups.Add(new LanguageSetup("IronPython.Runtime.PythonContext, IronPython", "IronPython 2.6", new[] { "IronPython", "Python", "py" }, new[] { ".py" })); scriptRuntimeSetup.LanguageSetups.Add(new LanguageSetup("IronRuby.Runtime.RubyContext, IronRuby", "IronRuby 1.0", new[] { "IronRuby", "Ruby", "rb" }, new[] { ".rb" })); scriptRuntimeSetup.LanguageSetups[0].Options.Add("SearchPaths", @"Libraries\IronPython".Split(';')); scriptRuntimeSetup.LanguageSetups[1].Options.Add("SearchPaths", @"Libraries\IronRuby\IronRuby;Libraries\IronRuby\ruby;Libraries\IronRuby\ruby\site_ruby;Libraries\IronRuby\ruby\site_ruby\1.8;Libraries\IronRuby\ruby\1.8".Split(';')); scriptRuntimeSetup.LanguageSetups[1].Options.Add("LibraryPaths", @"Libraries\IronRuby\IronRuby;Libraries\IronRuby\ruby;Libraries\IronRuby\ruby\site_ruby;Libraries\IronRuby\ruby\site_ruby\1.8;Libraries\IronRuby\ruby\1.8".Split(';')); scriptRuntimeSetup.LanguageSetups[1].Options["KCode"] = RubyEncoding.KCodeUTF8; scriptRuntimeSetup.LanguageSetups[1].ExceptionDetail = true; _scriptRuntime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, scriptRuntimeSetup); foreach (var asm in AppDomain.CurrentDomain.GetAssemblies()) _scriptRuntime.LoadAssembly(asm); _scriptScopes = new Dictionary<string, ScriptScope>(); PrepareScriptScopeByPath("*Eval*"); _scriptRuntime.Globals.SetVariable("Session", _sessionProxy.GetTransparentProxy()); _scriptRuntime.Globals.SetVariable("Server", _serverProxy.GetTransparentProxy()); _scriptRuntime.Globals.SetVariable("CurrentSession", _sessionProxy.GetTransparentProxy()); _scriptRuntime.Globals.SetVariable("CurrentServer", _serverProxy.GetTransparentProxy()); // 共通のスクリプトを読む LoadScriptsFromDirectory(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "GlobalScripts"), scriptExecutionCallback); // ユーザごとのスクリプトを読む LoadScriptsFromDirectory(Path.Combine(CurrentSession.UserConfigDirectory, "Scripts"), scriptExecutionCallback); }