Пример #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);
            }
        }
Пример #2
0
        internal static string SetScriptedSend(ScriptEngine Engine, string Code)
        {
            try
            {
                ScriptRuntime Runtime      = Engine.Runtime;
                Assembly      MainAssembly = Assembly.GetExecutingAssembly();
                string        RootDir      = Directory.GetParent(MainAssembly.Location).FullName;
                Runtime.LoadAssembly(MainAssembly);
                Runtime.LoadAssembly(typeof(String).Assembly);
                Runtime.LoadAssembly(typeof(Uri).Assembly);

                if (Engine.Setup.DisplayName.Contains("IronPython"))
                {
                    string[] Results = PluginEditor.CheckPythonIndentation(Code);
                    if (Results[1].Length > 0)
                    {
                        throw new Exception(Results[1]);
                    }
                }

                ScriptSource Source = Engine.CreateScriptSourceFromString(Code);
                Source.ExecuteProgram();
                return("");
            }
            catch (Exception Exp)
            {
                return(Exp.Message);
            }
        }
Пример #3
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.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];
                    CompiledPlugin = PluginSource.Compile(CompileErrors);
                    ErrorMessage   = CompileErrors.GetErrors();
                    if (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 = "";
            }
        }
Пример #4
0
        internal static Module LoadModule(Module M)
        {
            try
            {
                string FullName = string.Format("{0}\\modules\\{1}\\{2}", Config.RootDir, M.Name, M.FileName);
                if (M.FileName.EndsWith(".dll"))
                {
                    Assembly MA        = System.Reflection.Assembly.LoadFile(FullName);
                    Module   NewModule = (Module)Activator.CreateInstance(MA.GetTypes()[0]);
                    Module.Add(NewModule.GetInstance());
                }
                else
                {
                    Engine = PluginEngine.GetScriptEngine();

                    if (M.FileName.EndsWith(".py"))
                    {
                        Engine.Runtime.TryGetEngine("py", out Engine);
                    }
                    else
                    {
                        Engine.Runtime.TryGetEngine("rb", out Engine);
                    }
                    List <string> ModulePaths = new List <string>();
                    foreach (Module ModuleFromXml in ModuleListFromXml)
                    {
                        ModulePaths.Add(string.Format("{0}\\modules\\{1}\\", Config.RootDir, ModuleFromXml.Name));
                    }
                    Engine.SetSearchPaths(ModulePaths);
                    if (M.FileName.Length == 0)
                    {
                        throw new Exception("Module is missing script files");
                    }
                    ScriptSource        ModuleSource  = Engine.CreateScriptSourceFromFile(FullName);
                    ScriptErrorReporter CompileErrors = new ScriptErrorReporter();
                    string       ErrorMessage         = "";
                    CompiledCode CompiledModule       = ModuleSource.Compile(CompileErrors);
                    ErrorMessage = CompileErrors.GetErrors();
                    if (M.FileName.EndsWith(".py"))
                    {
                        string IndentError = PluginEditor.CheckPythonIndentation(ModuleSource.GetCode())[1];
                        if (IndentError.Length > 0)
                        {
                            ErrorMessage = string.Format("{0}\r\n{1}", IndentError, ErrorMessage);
                        }
                    }
                    if (ErrorMessage.Length == 0)
                    {
                        ModuleSource.ExecuteProgram();
                    }
                    else
                    {
                        throw new Exception(string.Format("Syntax error in module file:{0}\r\n{1}", M.FileName, ErrorMessage));
                    }
                }
            }
            catch (Exception Exp)
            {
                ModuleStartPromptForm PF = GetPromptWindow(M);
                if (PF != null)
                {
                    PF.ShowError("Error Loading Module.");
                }
                IronException.Report(string.Format("Error Loading Module - {0}", M.Name), Exp);
                return(null);
            }
            IronUI.BuildPluginTree();
            ModuleStartPromptForm UsedPF = RemovePromptWindowFromList(M);

            if (UsedPF != null)
            {
                try
                {
                    if (!UsedPF.IsClosed)
                    {
                        UsedPF.CloseForm();
                    }
                }
                catch { }
            }
            return(Get(M.Name));
        }