/// <summary>
        ///
        /// </summary>
        private static void LoadScripts()
        {
            // 古いものをすべて削除
            OnUnload(EventArgs.Empty);
            Unload = null;
            Load   = null;

#pragma warning disable 0618
            DynamicHelpers.TopNamespace.LoadAssembly(Assembly.GetExecutingAssembly());
            DynamicHelpers.TopNamespace.LoadAssembly(Assembly.LoadWithPartialName("System.Windows.Forms"));
#pragma warning restore 0618

            IScriptEnvironment scriptEnv = ScriptEnvironment.GetEnvironment();
            _module = scriptEnv.CreateModule("ScriptModule");

            Boolean hasScripts = false;
            if (Directory.Exists("Scripts"))
            {
                foreach (String path in Directory.GetFiles("Scripts", "*.py"))
                {
                    Debug.WriteLine("Load Script: " + path);
                    try
                    {
                        IScriptEngine engine = scriptEnv.GetLanguageProviderByFileExtension(Path.GetExtension(path)).GetEngine();
                        engine.ExecuteFileContent(path, _module);
                        hasScripts = true;
                    }
                    catch (SyntaxErrorException se)
                    {
                        MessageBox.Show(String.Format(Resources.Strings.ScriptSyntaxException, path, se.Line, se.Column, se.Message), ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(String.Format(Resources.Strings.ScriptException, path, e.Message), ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }

            // 一つも読み込んでいなかったらデフォルト
            if (!hasScripts)
            {
                Script.GetEngine("py").Execute(Resources.Strings.DefaultPythonScript, _module);
            }

            // 実行
            _module.Execute();

            OnLoad(EventArgs.Empty);

            ShowBalloonTip(Resources.Strings.ScriptsLoaded, ToolTipIcon.Info);
        }
示例#2
0
 protected override void Initialize()
 {
     base.Initialize();
     Options.LanguageProvider = ScriptEnvironment.GetEnvironment().GetLanguageProvider(typeof(IronSchemeLanguageProvider));
 }