Exemplo n.º 1
0
        void ReDiff()
        {
            var src_sheet = books["src"].sheetname;

            DiffSheet(books["src"].GetCurSheet(), books["dst"].GetCurSheet(), sheetsDiff[src_sheet]);

            DstDataGrid.RefreshData();
            SrcDataGrid.RefreshData();
        }
Exemplo n.º 2
0
        public void DoDiff()
        {
            var total = src.files.Union(dst.files).ToList();

            total.Sort();

            results.Clear();
            resultRevisions.Clear();

            var md5Hash = MD5.Create();

            foreach (var file in total)
            {
                var res    = new DiffResult <string>(file, file, DiffStatus.Equal);
                var consrc = src.files.Contains(file);
                var condst = dst.files.Contains(file);
                if (consrc && !condst)
                {
                    res.Obj2   = null;
                    res.Status = DiffStatus.Deleted;
                }
                else if (!consrc && condst)
                {
                    res.Obj1   = null;
                    res.Status = DiffStatus.Inserted;
                }

                if (res.Status == DiffStatus.Equal)
                {
                    // check md5 first
                    //var hash1 = md5Hash.ComputeHash(File.OpenRead(src.root + file));
                    //var hash2 = md5Hash.ComputeHash(File.OpenRead(dst.root + file));
                    if (!DiffUtil.FilesAreEqual(src.root + file, dst.root + file))
                    {
                        res.Status = DiffStatus.Modified;
                    }
                }

                results.Add(res);
            }

            DstDataGrid.refreshData();
            SrcDataGrid.refreshData();
        }
Exemplo n.º 3
0
        private void SrcFileSheetsCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                var selection = (e.AddedItems[0] as ComboBoxItem).Content as SheetNameCombo;
                books["src"].sheet = selection.ID;

                if (books.ContainsKey("dst") && books["src"].sheetname != books["dst"].sheetname)
                {
                    var idx = books["dst"].GetComboIDBySheetName(books["src"].sheetname);
                    if (idx >= 0)
                    {
                        DstFileSheetsCombo.SelectedItem = books["dst"].sheetCombo[idx];
                    }
                }

                SrcDataGrid.RefreshData();
                OnSheetChanged();
            }
        }
