Ejemplo n.º 1
0
        private void btnCompare_Click(object sender, EventArgs e)
        {
            DiffControl diffControl = new DiffControl();
            diffControl.Dock = DockStyle.Fill;
            panel.Controls.Clear();
            panel.Controls.Add(diffControl);

            bool chkIgnoreCase = false;
            bool chkIgnoreWhitespace = true;
            bool chkSupportChangeEditType = false;

            List<string> code1, code2;

            code1 = GetContent(tbSrcDir.Text);
            for (int i = 0; i < code1.Count; i++) code1[i] = code1[i].Substring(tbSrcDir.Text.Length);
            code2 = GetContent(tbDstDir.Text);
            for (int i = 0; i < code2.Count; i++) code2[i] = code2[i].Substring(tbDstDir.Text.Length);

            try
            {
                TextDiff diff = new TextDiff(HashType.CRC32, chkIgnoreCase, chkIgnoreWhitespace, 0, chkSupportChangeEditType);

                EditScript script = diff.Execute(code1, code2);

                diffControl.SetData(code1, code2, script);//, strA, strB);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        private void btnCompare_Click(object sender, EventArgs e)
        {
            DiffControl diffControl = new DiffControl();
            diffControl.Dock = DockStyle.Fill;

            panel.Controls.Clear();
            panel.Controls.Add(diffControl);

            bool chkIgnoreCase = false;
            bool chkIgnoreWhitespace = true;
            bool chkSupportChangeEditType = true;

            IList<string> code1, code2;

            code1 = GetDbDDL((cbSrcDb.SelectedItem as ConnectionSettings).Database);
            code2 = GetDbDDL((cbDstDb.SelectedItem as ConnectionSettings).Database);

            try
            {
                TextDiff diff = new TextDiff(HashType.CRC32, chkIgnoreCase, chkIgnoreWhitespace, 0, chkSupportChangeEditType);

                EditScript script = diff.Execute(code1, code2);

                diffControl.SetData(code1, code2, script);//, strA, strB);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
        public static void ShowDiff(this DiffControl ctrl, string a, string b)
        {
            TextDiff      diff   = new TextDiff(HashType.HashCode, true, true, 0, false);
            List <string> la     = new List <string>(a.Split('\n'));
            List <string> lb     = new List <string>(b.Split('\n'));
            EditScript    script = diff.Execute(la, lb);

            ctrl.SetData(la, lb, script);
        }
Ejemplo n.º 4
0
        public static void CompareCode(string filePath, string modifiedContent)
        {
            Form f = new Form();
            f.WindowState = FormWindowState.Maximized;
            f.Text = "[Original] vs. [Modified]";
            //ComponentResourceManager resources = new ComponentResourceManager(this.GetType());
            //f.Icon = (Icon)(resources.GetObject("$this.Icon"));

            DiffControl diffControl = new DiffControl();
            diffControl.Dock = DockStyle.Fill;
            f.Controls.Add(diffControl);

            bool chkIgnoreCase = false;
            bool chkIgnoreWhitespace = true;
            bool chkSupportChangeEditType = false;
            bool chkXML = false;

            string strA = filePath;

            try
            {
                TextDiff diff = new TextDiff(HashType.CRC32, chkIgnoreCase, chkIgnoreWhitespace, 0, chkSupportChangeEditType);

                IList<string> code1, code2;
                if (chkXML)
                {
                    code1 = Functions.GetXMLTextLines(strA, WhitespaceHandling.All);
                    code2 = modifiedContent.Replace("\r", "").Split('\n');
                }
                else
                {
                    code1 = Functions.GetFileTextLines(strA);
                    code2 = modifiedContent.Replace("\r", "").Split('\n');
                }

                EditScript script = diff.Execute(code1, code2);

                diffControl.SetData(code1, code2, script);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            f.Show();
        }
Ejemplo n.º 5
0
        private void btnCompare_Click(object sender, EventArgs e)
        {
            Encoding enc = null;
            IList<string> code1 = txtUrl1.Text.DownloadPage(ref enc).Replace("\r", "").Split('\n');
            IList<string> code2 = txtUrl2.Text.DownloadPage(ref enc).Replace("\r", "").Split('\n');

            TextDiff diff = new TextDiff(HashType.CRC32, true, true);
            EditScript script = diff.Execute(code1, code2);

            List<MyEdit> diffList = new List<MyEdit>();
            for (int editIndex = 0; editIndex < script.Count; editIndex += 2)
            {
                Edit edit = script[editIndex];
                string strA = "";
                for (int i = edit.StartA; i < edit.StartA + edit.Length; i++)
                    strA += code1[i] + Environment.NewLine;
                string strB = "";
                for (int i = edit.StartB; i < edit.StartB + edit.Length; i++)
                    strB += code2[i] + Environment.NewLine;
                diffList.Add(new MyEdit
                {
                    Left = strA,
                    Right = strB,
                    Type = edit.Type
                });
            }

            List<MyEdit> mySubList = getLongestNItems(diffList, 5);

            DiffControl diffControl = new DiffControl();
            diffControl.Dock = DockStyle.Fill;
            panel.Controls.Clear();
            panel.Controls.Add(diffControl);

            diffControl.SetData(code1, code2, script);//, strA, strB);
        }
Ejemplo n.º 6
0
        private void btnDiff_Click(object sender, EventArgs e)
        {
            GeneratedCode gc = (GeneratedCode)tabControl1.SelectedTab.Tag;

            Form f = new Form();
            f.WindowState = FormWindowState.Maximized;
            f.Text = "[Existing File] vs. [Generated Code]";
            ComponentResourceManager resources = new ComponentResourceManager(this.GetType());
            f.Icon = (Icon)(resources.GetObject("$this.Icon"));

            DiffControl diffControl = new DiffControl();
            diffControl.Dock = DockStyle.Fill;
            f.Controls.Add(diffControl);

            bool chkIgnoreCase = false;
            bool chkIgnoreWhitespace = true;
            bool chkSupportChangeEditType = false;
            bool chkXML = false;

            string strA = gc.Path;

            try
            {
                //edtTextOne.Text = strA;
                //edtTextTwo.Text = strB;

                TextDiff diff = new TextDiff(HashType.CRC32, chkIgnoreCase, chkIgnoreWhitespace, 0, chkSupportChangeEditType);

                IList<string> code1, code2;
                if (chkXML)
                {
                    code1 = Functions.GetXMLTextLines(strA, WhitespaceHandling.All);
                    code2 = gc.Code.Replace("\r","").Split('\n');//Functions.GetXMLTextLines(strB, eWS);
                }
                else
                {
                    code1 = Functions.GetFileTextLines(strA);
                    code2 = gc.Code.Replace("\r","").Split('\n');//Functions.GetFileTextLines(strB);
                }

                EditScript script = diff.Execute(code1, code2);

                diffControl.SetData(code1, code2, script);//, strA, strB);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            f.Show();
        }