Example #1
0
 public ScriptOutputStream(ScriptOutput gui)
 {
     _outputBuffer = String.Empty;
     _gui          = gui;
 }
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            _application = commandData.Application;
            _commandData = commandData;
            _elements    = elements;


            // 1: ---------------------------------------------------------------------------------------------------------------------------------------------
            // Processing Journal Data and getting the script path to be executed in IronPython engine
            IDictionary <String, String> dataMap = commandData.JournalData;

            try
            {
                _scriptSource        = dataMap["ScriptSource"];
                _syspaths            = dataMap["SearchPaths"];
                _modelName           = dataMap["ModelName"];
                _commandOutputDir    = dataMap["OutputPath"];
                _commandOutputPrefix = dataMap["OutputPrefix"];
                _logFile             = dataMap["LogFile"];
            }
            catch (Exception)
            {
                _syspaths = "";
                var fdlg = new OpenFileDialog();
                fdlg.Filter           = "|*.py";
                fdlg.RestoreDirectory = true;
                fdlg.Multiselect      = false;

                if (fdlg.ShowDialog() == DialogResult.OK)
                {
                    _scriptSource = fdlg.FileName;
                }
                else
                {
                    return(Result.Cancelled);
                }

                _uimode = true;
            }

            // 2: ---------------------------------------------------------------------------------------------------------------------------------------------
            // Stating a new output window
            _scriptOutput = new ScriptOutput();
            _outputStream = new ScriptOutputStream(_scriptOutput);
            // Forces creation of handle before showing the window
            var hndl = _scriptOutput.Handle;

            // 3: ---------------------------------------------------------------------------------------------------------------------------------------------
            // Executing the script

            // Get script executor
            var executor = new ScriptExecutor(commandData);
            // Execute script
            var resultCode = executor.ExecuteScript(this);

            // Return results
            if (resultCode == 0)
            {
                return(Result.Succeeded);
            }
            else
            {
                return(Result.Cancelled);
            }
        }