Exemplo n.º 4
0
        public void Diff(string file1, string file2, bool resetInitFile = true)
        {
            if (string.IsNullOrEmpty(file1) || string.IsNullOrEmpty(file2))
            {
                return;
            }

            if (resetInitFile)
            {
                SrcFile = file1;
                DstFile = file2;
            }

            string oldsheetName = null;

            if (books.ContainsKey("src"))
            {
                oldsheetName = books["src"].sheetname;
            }

            var src = InitWorkWrap(file1);
            var dst = InitWorkWrap(file2);


            var option = new DiffOption <SheetNameCombo>();

            option.EqualityComparer = new SheetNameComboComparer();
            var result = DiffUtil.Diff(src.sheetNameCombos, dst.sheetNameCombos, option);

            //diffSheetName = result.ToList();//
            diffSheetName = DiffUtil.OptimizeCaseDeletedFirst(result).ToList();
            books["src"]  = src;
            books["dst"]  = dst;
            var srcSheetID = -1;
            var dstSheetID = -1;

            for (int i = 0; i < diffSheetName.Count; ++i)
            {
                var sheetname = diffSheetName[i];
                var name      = sheetname.Obj1 == null ? sheetname.Obj2.Name : sheetname.Obj1.Name;

                // 只有sheet名字一样的可以diff, 先这么处理
                if (sheetname.Status == DiffStatus.Equal)
                {
                    var sheet1 = sheetname.Obj1.ID;
                    var sheet2 = sheetname.Obj2.ID;

                    sheetsDiff[name] = DiffSheet(src.book.GetSheetAt(sheet1), dst.book.GetSheetAt(sheet2));

                    if (sheetsDiff[name] != null)
                    {
                        oldsheetName = sheetname.Obj1.Name;
                        var sheetidx = 0;
                        if (!string.IsNullOrEmpty(oldsheetName))
                        {
                            sheetidx = src.book.GetSheetIndex(oldsheetName);
                        }
                        if (sheetsDiff[name].changed || srcSheetID == -1)
                        {
                            src.sheet  = sheetidx;
                            srcSheetID = sheetidx;
                        }

                        if (!string.IsNullOrEmpty(oldsheetName))
                        {
                            sheetidx = dst.book.GetSheetIndex(oldsheetName);
                        }
                        if (sheetsDiff[name].changed || dstSheetID == -1)
                        {
                            dst.sheet  = sheetidx;
                            dstSheetID = sheetidx;
                        }
                    }
                }
            }

            // refresh ui
            SrcFilePath.Content = file1;
            DstFilePath.Content = file2;

            SrcFileSheetsCombo.Items.Clear();
            foreach (var item in src.sheetCombo)
            {
                int             index  = diffSheetName.FindIndex(a => a.Obj1 != null && a.Obj1.ID == (item.Content as SheetNameCombo).ID);
                SolidColorBrush color  = null;
                DiffStatus      status = diffSheetName[index].Status;
                if (status != DiffStatus.Equal)
                {
                    color = Util.GetColorByDiffStatus(status);
                }
                else
                {
                    var name = diffSheetName[index].Obj1.Name;
                    color = Util.GetColorByDiffStatus(sheetsDiff.ContainsKey(name) && sheetsDiff[name] != null && sheetsDiff[name].changed ? DiffStatus.Modified : DiffStatus.Equal);
                }

                if (color != null)
                {
                    item.Background = color;
                }

                SrcFileSheetsCombo.Items.Add(item);
            }
            var comboidx = src.ItemID2ComboIdx[src.sheet];

            SrcFileSheetsCombo.SelectedItem = src.sheetCombo[comboidx];

            DstFileSheetsCombo.Items.Clear();
            foreach (var item in dst.sheetCombo)
            {
                int             index  = diffSheetName.FindIndex(a => a.Obj2 != null && a.Obj2.ID == (item.Content as SheetNameCombo).ID);
                SolidColorBrush color  = null;
                DiffStatus      status = diffSheetName[index].Status;
                if (status != DiffStatus.Equal)
                {
                    color = Util.GetColorByDiffStatus(status);
                }
                else
                {
                    var name = diffSheetName[index].Obj1.Name;
                    color = Util.GetColorByDiffStatus(sheetsDiff.ContainsKey(name) && sheetsDiff[name] != null && sheetsDiff[name].changed ? DiffStatus.Modified : DiffStatus.Equal);
                }

                if (color != null)
                {
                    item.Background = color;
                }

                DstFileSheetsCombo.Items.Add(item);
            }
            comboidx = dst.ItemID2ComboIdx[dst.sheet];
            DstFileSheetsCombo.SelectedItem = dst.sheetCombo[comboidx];

            DstDataGrid.RefreshData();
            SrcDataGrid.RefreshData();
        }
