Esempio n. 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Overwrites the current version of a book with an imported version.
		/// </summary>
		/// <param name="bookCurr">The current version of the book.</param>
		/// <param name="bookImported">The imported version of the book.</param>
		/// ------------------------------------------------------------------------------------
		protected IScrBook OverwriteBook(IScrBook bookCurr, IScrBook bookImported)
		{
			if (bookCurr != null)
			{
				Logger.WriteEvent("Performing full Overwrite of book: " + bookCurr.BookId);

				// Set up undo action
				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(bookCurr, null, m_app as FwApp);
					m_cache.ActionHandlerAccessor.AddAction(fixer1);
				}

				bool fBackedUp = false;
				// Move existing book to backup.
				if (m_booksBackedUp.Contains(bookCurr.CanonicalNum))
				{
					// We already have saved the current version before we did a merge. Now the
					// user has decided that he wants to overwrite instead, so we blow away
					// the merged version before we copy the imported book to current (TE-7214).
					m_scr.ScriptureBooksOS.Remove(bookCurr);
					fBackedUp = true;
				}

				if (!fBackedUp)
				{
					// Didn't find this book in the collection, so move it to the backup.
					ReplaceBookInBackup(bookCurr, true);
				}
			}
			IScrBook newCopy = m_scr.CopyBookToCurrent(bookImported);
			ReplaceInFilterFixer fixer = new ReplaceInFilterFixer(null, newCopy, m_app as FwApp);

			fixer.Redo();
			if (m_cache.ActionHandlerAccessor != null)
				m_cache.ActionHandlerAccessor.AddAction(fixer);

			return newCopy;
		}
Esempio n. 2
0
        /// ------------------------------------------------------------------------------------
        /// <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>
        /// 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;
                    }
                }
        }