Exemple #1
0
        internal static InteractiveShellResult ExecuteMultiLineShellInput(string Commands)
        {
            List <string>          CommandsList = new List <string>();
            InteractiveShellResult ISR          = new InteractiveShellResult();

            try
            {
                string ProcessedCode = Commands;
                if (IronScripting.Engine.Setup.DisplayName.Contains("IronPython"))
                {
                    string[] Results = PluginEditor.CheckPythonIndentation(ProcessedCode);
                    if (Results[1].Length > 0)
                    {
                        ProcessedCode = PluginEditor.FixPythonIndentation(ProcessedCode);
                        Results       = PluginEditor.CheckPythonIndentation(ProcessedCode);
                        if (Results[1].Length > 0)
                        {
                            throw new Exception(Results[1]);
                        }
                    }
                }
                ScriptSource Source = IronScripting.Engine.CreateScriptSourceFromString(ProcessedCode, SourceCodeKind.AutoDetect);
                Source.Execute(IronScripting.Scope);
                Reset();
                return(ISR);
            }
            catch (Exception exp)
            {
                ISR.ResultString = "Exception : " + exp.Message + Environment.NewLine;
                Reset();
                return(ISR);
            }
        }
Exemple #2
0
        static void LoadPlugin(string PluginFile, ScriptEngine Engine)
        {
            try
            {
                ScriptSource        PluginSource;
                CompiledCode        CompiledPlugin;
                ScriptErrorReporter CompileErrors = new ScriptErrorReporter();
                string ErrorMessage = "";

                fileName = PluginFile.Substring(PluginFile.LastIndexOf('\\') + 1);
                if (StartUp)
                {
                    IronUI.LF.ShowLoadMessage("Loading Plugin - " + fileName);
                }
                if (PluginFile.EndsWith(".py", StringComparison.CurrentCultureIgnoreCase))
                {
                    Engine.Runtime.TryGetEngine("py", out Engine);
                    PluginSource = Engine.CreateScriptSourceFromFile(PluginFile);
                    string IndentError = PluginEditor.CheckPythonIndentation(PluginSource.GetCode())[1];
                    if (IndentError.Length > 0)
                    {
                        string UpdatedCode = PluginEditor.FixPythonIndentation(PluginSource.GetCode());
                        PluginSource = Engine.CreateScriptSourceFromString(UpdatedCode);
                        //ErrorMessage = string.Format("{0}\r\n{1}", IndentError, ErrorMessage);
                    }
                    CompiledPlugin = PluginSource.Compile(CompileErrors);
                    ErrorMessage   = CompileErrors.GetErrors();
                    if (ErrorMessage.Length > 0 && IndentError.Length > 0)
                    {
                        ErrorMessage = string.Format("{0}\r\n{1}", IndentError, ErrorMessage);
                    }
                    if (ErrorMessage.Length == 0)
                    {
                        PluginSource.ExecuteProgram();
                    }
                }
                else if (PluginFile.EndsWith(".rb", StringComparison.CurrentCultureIgnoreCase))
                {
                    Engine.Runtime.TryGetEngine("rb", out Engine);
                    PluginSource   = Engine.CreateScriptSourceFromFile(PluginFile);
                    CompiledPlugin = PluginSource.Compile(CompileErrors);
                    ErrorMessage   = CompileErrors.GetErrors();
                    if (ErrorMessage.Length == 0)
                    {
                        PluginSource.ExecuteProgram();
                    }
                }
                if (ErrorMessage.Length > 0)
                {
                    IronException.Report("Syntax error in Plugin - " + PluginFile, ErrorMessage);
                }
            }
            catch (Exception Exp)
            {
                IronException.Report("Error loading plugin - " + PluginFile, Exp.Message, Exp.StackTrace);
            }
            finally
            {
                fileName = "";
            }
        }