Exemplo n.º 5
0
        private void ExecuteDiff(bool isStartup = false)
        {
            if (!File.Exists(SrcPathTextBox.Text) || !File.Exists(DstPathTextBox.Text))
            {
                return;
            }

            SrcDataGrid.ScrollIntoView(FastGridCellAddress.Empty);
            DstDataGrid.ScrollIntoView(FastGridCellAddress.Empty);

            SrcDataGrid.FirstVisibleColumnScrollIndex = 0;
            SrcDataGrid.FirstVisibleRowScrollIndex    = 0;
            DstDataGrid.FirstVisibleColumnScrollIndex = 0;
            DstDataGrid.FirstVisibleRowScrollIndex    = 0;

            SrcDataGrid.InitializeComponent();
            DstDataGrid.InitializeComponent();

            SrcDataGrid.SetMaxColumnSize(App.Instance.Setting.CellWidth);
            DstDataGrid.SetMaxColumnSize(App.Instance.Setting.CellWidth);
            SrcDataGrid.SetMinColumnSize(App.Instance.Setting.CellWidth);
            DstDataGrid.SetMinColumnSize(App.Instance.Setting.CellWidth);

            var           srcPath = SrcPathTextBox.Text;
            var           dstPath = DstPathTextBox.Text;
            ExcelWorkbook wb1     = null;
            ExcelWorkbook wb2     = null;

            ProgressWindow.DoWorkWithModal(progress =>
            {
                progress.Report(Properties.Resources.Msg_ReadingFiles);

                var config = CreateReadConfig();
                wb1        = ExcelWorkbook.Create(srcPath, config);
                wb2        = ExcelWorkbook.Create(dstPath, config);
            });

            FileSetting srcSetting = null;
            FileSetting dstSetting = null;

            if (!IgnoreFileSettingCheckbox.IsChecked.Value)
            {
                srcSetting =
                    FindFilseSetting(Path.GetFileName(SrcPathTextBox.Text), SrcSheetCombobox.SelectedIndex, SrcSheetCombobox.SelectedItem.ToString(), isStartup);

                dstSetting =
                    FindFilseSetting(Path.GetFileName(DstPathTextBox.Text), DstSheetCombobox.SelectedIndex, DstSheetCombobox.SelectedItem.ToString(), isStartup);

                diffConfig = CreateDiffConfig(srcSetting, dstSetting, isStartup);
            }
            else
            {
                diffConfig = new ExcelSheetDiffConfig();

                diffConfig.SrcSheetIndex = Math.Max(SrcSheetCombobox.SelectedIndex, 0);
                diffConfig.DstSheetIndex = Math.Max(DstSheetCombobox.SelectedIndex, 0);
            }

            SrcSheetCombobox.SelectedIndex = diffConfig.SrcSheetIndex;
            DstSheetCombobox.SelectedIndex = diffConfig.DstSheetIndex;

            var sheet1 = wb1.Sheets[SrcSheetCombobox.SelectedItem.ToString()];
            var sheet2 = wb2.Sheets[DstSheetCombobox.SelectedItem.ToString()];

            if (sheet1.Rows.Count > 10000 || sheet2.Rows.Count > 10000)
            {
                MessageBox.Show(Properties.Resources.Msg_WarnSize);
            }

            ExcelSheetDiff diff = null;

            ProgressWindow.DoWorkWithModal(progress =>
            {
                progress.Report(Properties.Resources.Msg_ExtractingDiff);
                diff = ExcelSheet.Diff(sheet1, sheet2, diffConfig);
            });

            var modelConfig = new DiffGridModelConfig();
            var srcModel    = new DiffGridModel(DiffType.Source, diff, modelConfig);
            var dstModel    = new DiffGridModel(DiffType.Dest, diff, modelConfig);

            (DataContext as ViewModels.DiffViewModel).UpdateDiffSummary(diff.CreateSummary());

            SrcDataGrid.AlternatingColors = App.Instance.Setting.AlternatingColors;
            DstDataGrid.AlternatingColors = App.Instance.Setting.AlternatingColors;
            SrcDataGrid.CellFontName      = App.Instance.Setting.FontName;
            DstDataGrid.CellFontName      = App.Instance.Setting.FontName;

            SrcDataGrid.Model = srcModel;
            DstDataGrid.Model = dstModel;

            if (ShowOnlyDiffRadioButton.IsChecked.Value)
            {
                srcModel.HideEqualRows();
                srcModel.HideEqualRows();
            }

            if (srcSetting != null)
            {
                srcModel.SetColumnHeader(srcSetting.ColumnHeaderIndex);
                if (string.IsNullOrEmpty(srcSetting.RowHeaderName))
                {
                    srcModel.SetRowHeader(srcSetting.RowHeaderIndex);
                }
                else
                {
                    srcModel.SetRowHeader(srcSetting.RowHeaderName);
                }
                SrcDataGrid.MaxRowHeaderWidth = srcSetting.MaxRowHeaderWidth;
            }

            if (dstSetting != null)
            {
                dstModel.SetColumnHeader(dstSetting.ColumnHeaderIndex);
                if (string.IsNullOrEmpty(dstSetting.RowHeaderName))
                {
                    dstModel.SetRowHeader(dstSetting.RowHeaderIndex);
                }
                else
                {
                    dstModel.SetRowHeader(dstSetting.RowHeaderName);
                }
                DstDataGrid.MaxRowHeaderWidth = dstSetting.MaxRowHeaderWidth;
            }

            DataGridEventDispatcher.DispatchModelUpdateEvent(SrcDataGrid, container);
            DataGridEventDispatcher.DispatchModelUpdateEvent(DstDataGrid, container);

            if (!App.Instance.KeepFileHistory)
            {
                App.Instance.UpdateRecentFiles(SrcPathTextBox.Text, DstPathTextBox.Text);
            }
        }
