/// <summary> /// Verifies the syntactic validity of the user script. /// </summary> private bool ValidateScript(bool confirmOK) { try { UserCSScript testInstruction = new UserCSScript(txtCode.Text); CompilerErrorCollection errors; testInstruction.Compile(out errors); txtCode.AnnotationClearAll(); txtCode.AnnotationVisible = ScintillaNET.Annotation.Boxed; txtCode.Styles[1].BackColor = Color.FromArgb(0xFFF0F0); txtCode.Styles[1].ForeColor = Color.FromArgb(0x800000); txtCode.Styles[2].BackColor = Color.FromArgb(0xFFFFF0); txtCode.Styles[2].ForeColor = Color.FromArgb(0x808000); if (errors.HasErrors) { bool hasScrolled = false; foreach (CompilerError error in errors) { int lineNum = error.Line - testInstruction.LineAtCodeStart; if (!hasScrolled) { hasScrolled = true; txtCode.LineScroll(lineNum, 0); } txtCode.Lines[lineNum].AnnotationText = error.ErrorText; txtCode.Lines[lineNum].AnnotationStyle = 1; if (error.IsWarning) { txtCode.Lines[lineNum].AnnotationStyle = 2; } } } else { if (confirmOK) { MessageBox.Show(this, "No errors could be found in the script.", System.Windows.Forms.Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } return(true); } } catch (Exception ex) { MessageBox.Show(this, "The code cannot be compiled: " + ex.Message, System.Windows.Forms.Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }
/// <summary> /// Verifies the syntactic validity of the user script. /// </summary> private bool ValidateScript(bool confirmOK) { try { UserCSScript testInstruction = new UserCSScript(txtCode.Text); CompilerErrorCollection errors; testInstruction.Compile(out errors); txtCode.ClearAllAnnotations(); if (errors.HasErrors) { bool hasScrolled = false; foreach (CompilerError error in errors) { int lineNum = error.Line - testInstruction.LineAtCodeStart; if (!hasScrolled) { hasScrolled = true; txtCode.ScrollToLine(lineNum); } txtCode.SetAnnotation(lineNum, error.ErrorText, error.IsWarning); } } else { if (confirmOK) { MessageBox.Show(this, "No errors could be found in the script.", System.Windows.Forms.Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } return(true); } } catch (Exception ex) { MessageBox.Show(this, "The code cannot be compiled: " + ex.Message, System.Windows.Forms.Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }
/// <summary> /// Verifies the syntactic validity of the user script. /// </summary> private bool ValidateScript(bool confirmOK) { try { UserCSScript testInstruction = new UserCSScript(txtCode.Text); CompilerErrorCollection errors; testInstruction.Compile(out errors); txtCode.ClearAllAnnotations(); if (errors.HasErrors) { bool hasScrolled = false; foreach (CompilerError error in errors) { int lineNum = error.Line - testInstruction.LineAtCodeStart; if (!hasScrolled) { hasScrolled = true; txtCode.ScrollToLine(lineNum); } txtCode.SetAnnotation(lineNum, error.ErrorText, error.IsWarning); } } else { if (confirmOK) { MessageBox.Show(this, "No errors could be found in the script.", System.Windows.Forms.Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } return true; } } catch (Exception ex) { MessageBox.Show(this, "The code cannot be compiled: " + ex.Message, System.Windows.Forms.Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } return false; }