コード例 #1
0
        private static XmlElement KeepOrThrow(QueryParser parser, int errorCode, string message, int start, int end)
        {
            //
            // Error object.
            //
            ParseError error = new ParseError(errorCode, message, start, end);

            //
            // Check run mode.
            //
            if (parser._errors != null)
            {
                //
                // Create error message and add it to the errors collection of the query object.
                //
                int id = parser._errors.Add(error);

                //
                // Generate an error reference tag that will be inserted in the generated CAML on the faulting position.
                //
                return(parser._factory.ParseError(id));
            }
            else
            {
                //
                // Runtime mode: throw an exception.
                //
                NotSupportedException ex = new NotSupportedException(error.ToString());
                ex.HelpLink = error.HelpLink;
                throw ex;
            }
        }
コード例 #2
0
        /// <summary>
        /// Helper method to clear selections in the LINQ and CAML textboxes.
        /// </summary>
        private void ClearSelections()
        {
            //
            // Select all and undo marking.
            //
            txtLinq.Select(0, txtLinq.Text.Length);
            txtLinq.SelectionFont = new Font(txtLinq.Font, FontStyle.Regular);
            txtCaml.Select(0, txtCaml.Text.Length);
            txtCaml.SelectionFont = new Font(txtCaml.Font, FontStyle.Regular);

            //
            // Unselect for pretty display.
            //
            txtLinq.Select(0, 0);
            txtCaml.Select(0, 0);

            //
            // Hide tooltip.
            //
            linqTip.RemoveAll();
            camlTip.RemoveAll();

            //
            // Set default cursor.
            //
            txtLinq.Cursor = Cursors.Default;
            txtCaml.Cursor = Cursors.Default;

            //
            // Set to no current error.
            //
            currentError = null;
        }
コード例 #3
0
        /// <summary>
        /// Helper method to mark an error in the UI.
        /// </summary>
        /// <param name="id">ID of the error to mark. Used for marking in the CAML textbox.</param>
        /// <param name="error">Error object of the error to mark. Used for marking in the LINQ expression textbox.</param>
        /// <param name="selected">Indicates whether the error is currently selected or not.</param>
        private void MarkError(int id, ParseError error, bool selected)
        {
            //
            // Select the expression part indicated by the error and mark it.
            //
            txtLinq.Select(error.StartIndex, error.EndIndex - error.StartIndex + 1);
            txtLinq.SelectionColor = Color.Red;
            if (selected)
            {
                txtLinq.SelectionFont = new Font(txtLinq.SelectionFont, FontStyle.Underline);
            }

            //
            // Locate the ParseError placeholder in the CAML query and mark it.
            //
            string tag   = "<ParseError ID=\"" + id + "\" />";
            int    iCaml = txtCaml.Text.IndexOf(tag, StringComparison.Ordinal);

            if (iCaml >= 0)
            {
                txtCaml.Select(iCaml, tag.Length);
                txtCaml.SelectionColor = Color.Red;
                if (selected)
                {
                    txtCaml.SelectionFont = new Font(txtCaml.SelectionFont, FontStyle.Underline);
                }
                else
                {
                    _camlPositions.Add(id, new Position()
                    {
                        Start = iCaml, End = iCaml + tag.Length - 1
                    });
                }
            }
        }
コード例 #4
0
        private void txtCaml_MouseMove(object sender, MouseEventArgs e)
        {
            //
            // Get the position inside the textbox based on the mouse cursor position.
            //
            int i = txtCaml.GetCharIndexFromPosition(e.Location);

            //
            // Find the error (if any) that corresponds to the current position.
            // We expect the number of errors to be low, so we just iterate over the collection.
            //
            foreach (var pos in _camlPositions)
            {
                ParseError error = _errors[pos.Key];

                //
                // Matching position?
                //
                if (pos.Value.Start <= i && i <= pos.Value.End)
                {
                    //
                    // Compare to selected error (if any).
                    //
                    if (currentError == null || currentError != error)
                    {
                        //
                        // Clear previous error display.
                        //
                        ClearSelections();

                        //
                        // Mark error.
                        //
                        MarkError(pos.Key, error, true);

                        //
                        // Unselect for pretty display.
                        //
                        txtLinq.Select(0, 0);
                        txtCaml.Select(0, 0);

                        //
                        // Set cursor on CAML textbox to indicate the possibility to click it (act as a link).
                        //
                        txtCaml.Cursor = Cursors.Hand;

                        //
                        // Set the current error.
                        //
                        currentError = error;
                    }

                    //
                    // Set the tooltip.
                    //
                    camlTip.SetToolTip(txtCaml, error.ToString());

                    //
                    // Found and done.
                    //
                    return;
                }
            }

            //
            // No error found. Clean the error display if a previous selected error is still displayed.
            //
            if (currentError != null)
            {
                ClearSelections();
            }
        }