/// ------------------------------------------------------------------------------------ /// <summary> /// Just note that this method got called. /// </summary> /// <param name="bookMerger">The book merger.</param> /// ------------------------------------------------------------------------------------ public void MakeBackupIfNeeded(BookMerger bookMerger) { Assert.IsNotNull(bookMerger); if (MakeBackupCalled != null) MakeBackupCalled(bookMerger); m_NumberOfCallsToMakeBackupIfNeeded++; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Performs a partial overwrite of the book using the imported portion of the book. /// </summary> /// <param name="bookMerger">The book merger.</param> /// <param name="sectionsToRemove">The sections to remove as the first step (before /// calling the auto-merge code).</param> /// ------------------------------------------------------------------------------------ protected override void PartialOverwrite(BookMerger bookMerger, List <IScrSection> sectionsToRemove) { Assert.AreEqual((BookMerger)lstImportedBooks.Items[0].Tag, bookMerger); Assert.AreEqual(m_sectionsToRemove, sectionsToRemove); m_fPartialOverwriteWasCalled = true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Updates the diff count. /// </summary> /// <param name="item">The item.</param> /// <param name="bookMerger">The book merger.</param> /// ------------------------------------------------------------------------------------ private void UpdateDiffCount(ListViewItem item, BookMerger bookMerger) { int diffCountOrig = bookMerger.OriginalNumberOfDifferences; int diffCount = bookMerger.NumberOfDifferences; if (diffCount == 0) { item.SubItems[kStatusCol].Text = (diffCountOrig == 0) ? Properties.Resources.kstidIdentical : Properties.Resources.kstidNoDifferencesLeft; item.ImageIndex = 0; } else { string newText; if (diffCount == 1) { newText = diffCount == diffCountOrig ? Properties.Resources.kstidOneInitialDifference : Properties.Resources.kstidOneRemainingDifference; } else { newText = diffCount == diffCountOrig ? Properties.Resources.kstidInitialDifferences : Properties.Resources.kstidRemainingDifferences; } item.SubItems[kStatusCol].Text = newText; if (diffCount > 1) { item.SubItems[kStatusCol].Text = string.Format(item.SubItems[kStatusCol].Text, diffCount); } item.ImageIndex = -1; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the Click event of the btnOverwrite control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> /// ------------------------------------------------------------------------------------ protected void btnOverwrite_Click(object sender, EventArgs e) { foreach (ListViewItem item in SelectedBookItems) { BookMerger bookMerger = item.Tag as BookMerger; if (bookMerger == null) { continue; } IScrBook currentBook = bookMerger.BookCurr; string sDetails; List <IScrSection> sectionsToRemove; HashSet <int> missingBtWs; OverwriteType typeOfOverwrite = DetermineOverwritability(bookMerger, out sDetails, out sectionsToRemove, out missingBtWs); if (bookMerger.OriginalNumberOfDifferences != bookMerger.NumberOfDifferences) { if (!ConfirmOverwriteOfMergedVersion(currentBook.BestUIName)) { continue; } } if (typeOfOverwrite == OverwriteType.DataLoss) { // There would be data loss if the user overwrites, so inform them that overwrite // is not possible and go on to the next book. ReportDataLoss(currentBook, ScrDraftType.ImportedVersion, this, sDetails); continue; } if (missingBtWs == null || missingBtWs.Count == 0 || ConfirmBtOverwrite(currentBook, ScrDraftType.ImportedVersion, sectionsToRemove, missingBtWs, this)) { // This undo task will eventually get rolled into an outer undo task, but we // need to do this so that the low-level back translation code won't think we're // outside any undo task (because it suppresses the undo actions in that case). using (UndoableUnitOfWorkHelper undoHelper = new UndoableUnitOfWorkHelper( m_cache.ServiceLocator.GetInstance <IActionHandler>(), "Undo Overwrite", "Redo Overwrite")) { // Either no back translations might be lost, or the user has confirmed that they // want to overwrite them. if (typeOfOverwrite == OverwriteType.Partial) { PartialOverwrite(bookMerger, sectionsToRemove); } else { OnBookOverwritten(currentBook, OverwriteBook(bookMerger)); } undoHelper.RollBack = false; } SetItemStatus(item, ImportedBookStatus.Overwritten); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Makes a backup (saved version) of the current version of the book in the given /// BookMerger if we don't already have it backed up. /// </summary> /// <remarks>This is called when the user clicks the Compare and Merge button as well as /// before auto-merging.</remarks> /// <param name="bookMerger">The book merger.</param> /// ------------------------------------------------------------------------------------ public void MakeBackupIfNeeded(BookMerger bookMerger) { // Copy original to backup using (new WaitCursor(this)) { ReplaceBookInBackup(bookMerger.BookCurr, false); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determines the overwritability. /// </summary> /// <param name="bookMerger">The book merger.</param> /// <param name="sDetails">The details of what would be lost if the user overwrites. /// </param> /// <param name="sectionsToRemove">The sections to remove.</param> /// <param name="missingBtWs">The back translation writing systems in use /// in the Current book, but missing in the saved version.</param> /// <returns>The type of overwrite.</returns> /// ------------------------------------------------------------------------------------ protected override OverwriteType DetermineOverwritability(BookMerger bookMerger, out string sDetails, out List <IScrSection> sectionsToRemove, out HashSet <int> missingBtWs) { sDetails = null; sectionsToRemove = m_sectionsToRemove; missingBtWs = new HashSet <int>(); return(m_typeOfOverwrite); }
/// -------------------------------------------------------------------------------- /// <summary> /// Simulates pressing the Compare button /// </summary> /// -------------------------------------------------------------------------------- public void SimulateCompare() { // The first step after the user pressed the Compare button is to backup the // current book. BookMerger bookMerger = (BookMerger)lstImportedBooks.Items[0].Tag; ReflectionHelper.SetField(bookMerger, "m_origDiffCount", 893); m_backupVersion.AddBookCopy(bookMerger.BookCurr); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Performs a partial overwrite of the book using the imported portion of the book. /// </summary> /// <param name="bookMerger">The book merger.</param> /// <param name="sectionsToRemove">The sections to remove as the first step (before /// calling the auto-merge code).</param> /// ------------------------------------------------------------------------------------ protected virtual void PartialOverwrite(BookMerger bookMerger, List <IScrSection> sectionsToRemove) { Logger.WriteEvent("Performing partial Overwrite of book: " + bookMerger.BookCurr.BookId); using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this)) { progress.Title = Properties.Resources.kstidOverwriteCaption; progress.RunTask(bookMerger.DoPartialOverwrite, sectionsToRemove); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handle the View Differences button. Display the Review Differences window to /// view/merge differences between the current scripture and selected book in the tree. /// </summary> /// ------------------------------------------------------------------------------------ private void m_btnDiff_Click(object sender, System.EventArgs e) { // If the selected item is not a book, then don't do a diff. TreeNode node = m_treeArchives.SelectedNode; if (node == null) { return; } ScrBook bookRev = node.Tag as ScrBook; if (bookRev == null) { return; } //ScrDraft archive = node.Parent.Tag as ScrDraft; using (BookMerger merger = new BookMerger(m_cache, m_styleSheet, bookRev)) { using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this)) { progress.Title = DlgResources.ResourceString("kstidCompareCaption"); progress.Message = string.Format( DlgResources.ResourceString("kstidMergeProgress"), bookRev.BestUIName); progress.RunTask(true, new BackgroundTaskInvoker(merger.DetectDifferences)); } // always hide diffs that could cause deletion of current sections, if reverted merger.UseFilteredDiffList(); // If there were differences detected then show the diff dialog if (merger.NumberOfDifferences != 0) { using (DiffDialog dlg = new DiffDialog(merger, m_cache, m_styleSheet, m_zoomDraft, m_zoomFootnote)) { // We have to pass the owner (this), so that the dialog shows when the // user clicks on the TE icon in the taskbar. Otherwise only the Archive // dialog would pop up and beeps; diff dialog could only be regained by Alt-Tab. dlg.ShowDialog(this); } } else { // Tell users that no differences were found in the merge MessageBox.Show(this, string.Format(DlgResources.ResourceString("kstidNoDifferencesDetected"), bookRev.BestUIName), Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Update the difference counts for all imported books. /// </summary> /// ------------------------------------------------------------------------------------ private void UpdateDifferenceCounts() { foreach (ListViewItem item in lstImportedBooks.Items) { BookMerger bookMerger = item.Tag as BookMerger; if (bookMerger != null) { UpdateDiffCount(item, bookMerger); UpdateButtonStatus(bookMerger); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Makes a saved version of the current version of the book in the given BookMerger if /// needed (the agent is responsible for knowing whether a backup already exists). /// </summary> /// <param name="bookMerger">The book merger.</param> /// ------------------------------------------------------------------------------------ public void MakeBackupIfNeeded(BookMerger bookMerger) { Debug.Fail("Will we want to create a backup here? We may refactor so that import and" + "saved versions dialog use the same method... and the same IBookVersionAgent"); return; }
/// ------------------------------------------------------------------------------------ /// <summary> /// If all of the books are "new" or auto-merged or caller is asking to auto-accept /// changes, then don't actually show the dialog. /// See TE-7072, TE-2126 and FB-8847. Otherwise, show the dialog and process normally. /// </summary> /// <param name="wnd">The parent form</param> /// <param name="fAutoAcceptChanges">if set to <c>true</c> automatically accept all /// the imported stuff by applying the changes.</param> /// ------------------------------------------------------------------------------------ public void ShowOrSave(IWin32Window wnd, bool fAutoAcceptChanges) { int cNewOrAutoMerged = 0; m_owningForm = wnd as Form; bool fCancelled = false; foreach (ListViewItem item in lstImportedBooks.Items) { BookMerger bookMerger = item.Tag as BookMerger; if (bookMerger == null) { ++cNewOrAutoMerged; continue; } using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(m_owningForm)) { bookMerger.AttemptAutoMerge = true; bookMerger.BookVersionAgent = this; bookMerger.UseFilteredDiffList = true; progressDlg.Title = Properties.Resources.kstidImportProgressCaption; Debug.Assert(bookMerger.BookRev != null); progressDlg.Message = string.Format(Properties.Resources.kstidMergeProgress, bookMerger.BookRev.BestUIName); progressDlg.CancelButtonText = Properties.Resources.kstidStopImporting; // User should not see undo tasks, so the strings don't need to be localized. UndoableUnitOfWorkHelper.Do("Automerge", "Automerge", m_cache.ServiceLocator.GetInstance <IActionHandler>(), () => { try { progressDlg.RunTask(bookMerger.DetectDifferences); if (bookMerger.AutoMerged) { SetItemStatus(item, ImportedBookStatus.AutoMerged); cNewOrAutoMerged++; } else if (fAutoAcceptChanges) { progressDlg.Message = string.Format(Properties.Resources.kstidAutoAcceptMergeProgress, bookMerger.BookRev.BestUIName); progressDlg.RunTask(true, bookMerger.AcceptAllChanges); } } catch (WorkerThreadException e) { if (e.InnerException is CancelException) { // The current version of fCancelled = true; return; } throw; } }); } if (fCancelled) { return; } } if (cNewOrAutoMerged < lstImportedBooks.Items.Count && !fAutoAcceptChanges) { ShowDialog(wnd); } else { OnClosed(null); } }
/// -------------------------------------------------------------------------------- /// <summary> /// Gets the revision book from the BookMerger. /// </summary> /// -------------------------------------------------------------------------------- protected override ScrBook GetBookRev(BookMerger merger) { return(new DummyScrBook(m_cache, merger.BookRev.Hvo)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handle the View Differences button. Display the Review Differences window to /// view/merge differences between the current scripture and selected book in the tree. /// </summary> /// ------------------------------------------------------------------------------------ private void m_btnDiff_Click(object sender, System.EventArgs e) { // If the selected item is not a book, then don't do a diff. TreeNode node = m_treeArchives.SelectedNode; if (node == null) { return; } IScrBook bookRev = (IScrBook)node.Tag; if (bookRev == null) { return; } using (BookMerger merger = new BookMerger(m_cache, m_styleSheet, bookRev)) { using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this, m_cache.ThreadHelper)) { progress.Title = DlgResources.ResourceString("kstidCompareCaption"); progress.Message = string.Format( DlgResources.ResourceString("kstidMergeProgress"), bookRev.BestUIName); progress.RunTask(merger.DetectDifferences); } int cUnfilteredDifferences = merger.NumberOfDifferences; // always hide diffs that could cause deletion of current sections, if reverted merger.UseFilteredDiffList = true; bool fShowCompareAndMergeDlg = (merger.NumberOfDifferences != 0); if (!fShowCompareAndMergeDlg && cUnfilteredDifferences > 0) { // Tell users that no differences were found in the merge if (MessageBox.Show(this, string.Format(DlgResources.ResourceString("kstidOnlyAdditionsDetected"), bookRev.BestUIName), m_app.ApplicationName, MessageBoxButtons.YesNo) == DialogResult.Yes) { fShowCompareAndMergeDlg = true; merger.UseFilteredDiffList = false; } } // If there were differences detected then show the diff dialog if (fShowCompareAndMergeDlg) { using (DiffDialog dlg = new DiffDialog(merger, m_cache, m_styleSheet, m_zoomDraft, m_zoomFootnote, m_app, m_helpTopicProvider)) { // We have to pass the owner (this), so that the dialog shows when the // user clicks on the TE icon in the taskbar. Otherwise only the Archive // dialog would pop up and beeps; diff dialog could only be regained by Alt-Tab. dlg.ShowDialog(this); } } else if (cUnfilteredDifferences == 0) { // Tell users that no differences were found in the merge MessageBoxUtils.Show(this, string.Format(DlgResources.ResourceString("kstidNoDifferencesDetected"), bookRev.BestUIName), m_app.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Makes a backup (saved version) of the current version of the book in the given /// BookMerger if we don't already have it backed up. /// </summary> /// <remarks>This is called when the user clicks the Compare and Merge button as well as /// before auto-merging.</remarks> /// <param name="bookMerger">The book merger.</param> /// ------------------------------------------------------------------------------------ public void MakeBackupIfNeeded(BookMerger bookMerger) { // Copy original to backup using (WaitCursor wc = new WaitCursor(this)) { if (NoExistingBackup(bookMerger.BookCurr)) m_scr.AddBookToSavedVersion(m_backupVersion, bookMerger.BookCurr); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Overwrites the current version of a book with an imported version. /// </summary> /// <param name="bookMerger">The book merger containing the current version and the /// imported version to replace it with.</param> /// ------------------------------------------------------------------------------------ private int OverwriteBook(BookMerger bookMerger) { return OverwriteBook(bookMerger.BookCurr, bookMerger.BookRev); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Completes the initialize. Every test needs to call this before initializing. /// We don't include this in the initialize run before every test because, if we want /// to create another archive, it will cause a crash. /// </summary> /// <param name="fMakePhilemonChanges">if <c>true</c> make changes in Philemon and /// detect differences</param> /// <param name="bookRev">the book to use for the revision in the bookmerger.</param> /// ------------------------------------------------------------------------------------ private void CompleteInitialize(bool fMakePhilemonChanges, IScrBook bookRev) { Debug.Assert(m_bookMerger == null, "m_bookMerger is not null."); if (fMakePhilemonChanges) { m_philemonCurr = m_scr.FindBook(57); m_draft = m_scr.CreateSavedVersion("PhilemonArchive", new int[] {m_philemonCurr.Hvo}); m_philemonRev = m_draft.FindBook(57); m_draft.Type = ScrDraftType.ImportedVersion; } //if (m_bookMerger != null) // m_bookMerger.Dispose(); m_bookMerger = new BookMerger(Cache, null, fMakePhilemonChanges ? m_philemonRev : bookRev); if (fMakePhilemonChanges) { MakeChangesInPhilemonCurrent(); m_bookMerger.DetectDifferences(null); Assert.AreEqual(6, m_bookMerger.Differences.Count, "Problem in Initialize (unexpected number of diffs)"); } m_styleSheet = new FwStyleSheet(); m_styleSheet.Init(Cache, m_scr.Hvo, (int)Scripture.ScriptureTags.kflidStyles); Debug.Assert(m_dlg == null, "m_dlg is not null."); //if (m_dlg != null) // m_dlg.Dispose(); m_dlg = new DummyDiffDialog(m_bookMerger, Cache, m_styleSheet, null); m_dlg.CreateControl(); // Pieces that may be needed for merging BT segments. using (new SuppressSubTasks(Cache)) { EnsureAnnDefn(LangProject.kguidAnnTextSegment); EnsureAnnDefn(LangProject.kguidAnnFreeTranslation); EnsureAnnDefn(LangProject.kguidAnnWordformInContext); EnsureAnnDefn(LangProject.kguidAnnPunctuationInContext); if (Cache.LangProject.WordformInventoryOA == null) { WordformInventory wfi = new WordformInventory(); Cache.LangProject.WordformInventoryOA = wfi; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Makes a backup (saved version) of the current version of the book in the given /// BookMerger if we don't already have it backed up. /// </summary> /// <remarks>This is called when the user clicks the Compare and Merge button as well as /// before auto-merging.</remarks> /// <param name="bookMerger">The book merger.</param> /// ------------------------------------------------------------------------------------ public void MakeBackupIfNeeded(BookMerger bookMerger) { // Copy original to backup using (WaitCursor wc = new WaitCursor(this)) { ReplaceBookInBackup(bookMerger.BookCurr, false); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="bookMerger"></param> /// <param name="cache"></param> /// <param name="stylesheet"></param> /// <param name="draft"></param> /// ------------------------------------------------------------------------------------ public MockedCacheDiffDialog(BookMerger bookMerger, FdoCache cache, IVwStylesheet stylesheet, ScrDraft draft) : base(bookMerger, cache, stylesheet, draft) { }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; if (disposing) { // Dispose managed resources here. if (m_dlg != null) m_dlg.Dispose(); if (m_bookMerger != null) m_bookMerger.Dispose(); } // Dispose unmanaged resources here, whether disposing is true or false. m_bookMerger = null; m_philemonRev = null; m_philemonCurr = null; m_dlg = null; m_draft = null; m_styleSheet = null; base.Dispose(disposing); }
public override void Exit() { CheckDisposed(); //if (m_bookMerger != null) //{ // clear out the difference list. while (m_bookMerger.Differences.MoveFirst() != null) m_bookMerger.Differences.Remove(m_bookMerger.Differences.CurrentDifference); m_bookMerger.Dispose(); m_bookMerger = null; //} //if (m_dlg != null) //{ m_dlg.Close(); m_dlg.Dispose(); m_dlg = null; //} base.Exit(); }
public override void Initialize() { CheckDisposed(); base.Initialize(); // init the DummyBookMerger Debug.Assert(m_bookMerger == null, "m_bookMerger is not null."); //if (m_bookMerger != null) // m_bookMerger.Dispose(); m_bookMerger = new DummyBookMerger(Cache, null, m_philemonRev); m_styleSheet = new FwStyleSheet(); m_styleSheet.Init(Cache, m_scr.Hvo, (int)Scripture.ScriptureTags.kflidStyles); Debug.Assert(m_dlg == null, "m_dlg is not null."); //if (m_dlg != null) // m_dlg.Dispose(); m_dlg = new MockedCacheDiffDialog(m_bookMerger, Cache, m_styleSheet, null); ScriptureChangeWatcher.Create(Cache); // Additional pieces needed for Interlinear segment merging. EnsureAnnDefn(LangProject.kguidAnnTextSegment); EnsureAnnDefn(LangProject.kguidAnnFreeTranslation); EnsureAnnDefn(LangProject.kguidAnnWordformInContext); EnsureAnnDefn(LangProject.kguidAnnPunctuationInContext); if (Cache.LangProject.WordformInventoryOA == null) { WordformInventory wfi = new WordformInventory(); Cache.LangProject.WordformInventoryOA = wfi; } }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { // Must not be run more than once. if (IsDisposed) return; if (disposing) { // Dispose managed resources here. if (m_dlg != null) { m_dlg.Dispose(); m_dlg = null; } // clear out the difference list. if (m_bookMerger != null) { while (m_bookMerger.Differences.MoveFirst() != null) m_bookMerger.Differences.Remove(m_bookMerger.Differences.CurrentDifference); m_bookMerger.Dispose(); m_bookMerger = null; } } // Dispose unmanaged resources here, whether disposing is true or false. m_philemonRev = null; m_philemonCurr = null; m_styleSheet = null; base.Dispose(disposing); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determines the overwritability. /// </summary> /// <param name="merger">The merger.</param> /// <param name="sDetails">The details of what would be lost if the user overwrites.</param> /// <param name="sectionsToRemove">The sections to remove.</param> /// <param name="missingBtWs">The back translation writing systems in use /// in the Current book, but missing in the saved version.</param> /// <returns>The type of overwrite.</returns> /// ------------------------------------------------------------------------------------ protected virtual OverwriteType DetermineOverwritability(BookMerger merger, out string sDetails, out List <IScrSection> sectionsToRemove, out HashSet <int> missingBtWs) { return(merger.BookCurr.DetermineOverwritability( merger.BookRev, out sDetails, out sectionsToRemove, out missingBtWs)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="bookMerger"></param> /// <param name="cache"></param> /// <param name="stylesheet"></param> /// <param name="draft"></param> /// ------------------------------------------------------------------------------------ public DummyDiffDialog(BookMerger bookMerger, FdoCache cache, IVwStylesheet stylesheet, ScrDraft draft) : base(bookMerger, cache, stylesheet, 1.0f, 1.0f) { }
public override void TestTearDown() { // clear out the difference list. while (m_bookMerger.Differences.MoveFirst() != null) m_bookMerger.Differences.Remove(m_bookMerger.Differences.CurrentDifference); m_bookMerger.Dispose(); m_bookMerger = null; m_dlg.Close(); m_dlg.Dispose(); m_dlg = null; base.TestTearDown(); }
public override void Exit() { CheckDisposed(); if (m_dlg != null) { m_dlg.Close(); m_dlg.Dispose(); m_dlg = null; } // Have to do this before the BookMerger is zapped, // or the Difference objects in some special action handler blow up. base.Exit(); // clear out the difference list. if (m_bookMerger != null) { // No need to remove them this way, // as Dispsoe does a much better job of wiping out a BookMerger object now. //while (m_bookMerger.Differences.MoveFirst() != null) // m_bookMerger.Differences.Remove(m_bookMerger.Differences.CurrentDifference); m_bookMerger.Dispose(); m_bookMerger = null; } m_philemonRev = null; m_philemonCurr = null; m_draft = null; m_styleSheet = null; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Update the status of the Compare and Overwrite buttons on the dialog. /// </summary> /// <param name="bookMerger"></param> /// ------------------------------------------------------------------------------------ private void UpdateButtonStatus(BookMerger bookMerger) { btnCompare.Enabled = (bookMerger != null && bookMerger.BookCurr != null && bookMerger.NumberOfDifferences > 0); btnOverwrite.Enabled = (bookMerger != null && bookMerger.BookCurr != null); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Performs a partial overwrite of the book using the imported portion of the book. /// </summary> /// <param name="bookMerger">The book merger.</param> /// <param name="sectionsToRemove">The sections to remove as the first step (before /// calling the auto-merge code).</param> /// ------------------------------------------------------------------------------------ protected virtual void PartialOverwrite(BookMerger bookMerger, List<IScrSection> sectionsToRemove) { using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this)) { progress.Title = DlgResources.ResourceString("kstidOverwriteCaption"); progress.RunTask(true, new BackgroundTaskInvoker(bookMerger.DoPartialOverwrite), sectionsToRemove); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determines the overwritability. /// </summary> /// <param name="merger">The merger.</param> /// <param name="sDetails">The details of what would be lost if the user overwrites.</param> /// <param name="sectionsToRemove">The sections to remove.</param> /// <param name="missingBtWs">The back translation writing systems in use /// in the Current book, but missing in the saved version.</param> /// <returns>The type of overwrite.</returns> /// ------------------------------------------------------------------------------------ protected virtual OverwriteType DetermineOverwritability(BookMerger merger, out string sDetails, out List<IScrSection> sectionsToRemove, out List<int> missingBtWs) { return GetBookCur(merger).DetermineOverwritability( GetBookRev(merger), out sDetails, out sectionsToRemove, out missingBtWs); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the revision book from the BookMerger. /// </summary> /// ------------------------------------------------------------------------------------ protected virtual ScrBook GetBookRev(BookMerger merger) { return (ScrBook)merger.BookRev; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Updates the diff count. /// </summary> /// <param name="item">The item.</param> /// <param name="bookMerger">The book merger.</param> /// ------------------------------------------------------------------------------------ private void UpdateDiffCount(ListViewItem item, BookMerger bookMerger) { int diffCountOrig = bookMerger.OriginalNumberOfDifferences; int diffCount = bookMerger.NumberOfDifferences; if (diffCount == 0) { item.SubItems[kStatusCol].Text = TeResourceHelper.GetResourceString( (diffCountOrig == 0) ? "kstidIdentical" : "kstidNoDifferencesLeft"); item.ImageIndex = 0; } else { string stid = diffCount == 1 ? "kstidOne{0}Difference" : "kstid{0}Differences"; stid = String.Format(stid, (diffCount == diffCountOrig) ? "Initial" : "Remaining"); item.SubItems[kStatusCol].Text = TeResourceHelper.GetResourceString(stid); if (diffCount > 1) item.SubItems[kStatusCol].Text = String.Format(item.SubItems[kStatusCol].Text, diffCount); item.ImageIndex = -1; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Completes the initialize. Every test needs to call this before initializing. /// We don't include this in the initialize run before every test because, if we want /// to create another archive, it will cause a crash. /// </summary> /// <param name="fMakePhilemonChanges">if <c>true</c> make changes in Philemon and /// detect differences</param> /// <param name="bookRev">the book to use for the revision in the bookmerger.</param> /// ------------------------------------------------------------------------------------ private void CompleteInitialize(bool fMakePhilemonChanges, IScrBook bookRev) { Debug.Assert(m_bookMerger == null, "m_bookMerger is not null."); if (fMakePhilemonChanges) { using (UndoableUnitOfWorkHelper undoHelper = new UndoableUnitOfWorkHelper( m_actionHandler, "revision")) { m_philemonCurr = m_scr.FindBook(57); m_draft = Cache.ServiceLocator.GetInstance<IScrDraftFactory>().Create("PhilemonArchive", new IScrBook[] { m_philemonCurr }); m_philemonRev = m_draft.FindBook(57); m_draft.Type = ScrDraftType.ImportedVersion; undoHelper.RollBack = false; } } m_bookMerger = new BookMerger(Cache, null, fMakePhilemonChanges ? m_philemonRev : bookRev); if (fMakePhilemonChanges) { using (UndoableUnitOfWorkHelper undoHelper = new UndoableUnitOfWorkHelper( m_actionHandler, "Philemon changes")) { MakeChangesInPhilemonCurrent(); m_bookMerger.DetectDifferences(null); Assert.AreEqual(6, m_bookMerger.Differences.Count, "Problem in TestSetup (unexpected number of diffs)"); undoHelper.RollBack = false; } } m_styleSheet = new FwStyleSheet(); m_styleSheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles); Debug.Assert(m_dlg == null, "m_dlg is not null."); //if (m_dlg != null) // m_dlg.Dispose(); m_dlg = new DummyDiffDialog(m_bookMerger, Cache, m_styleSheet, null); m_dlg.CreateControl(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the current book from the BookMerger. /// </summary> /// ------------------------------------------------------------------------------------ protected virtual ScrBook GetBookCur(BookMerger merger) { return (ScrBook)merger.BookCurr; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the Click event of the m_btnCopyToCurr control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event /// data.</param> /// ------------------------------------------------------------------------------------ private void m_btnCopyToCurr_Click(object sender, EventArgs e) { // If nothing or a complete archive is selected, do nothing. TreeNode node = m_treeArchives.SelectedNode; if (node == null || !(node.Tag is ScrBook)) { return; } ScrBook savedBook = node.Tag as ScrBook; ScrBook originalBook = (ScrBook)m_scr.FindBook(savedBook.CanonicalNum); TreeNode parentNode = node.Parent; ScrDraft archive = parentNode.Tag as ScrDraft; OverwriteType typeOfOverwrite = OverwriteType.FullNoDataLoss; List <IScrSection> sectionsToRemove = null; if (originalBook != null) { string sDetails; List <int> missingBtWs; typeOfOverwrite = originalBook.DetermineOverwritability(savedBook, out sDetails, out sectionsToRemove, out missingBtWs); if (typeOfOverwrite == OverwriteType.DataLoss) { // There will be data loss if the user overwrites so we don't allow them // to continue. ImportedBooks.ReportDataLoss(originalBook, ScrDraftType.SavedVersion, this, sDetails); return; } if (missingBtWs != null && !ImportedBooks.ConfirmBtOverwrite(originalBook, ScrDraftType.SavedVersion, sectionsToRemove, missingBtWs, this)) { // The user might lose back translation(s) if they proceed and they decided // against it. return; } } string stUndo; string stRedo; TeResourceHelper.MakeUndoRedoLabels("kstidOverwriteCurrentWithSaved", out stUndo, out stRedo); using (new WaitCursor(this)) using (UndoTaskHelper helper = new UndoTaskHelper(m_cache.MainCacheAccessor, null, stUndo, stRedo, true)) { try { if (typeOfOverwrite == OverwriteType.Partial) { // Perform an automerge of the original book and the saved version. using (BookMerger merger = new BookMerger(m_cache, m_styleSheet, savedBook)) { using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this)) { progress.Title = DlgResources.ResourceString("kstidOverwriteCaption"); progress.RunTask(true, new BackgroundTaskInvoker(merger.DoPartialOverwrite), sectionsToRemove); } if (!merger.AutoMerged) { throw new Exception("Partial Overwrite was not successful."); } } } else { if (originalBook != null) { if (m_cache.ActionHandlerAccessor != null) { // When Undoing, we need to first resurrect the deleted book, then // put it back in the book filter...so we need a RIFF in the sequence // BEFORE the delete. ReplaceInFilterFixer fixer1 = new ReplaceInFilterFixer(originalBook.Hvo, 0, m_cache); m_cache.ActionHandlerAccessor.AddAction(fixer1); } originalBook.DeleteUnderlyingObject(); } int hvoNew = (m_scr as Scripture).CopyBookToCurrent(savedBook); ReplaceInFilterFixer fixer = new ReplaceInFilterFixer(0, hvoNew, m_cache); fixer.Redo(false); if (m_cache.ActionHandlerAccessor != null) { m_cache.ActionHandlerAccessor.AddAction(fixer); } } } catch { helper.EndUndoTask = false; throw; } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="merger"></param> /// ------------------------------------------------------------------------------------ public UndoMajorDifferenceAction(BookMerger merger) { m_bookMerger = merger; m_undoDifferenceListClone = m_bookMerger.Differences.Clone(); m_undoReviewListClone = m_bookMerger.ReviewedDiffs.Clone(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Overwrites the current version of a book with an imported version. /// </summary> /// <param name="bookMerger">The book merger containing the current version and the /// imported version to replace it with.</param> /// ------------------------------------------------------------------------------------ private IScrBook OverwriteBook(BookMerger bookMerger) { return(OverwriteBook(bookMerger.BookCurr, bookMerger.BookRev)); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the Click event of the m_btnCopyToCurr control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event /// data.</param> /// ------------------------------------------------------------------------------------ private void m_btnCopyToCurr_Click(object sender, EventArgs e) { // If nothing or a complete archive is selected, do nothing. TreeNode node = m_treeArchives.SelectedNode; if (node == null || !(node.Tag is IScrBook)) { return; } IScrBook savedBook = (IScrBook)node.Tag; IScrBook originalBook = (IScrBook)m_scr.FindBook(savedBook.CanonicalNum); TreeNode parentNode = node.Parent; IScrDraft archive = (IScrDraft)parentNode.Tag; OverwriteType typeOfOverwrite = OverwriteType.FullNoDataLoss; List <IScrSection> sectionsToRemove = null; if (originalBook != null) { string sDetails; HashSet <int> missingBtWs; typeOfOverwrite = originalBook.DetermineOverwritability(savedBook, out sDetails, out sectionsToRemove, out missingBtWs); if (typeOfOverwrite == OverwriteType.DataLoss) { // There will be data loss if the user overwrites so we don't allow them // to continue. ImportedBooks.ReportDataLoss(originalBook, ScrDraftType.SavedVersion, this, sDetails); return; } if (missingBtWs != null && !ImportedBooks.ConfirmBtOverwrite(originalBook, ScrDraftType.SavedVersion, sectionsToRemove, missingBtWs, this)) { // The user might lose back translation(s) if they proceed and they decided // against it. return; } } string stUndo; string stRedo; TeResourceHelper.MakeUndoRedoLabels("kstidOverwriteCurrentWithSaved", out stUndo, out stRedo); using (new WaitCursor(this)) using (UndoTaskHelper undoHelper = new UndoTaskHelper(m_cache.ActionHandlerAccessor, null, stUndo, stRedo)) { if (typeOfOverwrite == OverwriteType.Partial) { // Perform an automerge of the original book and the saved version. using (BookMerger merger = new BookMerger(m_cache, m_styleSheet, savedBook)) { using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this, m_cache.ThreadHelper)) { progress.Title = DlgResources.ResourceString("kstidOverwriteCaption"); progress.RunTask(merger.DoPartialOverwrite, sectionsToRemove); } if (!merger.AutoMerged) { throw new ContinuableErrorException("Partial Overwrite was not successful."); } } } else { // FWNX-677 - caused by mono-calgary patch bug-614850_Modal_614850_v6.patch List <Form> disabled_forms = new List <Form>(); if (MiscUtils.IsUnix) { lock (Application.OpenForms) { foreach (Form form in Application.OpenForms) { if (form.Enabled == false) { disabled_forms.Add(form); } } } foreach (Form form in disabled_forms) { form.Enabled = true; } } if (originalBook != null) { if (m_cache.ActionHandlerAccessor != null) { // When Undoing, we need to first resurrect the deleted book, then // put it back in the book filter...so we need a RIFF in the sequence // BEFORE the delete. ReplaceInFilterFixer fixer1 = new ReplaceInFilterFixer(originalBook, null, m_app); m_cache.ActionHandlerAccessor.AddAction(fixer1); } m_scr.ScriptureBooksOS.Remove(originalBook); } IScrBook newBook = m_scr.CopyBookToCurrent(savedBook); ReplaceInFilterFixer fixer = new ReplaceInFilterFixer(null, newBook, m_app); fixer.Redo(); if (m_cache.ActionHandlerAccessor != null) { m_cache.ActionHandlerAccessor.AddAction(fixer); } // FWNX-677 - caused by mono-calgary patch bug-614850_Modal_614850_v6.patch if (MiscUtils.IsUnix) { foreach (Form form in disabled_forms) { form.Enabled = false; } disabled_forms.Clear(); } } undoHelper.RollBack = false; } }
/// ----------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="DiffDialog"/> class. /// </summary> /// <param name="bookMerger"></param> /// <param name="cache"></param> /// <param name="stylesheet"></param> /// <param name="zoomFactorDraft">The zoom percentage to be used for the "draft" (i.e., /// main Scripture) view</param> /// <param name="zoomFactorFootnote">The zoom percentage to be used for the "footnote" /// view</param> /// <param name="fDoCollapseUndo">true if we want to collapse to a single Undo item on close.</param> /// ----------------------------------------------------------------------------------- public DiffDialog(BookMerger bookMerger, FdoCache cache, IVwStylesheet stylesheet, float zoomFactorDraft, float zoomFactorFootnote, bool fDoCollapseUndo) { Debug.Assert(cache != null); m_viewHelper = new ActiveViewHelper(this); m_fDoCollapseUndo = fDoCollapseUndo; // Required for Windows Form Designer support InitializeComponent(); // just as fallback in case the Designer replaced FwContainer with Container // in InitializeComponent()... if (!(components is FwContainer)) components = new FwContainer(components); // the last column of the table layout manager in the last row should have the // width of the scroll bar TableLayoutPanel tablePanel = tableLayoutPanel.GetControlFromPosition(0, 3) as TableLayoutPanel; tablePanel.ColumnStyles[3].Width = SystemInformation.VerticalScrollBarWidth - SystemInformation.FixedFrameBorderSize.Width; tablePanel = tableLayoutPanel.GetControlFromPosition(1, 3) as TableLayoutPanel; tablePanel.ColumnStyles[3].Width = SystemInformation.VerticalScrollBarWidth - SystemInformation.FixedFrameBorderSize.Width; m_msgMediator = new Mediator(); m_msgMediator.AddColleague(this); components.Add(m_msgMediator); m_bookMerger = bookMerger; m_differences = bookMerger.Differences; m_cache = cache; m_scr = m_cache.LangProject.TranslatedScriptureOA; m_stylesheet = stylesheet; m_zoomFactorDraft = zoomFactorDraft; m_zoomFactorFootnote = zoomFactorFootnote; // Don't start out in edit mode m_editMode = false; // If the diff is a comparison of the current against a normal saved version, then // change the label text. ScrDraft draft = new ScrDraft(m_cache, m_bookMerger.BookRev.OwnerHVO); if (draft.Type == ScrDraftType.SavedVersion) { lblSavedVersion.Text = string.Format(TeDiffViewResources.kstidSavedVersion, draft.Description); } else lblSavedVersion.Text = string.Format(lblSavedVersion.Text, draft.Description); CreateUndoMark(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handler to make sure MakeBackupIfNeeded was called before the current was changed /// by the code that executes the partial overwrite. /// </summary> /// <param name="bookMerger">The book merger.</param> /// ------------------------------------------------------------------------------------ private void m_bookVersionAgent_MakeBackupCalled_DoPartialOverwrite_TitleInRevision(BookMerger bookMerger) { Assert.AreEqual(1, bookMerger.BookCurr.TitleOA.ParagraphsOS.Count); IScrTxtPara title = (IScrTxtPara)bookMerger.BookCurr.TitleOA.ParagraphsOS[0]; Assert.AreEqual("Genesis", title.Contents.Text); }
/// -------------------------------------------------------------------------------- /// <summary> /// Gets the revision book from the BookMerger. /// </summary> /// -------------------------------------------------------------------------------- protected override ScrBook GetBookRev(BookMerger merger) { return new DummyScrBook(m_cache, merger.BookRev.Hvo); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="DiffDialog"/> class. /// </summary> /// <param name="bookMerger">The book merger.</param> /// <param name="cache">The cache.</param> /// <param name="stylesheet">The stylesheet.</param> /// <param name="zoomFactorDraft">The zoom percentage to be used for the "draft" (i.e., /// main Scripture) view</param> /// <param name="zoomFactorFootnote">The zoom percentage to be used for the "footnote" /// view</param> /// <param name="app">The app.</param> /// <param name="helpTopicProvider">The help topic provider.</param> /// ------------------------------------------------------------------------------------ public DiffDialog(BookMerger bookMerger, FdoCache cache, IVwStylesheet stylesheet, float zoomFactorDraft, float zoomFactorFootnote, IApp app, IHelpTopicProvider helpTopicProvider) : this(bookMerger, cache, stylesheet, zoomFactorDraft, zoomFactorFootnote, true, app, helpTopicProvider) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Performs a partial overwrite of the book using the imported portion of the book. /// </summary> /// <param name="bookMerger">The book merger.</param> /// <param name="sectionsToRemove">The sections to remove as the first step (before /// calling the auto-merge code).</param> /// ------------------------------------------------------------------------------------ protected virtual void PartialOverwrite(BookMerger bookMerger, List<IScrSection> sectionsToRemove) { Logger.WriteEvent("Performing partial Overwrite of book: " + bookMerger.BookCurr.BookId); using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this)) { progress.Title = DlgResources.ResourceString("kstidOverwriteCaption"); progress.RunTask(bookMerger.DoPartialOverwrite, sectionsToRemove); } }
/// ----------------------------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="DiffDialog"/> class. /// </summary> /// <param name="bookMerger"></param> /// <param name="cache"></param> /// <param name="stylesheet"></param> /// <param name="zoomFactorDraft">The zoom percentage to be used for the "draft" (i.e., /// main Scripture) view</param> /// <param name="zoomFactorFootnote">The zoom percentage to be used for the "footnote" /// view</param> /// ----------------------------------------------------------------------------------- public DiffDialog(BookMerger bookMerger, FdoCache cache, IVwStylesheet stylesheet, float zoomFactorDraft, float zoomFactorFootnote) : this(bookMerger, cache, stylesheet, zoomFactorDraft, zoomFactorFootnote, true) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Determines the overwritability. /// </summary> /// <param name="bookMerger">The book merger.</param> /// <param name="sDetails">The details of what would be lost if the user overwrites. /// </param> /// <param name="sectionsToRemove">The sections to remove.</param> /// <param name="missingBtWs">The back translation writing systems in use /// in the Current book, but missing in the saved version.</param> /// <returns>The type of overwrite.</returns> /// ------------------------------------------------------------------------------------ protected override OverwriteType DetermineOverwritability(BookMerger bookMerger, out string sDetails, out List<IScrSection> sectionsToRemove, out List<int> missingBtWs) { sDetails = null; sectionsToRemove = m_sectionsToRemove; missingBtWs = m_missingBtWs; return m_typeOfOverwrite; }
/// ----------------------------------------------------------------------------------- /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged /// resources; <c>false</c> to release only unmanaged resources. /// </param> /// ----------------------------------------------------------------------------------- protected override void Dispose( bool disposing ) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) return; if (disposing) { if (m_messageFilterInstalled) { Application.RemoveMessageFilter(this); m_messageFilterInstalled = false; } // We don't want to call Controls.Clear() here, because that causes the controls // to change size (and fire the events for it...). It causes CreateMenuAndToolbars() // to be called, so we end up with two toolbar adapters, but we dispose only one, // so eventually it tries to access the already disposed mediator. //Controls.Clear(); // No, since m_bookMerger owns it. // if (m_differences != null) // m_differences.Dispose(); if (m_viewHelper != null) m_viewHelper.Dispose(); if (m_msgMediator != null) { m_msgMediator.RemoveColleague(this); // m_msgMediator gets disposed from calling components.Dispose() below } if (m_undoTaskHelper != null) m_undoTaskHelper.Dispose(); if(components != null) { components.Dispose(); } } // Deal with unmanaged stuff here. m_viewHelper = null; m_differences = null; // Just null it, since m_bookMerger owns it and will dispose it. m_msgMediator = null; m_bookMerger = null; // Client gave it, so it has to dispose it. m_cache = null; m_scr = null; m_stylesheet = null; m_undoTaskHelper = null; base.Dispose( disposing ); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Performs a partial overwrite of the book using the imported portion of the book. /// </summary> /// <param name="bookMerger">The book merger.</param> /// <param name="sectionsToRemove">The sections to remove as the first step (before /// calling the auto-merge code).</param> /// ------------------------------------------------------------------------------------ protected override void PartialOverwrite(BookMerger bookMerger, List<IScrSection> sectionsToRemove) { Assert.AreEqual((BookMerger)lstImportedBooks.Items[0].Tag, bookMerger); Assert.AreEqual(m_sectionsToRemove, sectionsToRemove); m_fPartialOverwriteWasCalled = true; }