private void utBtnCompile_Click(object sender, EventArgs e) { lstCompilerResults.Items.Clear(); lstCompilerResults.Items.Add("Initializing Compiler Services.."); var compilerSvc = new CompilerServices(); lstCompilerResults.Items.Add("Compiling.."); var result = compilerSvc.CompileInput(rtbCode.Text); if (result.Errors.HasErrors) { foreach (var error in result.Errors) { lstCompilerResults.Items.Add(error); } } else { lstCompilerResults.Items.Add("Compiled Successfully!"); if (chkRunAfterCompile.Checked) { Process.Start(result.PathToAssembly); } } }
private void CompileAndExecute(string customCode, object sender) { var engine = (IAutomationEngineInstance)sender; //compile custom code var compilerSvc = new CompilerServices(); var result = compilerSvc.CompileInput(customCode); //check for errors if (result.Errors.HasErrors) { //throw exception var errors = string.Join(", ", result.Errors); throw new Exception("Errors Occured: " + errors); } else { var arguments = v_Args.ConvertUserVariableToString(engine); //run code, OpenBots will wait for the app to exit before resuming using (Diagnostics.Process scriptProc = new Diagnostics.Process()) { scriptProc.StartInfo.FileName = result.PathToAssembly; scriptProc.StartInfo.Arguments = arguments; if (v_OutputUserVariableName != "") { //redirect output scriptProc.StartInfo.RedirectStandardOutput = true; scriptProc.StartInfo.UseShellExecute = false; } scriptProc.Start(); scriptProc.WaitForExit(); if (v_OutputUserVariableName != "") { var output = scriptProc.StandardOutput.ReadToEnd(); output.StoreInUserVariable(engine, v_OutputUserVariableName, nameof(v_OutputUserVariableName), this); } } } }