Exemplo n.º 6
0
        private void DoVersionDiff_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(FilterCommits.Text))
            {
                TextTip.Content = "需要填写单号,多个单号空格隔开";
                return;
            }
            if (src.files.Count <= 0)
            {
                TextTip.Content = "拖目标文件夹进来,或目标文件夹下没有xls";
                return;
            }

            Collection <SvnLogEventArgs> logitems;

            DateTime startDateTime = DateTime.Now.AddDays(-60);
            DateTime endDateTime   = DateTime.Now;
            var      svnRange      = new SvnRevisionRange(new SvnRevision(startDateTime), new SvnRevision(endDateTime));

            List <SvnRevisionCombo> revisions = new List <SvnRevisionCombo>();

            var files = new Dictionary <string, RevisionRange>();

            var filter = FilterCommits.Text.Split(" #".ToArray(), StringSplitOptions.RemoveEmptyEntries);

            var sfilter   = string.Join("|", filter);
            var regfilter = new Regex(sfilter);

            using (SvnClient client = new SvnClient()) {
                client.Authentication.SslServerTrustHandlers += delegate(object _sender, SharpSvn.Security.SvnSslServerTrustEventArgs _e) {
                    _e.AcceptedFailures = _e.Failures;
                    _e.Save             = true; // Save acceptance to authentication store
                };

                if (client.GetUriFromWorkingCopy(src.root) != null)
                {
                    SvnInfoEventArgs info;
                    client.GetInfo(src.root, out info);
                    var uri = info.Uri;

                    var rootPath = info.Path;

                    client.GetLog(uri, new SvnLogArgs(svnRange), out logitems);

                    foreach (var logentry in logitems)
                    {
                        var author   = logentry.Author;
                        var message  = logentry.LogMessage;
                        var date     = logentry.Time;
                        var revision = logentry.Revision;

                        if (regfilter.IsMatch(message))
                        {
                            foreach (var filepath in logentry.ChangedPaths)
                            {
                                var path = filepath.Path;

                                RevisionRange minmax = null;
                                if (!files.TryGetValue(path, out minmax))
                                {
                                    minmax = new RevisionRange()
                                    {
                                        min = revision, max = revision, file = path
                                    };
                                    files[path] = minmax;
                                }
                                if (revision > minmax.max)
                                {
                                    minmax.max = revision;
                                }
                                if (revision < minmax.min)
                                {
                                    minmax.min = revision;
                                }
                            }
                        }
                    }
                }
            }

            results.Clear();
            resultRevisions.Clear();

            foreach (var file in files.Keys)
            {
                var range = files[file];
                var res   = new DiffResult <string>(file + "-" + range.min, file + "-" + range.max, DiffStatus.Modified);

                results.Add(res);
                resultRevisions.Add(range);
            }

            DstDataGrid.refreshData();
            SrcDataGrid.refreshData();
        }