Exemplo n.º 1
0
        private void btnDiff_Click(object sender, EventArgs e)
        {
            TextFileDiffList sLF        = null;
            TextFileDiffList dLF        = null;
            string           sourceFile = null;
            string           targetFile = null;

            try
            {
                _edSvc.SyncSessionCopy();
                var set = XmlCompareUtil.PrepareForComparison(_edSvc.CurrentConnection.ResourceService,
                                                              _edSvc.ResourceID,
                                                              _edSvc.EditedResourceID);
                sLF = set.Source;
                dLF = set.Target;
            }
            catch (Exception ex)
            {
                ErrorDialog.Show(ex);
                return;
            }
            finally
            {
                try { File.Delete(sourceFile); }
                catch { }
                try { File.Delete(targetFile); }
                catch { }
            }

            try
            {
                double     time = 0;
                DiffEngine de   = new DiffEngine();
                time = de.ProcessDiff(sLF, dLF, DiffEngineLevel.SlowPerfect);

                var          rep = de.DiffReport();
                TextDiffView dlg = new TextDiffView(sLF, dLF, rep, time);
                dlg.SetLabels(_edSvc.ResourceID, Strings.EditedResource);
                dlg.ShowDialog();
                dlg.Dispose();
            }
            catch (Exception ex)
            {
                string nl  = Environment.NewLine;
                string tmp = $"{ex.Message}{nl}{nl}***STACK***{nl}{ex.StackTrace}";
                MessageBox.Show(tmp, Strings.CompareError);
                return;
            }
        }
        public override void Run()
        {
            var wb = Workbench.Instance;

            if (wb == null)
            {
                return;
            }
            var ed = wb.ActiveEditor;

            if (ed == null)
            {
                return;
            }
            var edSvc = ed.EditorService;

            TextFileDiffList sLF        = null;
            TextFileDiffList dLF        = null;
            string           sourceFile = null;
            string           targetFile = null;

            try
            {
                ed.SyncSessionCopy();
                var set = XmlCompareUtil.PrepareForComparison(edSvc.CurrentConnection.ResourceService,
                                                              edSvc.ResourceID,
                                                              edSvc.EditedResourceID);
                sLF = set.Source;
                dLF = set.Target;
            }
            catch (Exception ex)
            {
                ErrorDialog.Show(ex);
                return;
            }
            finally
            {
                try { File.Delete(sourceFile); }
                catch { }
                try { File.Delete(targetFile); }
                catch { }
            }

            try
            {
                double     time = 0;
                DiffEngine de   = new DiffEngine();
                time = de.ProcessDiff(sLF, dLF, DiffEngineLevel.SlowPerfect);

                var          rep = de.DiffReport();
                TextDiffView dlg = new TextDiffView(sLF, dLF, rep, time);
                dlg.SetLabels(edSvc.ResourceID, Strings.EditedResource);
                dlg.ShowDialog();
                dlg.Dispose();
            }
            catch (Exception ex)
            {
                string nl  = Environment.NewLine;
                string tmp = $"{ex.Message}{nl}{nl}***STACK***{nl}{ex.StackTrace}";
                MessageBox.Show(tmp, Strings.CompareError);
                return;
            }
        }