public MainWindow(String[] startArgs) { InitializeComponent(); m_historyGraph.CommitClicked += SelectCommit; m_commitDiffView.SelectionChanged += SelectionChanged; m_fileTree.PreviewMouseWheel += (sender, e) => { var eventArg = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta); eventArg.RoutedEvent = UIElement.MouseWheelEvent; eventArg.Source = sender; this.m_fileTree.RaiseEvent(eventArg); }; m_startArgs = startArgs; if (m_startArgs != null && m_startArgs.Length > 0) { if (LoadRepo(m_startArgs[0])) { m_gridWelcome.Visibility = System.Windows.Visibility.Hidden; m_girdBrowse.Visibility = System.Windows.Visibility.Visible; m_cards.Visibility = System.Windows.Visibility.Visible; } else { MessageBox.Show("无法打开仓库", "错误"); } } else { m_gridWelcome.Visibility = System.Windows.Visibility.Visible; m_girdBrowse.Visibility = System.Windows.Visibility.Hidden; m_cards.Visibility = System.Windows.Visibility.Hidden; } DocOpt.ClearSpace(); m_msgStatText.DataContext = m_statText; }
public void Show(byte[] a, byte[] b, string path) { // start processing difference analysis. Clear(); try { if (path.LastIndexOf(".doc") == path.Length - 4) { new Thread(() => { XpsDocument resDoc = null; Application.Current.Dispatcher.Invoke(new Action(() => { ((MainWindow)Application.Current.MainWindow).SetStatus("正在分析文件差异..."); ((MainWindow)Application.Current.MainWindow).ShowWaitUI(true); })); // this process may take a long time to execute. resDoc = DocOpt.CompareWordDocument(a, DocOpt.OfficeDocuFormat.doc, b, DocOpt.OfficeDocuFormat.doc); Application.Current.Dispatcher.Invoke(new Action(() => { m_docViewer.Document = resDoc.GetFixedDocumentSequence(); ((MainWindow)Application.Current.MainWindow).SetStatusReady(); ((MainWindow)Application.Current.MainWindow).ShowWaitUI(false); })); }).Start(); ShowCardDoc(); } else if (path.LastIndexOf(".docx") == path.Length - 5) { new Thread(() => { XpsDocument resDoc = null; Application.Current.Dispatcher.Invoke(new Action(() => { ((MainWindow)Application.Current.MainWindow).SetStatus("正在分析文件差异..."); ((MainWindow)Application.Current.MainWindow).ShowWaitUI(true); })); // this process may take a long time to execute. resDoc = DocOpt.CompareWordDocument(a, DocOpt.OfficeDocuFormat.docx, b, DocOpt.OfficeDocuFormat.docx); Application.Current.Dispatcher.Invoke(new Action(() => { m_docViewer.Document = resDoc.GetFixedDocumentSequence(); ((MainWindow)Application.Current.MainWindow).SetStatusReady(); ((MainWindow)Application.Current.MainWindow).ShowWaitUI(false); })); }).Start(); ShowCardDoc(); } else if (path.LastIndexOf(".jpg") == path.Length - 4 || path.LastIndexOf(".jpeg") == path.Length - 5) { // TODO: // Show image - jpeg difference here } else { a = (Diff.IsBinary(a) == true ? Encoding.ASCII.GetBytes("Binary content\nFile size: " + a.Length) : a); b = (Diff.IsBinary(b) == true ? Encoding.ASCII.GetBytes("Binary content\nFile size: " + b.Length) : b); Init(new Diff(a, b)); ShowCardText(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
internal void Show(Change change) { if (change == null) { return; } // check repeat operation bool bRepeated = false; if (change.Commits.Length == m_workedCommits.Count && m_workedPath == change.Path) { bRepeated = true; HashSet <string> ciHash = new HashSet <string>(); foreach (var ci in change.Commits) { ciHash.Add(ci.Hash); } foreach (var worked in m_workedCommits) { if (ciHash.Contains(worked) == false) { bRepeated = false; break; } } } if (true == bRepeated) { return; } m_workedPath = change.Path; m_workedCommits.Clear(); foreach (var ci in change.Commits) { m_workedCommits.Add(ci.Hash); } // start processing difference analysis. Clear(); var a = (change.ReferenceObject != null ? (change.ReferenceObject as Blob).RawData : new byte[0]); var b = (change.ComparedObject != null ? (change.ComparedObject as Blob).RawData : new byte[0]); try { if (change.Path.LastIndexOf(".doc") == change.Path.Length - 4) { new Thread(() => { XpsDocument resDoc = null; Application.Current.Dispatcher.Invoke(new Action(() => { ((MainWindow)Application.Current.MainWindow).SetStatus("正在分析文件差异..."); ((MainWindow)Application.Current.MainWindow).ShowWaitUI(true); })); // this process may take a long time to execute. resDoc = DocOpt.CompareWordDocument(a, DocOpt.OfficeDocuFormat.doc, b, DocOpt.OfficeDocuFormat.doc); Application.Current.Dispatcher.Invoke(new Action(() => { m_docViewer.Document = resDoc.GetFixedDocumentSequence(); ((MainWindow)Application.Current.MainWindow).SetStatusReady(); ((MainWindow)Application.Current.MainWindow).ShowWaitUI(false); })); }).Start(); ShowCardDoc(); } else if (change.Path.LastIndexOf(".docx") == change.Path.Length - 5) { new Thread(() => { XpsDocument resDoc = null; Application.Current.Dispatcher.Invoke(new Action(() => { ((MainWindow)Application.Current.MainWindow).SetStatus("正在分析文件差异..."); ((MainWindow)Application.Current.MainWindow).ShowWaitUI(true); })); // this process may take a long time to execute. resDoc = DocOpt.CompareWordDocument(a, DocOpt.OfficeDocuFormat.docx, b, DocOpt.OfficeDocuFormat.docx); Application.Current.Dispatcher.Invoke(new Action(() => { m_docViewer.Document = resDoc.GetFixedDocumentSequence(); ((MainWindow)Application.Current.MainWindow).SetStatusReady(); ((MainWindow)Application.Current.MainWindow).ShowWaitUI(false); })); }).Start(); ShowCardDoc(); } else if (change.Path.LastIndexOf(".jpg") == change.Path.Length - 4 || change.Path.LastIndexOf(".jpeg") == change.Path.Length - 5) { // TODO: // Show image - jpeg difference here } else { a = (Diff.IsBinary(a) == true ? Encoding.ASCII.GetBytes("Binary content\nFile size: " + a.Length) : a); b = (Diff.IsBinary(b) == true ? Encoding.ASCII.GetBytes("Binary content\nFile size: " + b.Length) : b); Init(new Diff(a, b)); ShowCardText(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "错误"); } }