private void highlightDifferencesBetweenPreviewPanes()
        {
            string sOld = previewOldValue.Text;
            string sNew = previewNewValue.Text;

            var highlighter = new ScintillaLineHighlightingHelper();

            highlighter.ClearAll(previewNewValue);
            highlighter.ClearAll(previewOldValue);

            Diff diff = new Diff();

            foreach (Diff.Item item in diff.DiffText(sOld, sNew))
            {
                for (int i = item.StartA; i < item.StartA + item.deletedA; i++)
                {
                    highlighter.HighlightLine(previewOldValue, i, Color.Pink);
                }

                //if it is single line change
                for (int i = item.StartB; i < item.StartB + item.insertedB; i++)
                {
                    highlighter.HighlightLine(previewNewValue, i, Color.LawnGreen);
                }
            }
        }
        public void CreateScintillaComponents(string textBefore, string textAfter, string language = "mssql")
        {
            QueryEditorBefore          = new ScintillaTextEditorFactory().Create();
            QueryEditorBefore.Text     = textBefore;
            QueryEditorBefore.ReadOnly = true;

            splitContainer1.Panel1.Controls.Add(QueryEditorBefore);

            QueryEditorAfter          = new ScintillaTextEditorFactory().Create();
            QueryEditorAfter.Text     = textAfter;
            QueryEditorAfter.ReadOnly = true;

            splitContainer1.Panel2.Controls.Add(QueryEditorAfter);

            //compute difference
            if (textBefore == null)
            {
                textBefore = "";
            }
            if (textAfter == null)
            {
                textAfter = "";
            }

            Diff diff = new Diff();

            var highlighter = new ScintillaLineHighlightingHelper();

            highlighter.ClearAll(QueryEditorAfter);
            highlighter.ClearAll(QueryEditorBefore);

            foreach (Diff.Item item in diff.DiffText(textBefore, textAfter))
            {
                for (int i = item.StartA; i < item.StartA + item.deletedA; i++)
                {
                    highlighter.HighlightLine(QueryEditorBefore, i, Color.Pink);
                }

                for (int i = item.StartB; i < item.StartB + item.insertedB; i++)
                {
                    highlighter.HighlightLine(QueryEditorAfter, i, Color.LawnGreen);
                }
            }
        }
Beispiel #3
0
        public SQLBeforeAndAfterViewer(string sqlBefore, string sqlAfter, string headerTextForBefore, string headerTextForAfter, string caption, MessageBoxButtons buttons, string language = "mssql")
        {
            InitializeComponent();

            bool designMode = (LicenseManager.UsageMode == LicenseUsageMode.Designtime);

            if (designMode) //dont add the QueryEditor if we are in design time (visual studio) because it breaks
            {
                return;
            }

            QueryEditorBefore          = new ScintillaTextEditorFactory().Create();
            QueryEditorBefore.Text     = sqlBefore;
            QueryEditorBefore.ReadOnly = true;

            splitContainer1.Panel1.Controls.Add(QueryEditorBefore);


            QueryEditorAfter          = new ScintillaTextEditorFactory().Create();
            QueryEditorAfter.Text     = sqlAfter;
            QueryEditorAfter.ReadOnly = true;

            splitContainer1.Panel2.Controls.Add(QueryEditorAfter);


            //compute difference
            var highlighter = new ScintillaLineHighlightingHelper();

            highlighter.ClearAll(QueryEditorAfter);
            highlighter.ClearAll(QueryEditorBefore);

            if (sqlBefore == null)
            {
                sqlBefore = "";
            }
            if (sqlAfter == null)
            {
                sqlAfter = "";
            }

            Diff diff = new Diff();

            foreach (Diff.Item item in diff.DiffText(sqlBefore, sqlAfter))
            {
                for (int i = item.StartA; i < item.StartA + item.deletedA; i++)
                {
                    highlighter.HighlightLine(QueryEditorBefore, i, Color.Pink);
                }

                for (int i = item.StartB; i < item.StartB + item.insertedB; i++)
                {
                    highlighter.HighlightLine(QueryEditorAfter, i, Color.LawnGreen);
                }
            }

            switch (buttons)
            {
            case MessageBoxButtons.OK:
                btnYes.Visible = true;
                btnYes.Text    = "Ok";
                btnNo.Visible  = false;
                break;

            case MessageBoxButtons.YesNo:
                btnYes.Visible = true;
                btnNo.Visible  = true;
                break;

            default:
                throw new NotSupportedException("buttons");
            }

            lblBefore.Text = headerTextForBefore;
            lblAfter.Text  = headerTextForAfter;

            this.Text = caption;
        }
        /// <summary>
        /// Updates the Sql code for the current state of the <see cref="Options"/>
        /// </summary>
        public void RegenerateSQL()
        {
            ProblemObjects = new Dictionary <ISqlParameter, Exception>();

            var parameterManager = Options.ParameterManager;

            Sections.Clear();

            try
            {
                IsBroken             = false;
                QueryEditor.ReadOnly = false;
                string sql             = "";
                var    finalParameters = parameterManager.GetFinalResolvedParametersList().ToArray();

                int currentLine = 0;

                foreach (ISqlParameter parameter in finalParameters)
                {
                    //if it's a user one
                    if (AnyTableSqlParameter.HasProhibitedName(parameter) && !ProblemObjects.ContainsKey(parameter))
                    {
                        ProblemObjects.Add(parameter, new Exception("Parameter name " + parameter.ParameterName + " is a reserved name for the RDMP software"));//advise them
                    }
                    try
                    {
                        parameter.Check(new ThrowImmediatelyCheckNotifier());
                    }
                    catch (SyntaxErrorException errorException)
                    {
                        if (!ProblemObjects.ContainsKey(parameter))
                        {
                            ProblemObjects.Add(parameter, errorException);
                        }
                    }


                    string toAdd = QueryBuilder.GetParameterDeclarationSQL(parameter);

                    int lineCount = GetLineCount(toAdd);

                    Sections.Add(new ParameterEditorScintillaSection(Options.Refactorer, currentLine, currentLine += (lineCount - 1), parameter,

                                                                     !Options.ShouldBeReadOnly(parameter),

                                                                     toAdd));

                    sql += toAdd;
                    currentLine++;
                }

                QueryEditor.Text = sql.TrimEnd();
            }
            catch (Exception ex)
            {
                QueryEditor.Text = ex.ToString();

                IsBroken = true;

                var exception = ex as QueryBuildingException;
                if (exception != null)
                {
                    foreach (ISqlParameter p in exception.ProblemObjects.OfType <ISqlParameter>())
                    {
                        if (!ProblemObjects.ContainsKey(p))//might have already added it up above
                        {
                            ProblemObjects.Add(p, ex);
                        }
                    }

                    ProblemObjectsFound();
                }
            }
            QueryEditor.ReadOnly = true;

            var highlighter = new ScintillaLineHighlightingHelper();

            highlighter.ClearAll(QueryEditor);

            foreach (ParameterEditorScintillaSection section in Sections)
            {
                if (!section.Editable)
                {
                    for (int i = section.LineStart; i <= section.LineEnd; i++)
                    {
                        highlighter.HighlightLine(QueryEditor, i, Color.LightGray);
                    }
                }
            }
        }