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> /// 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); }
/// ------------------------------------------------------------------------------------ /// <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> /// 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(); }