Example #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Overrides DisplayImportedBooksDlg for testing - just accepts .
		/// </summary>
		/// <param name="backupSavedVersion">The saved version for backups of any overwritten
		/// books.</param>
		/// ------------------------------------------------------------------------------------
		protected override void DisplayImportedBooksDlg(IScrDraft backupSavedVersion)
		{
#if WANTTESTPORT // (TE) Do we still need this? (see below)
			DummyImportedBooks dlg = new DummyImportedBooks(m_cache, ImportedSavedVersion, backupSavedVersion);
			dlg.AcceptAllImportedBooks();
#endif
		}
Example #2
0
        /// --------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="T:ImportedBooks"/> class.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="importVersion">The ScrDraft containing the imported books.</param>
        /// <param name="backupVersion">where to store stuff overwritten or merged.</param>
        /// <param name="booksImported">The canonical numbers of the books which were
        /// imported (unordered).</param>
        /// <param name="helpTopicProvider">The help topic provider.</param>
        /// <param name="app">The application.</param>
        /// --------------------------------------------------------------------------------
        public ImportedBooks(LcmCache cache,
                             IScrDraft importVersion, IScrDraft backupVersion, IEnumerable <int> booksImported,
                             IHelpTopicProvider helpTopicProvider, IApp app) :
            this(cache, importVersion, backupVersion, helpTopicProvider, app)
        {
            foreach (int bookId in booksImported)
            {
                IScrBook rev = importVersion.FindBook(bookId);

                ListViewItem item = new ListViewItem(
                    new[] { rev.Name.UserDefaultWritingSystem.Text, GetBookInfo(rev) });
                item.SubItems.Add(Properties.Resources.kstidUnknown);

                IScrBook curBook = m_scr.FindBook(rev.CanonicalNum);
                if (curBook == null)
                {
                    SetItemStatus(item, ImportedBookStatus.New);
                    // User should not see this undo task so we don't need to localize the strings.
                    UndoableUnitOfWorkHelper.Do("Add book", "Add book",
                                                m_cache.ServiceLocator.GetInstance <IActionHandler>(), () =>
                    {
                        OnBookAdded(m_scr.CopyBookToCurrent(rev));
                    });
                }
                else
                {
                    item.Tag = new BookMerger(m_cache, rev);
                }
                lstImportedBooks.Items.Add(item);
            }
            lstImportedBooks.Items[0].Selected = true;
        }
Example #3
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initialize the FDO cache and open database
 /// </summary>
 /// <remarks>This method is called before each test</remarks>
 /// ------------------------------------------------------------------------------------
 public override void Initialize()
 {
     base.Initialize();
     m_inMemoryCache.InitializeWritingSystemEncodings();
     m_savedVersion = new ScrDraft();
     m_scr.ArchivedDraftsOC.Add(m_savedVersion);
 }
Example #4
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Discards the imported version and the undo actions.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public void DiscardImportedVersionAndUndoActions()
 {
     RemoveEmptyBackupSavedVersion();
     m_scr.ArchivedDraftsOC.Remove(m_importedSavedVersion);
     m_importedSavedVersion = null;
     m_cache.ActionHandlerAccessor.DiscardToMark(m_hMark);
 }
Example #5
0
 /// <summary>
 /// Displays the imported books dialog box (virtual to allow tests to suppress display
 /// of dialog box).
 /// </summary>
 /// <param name="backupSavedVersion">The saved version for backups of any overwritten
 /// books.</param>
 protected virtual void DisplayImportedBooksDlg(IScrDraft backupSavedVersion)
 {
     using (var dlg = new ImportedBooks(Cache, ImportedVersion, backupSavedVersion, UndoManager.ImportedBooks.Keys, m_helpTopicProvider, m_app))
     {
         dlg.ShowOrSave(m_mainWnd, true);
     }
 }
Example #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// When dialog closes, finish up the pending stuff.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> that contains the event data.</param>
        /// ------------------------------------------------------------------------------------
        protected override void OnClosed(EventArgs e)
        {
            using (new WaitCursor(this))
            {
                // User should not see undo tasks, so the strings don't need to be localized.
                UndoableUnitOfWorkHelper.Do("Remove empty", "Remove empty",
                                            m_cache.ServiceLocator.GetInstance <IActionHandler>(), () =>
                {
                    // Enhance JohnT: Normally we would make sure all these changes were a single Undo action,
                    // but for now we know this is part of a still larger Undoable task, the whole import.
                    // CollapseToMark is used to convert them all into one.

                    // Delete empty revisions created for this import.
                    //if (m_booksImported.BooksOS.Count == 0)
                    //    m_booksImported.DeleteUnderlyingObject();
                    if (m_backupVersion.BooksOS.Count == 0)
                    {
                        m_scr.ArchivedDraftsOC.Remove(m_backupVersion);
                        m_backupVersion = null;
                    }
                });

                if (e != null)
                {
                    base.OnClosed(e);
                }
            }
        }
Example #7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// User clicked OK button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        private void OnOk(object sender, System.EventArgs e)
        {
            using (new WaitCursor(this))
            {
                StepThroughNodesAndAddToList(m_treeView.Nodes[0]);
                if (m_BooksToSave.Count == 0)
                {
                    Close();
                    return;
                }

                using (new SuppressSubTasks(m_cache))
                {
                    string sSavePoint;
                    m_cache.DatabaseAccessor.SetSavePointOrBeginTrans(out sSavePoint);
                    try
                    {
                        m_SavedVersion = m_scr.CreateSavedVersion(m_description.Text,
                                                                  m_BooksToSave.ToArray());
                        m_cache.DatabaseAccessor.CommitTrans();
                    }
                    catch
                    {
                        m_cache.DatabaseAccessor.RollbackSavePoint(sSavePoint);
                        throw;
                    }
                    finally
                    {
                        Close();
                    }
                }
            }
        }
Example #8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds the new book (to the saved version...create it if need be) for which the
        /// vernacular is about to be imported.
        /// </summary>
        /// <param name="nCanonicalBookNumber">The canonical book number.</param>
        /// <param name="description">Description to use for the newly created imported version
        /// if necessary.</param>
        /// <param name="title">The title of the newly created book.</param>
        /// <returns>The newly created book (which has been added to the imported version)</returns>
        /// ------------------------------------------------------------------------------------
        public IScrBook AddNewBook(int nCanonicalBookNumber, string description, out IStText title)
        {
            if (m_importedVersion == null)
            {
                m_importedVersion = GetOrCreateVersion(description);
            }
            IScrBook existingBook = SetCurrentBook(nCanonicalBookNumber, true);

            if (existingBook != null)
            {
                if (m_lastBookAddedToImportedBooks == 0)
                {
                    // We've been asked to create a book we have already imported (typically
                    // reading multiple independent SF files).
                    title = existingBook.TitleOA;
                    return(existingBook);
                }

                // Replace any previous book with the one we're about to import.
                m_importedVersion.BooksOS.Remove(existingBook);
            }

            IScrBook newScrBook = m_cache.ServiceLocator.GetInstance <IScrBookFactory>().Create(m_importedVersion.BooksOS,
                                                                                                nCanonicalBookNumber, out title);

            return(newScrBook);
        }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initialize the window
		/// </summary>
		/// <param name="draft">The draft.</param>
		/// ------------------------------------------------------------------------------------
		public void SetDialogInfo(IScrDraft draft)
		{
			m_draft = draft;
			m_cbProtected.Checked = m_draft.Protected;
			m_tbDescription.Text = m_draft.Description;
			pictVersionType.Image =
				m_imageListTypeIcons.Images[m_draft.Type == ScrDraftType.ImportedVersion ? 0 : 1];
			lblCreatedDate.Text = m_draft.DateCreated.ToString();
		}
Example #10
0
		/// <summary>
		/// This must be called before starting import.
		/// </summary>
		public void StartImportingFiles()
		{
			Debug.Assert(m_cache.DomainDataByFlid.GetActionHandler() != null);
			Debug.Assert(m_cache.DomainDataByFlid.GetActionHandler().CurrentDepth == 0);
			m_hMark = m_cache.DomainDataByFlid.GetActionHandler().Mark();
			IActionHandler actionHandler = m_cache.ActionHandlerAccessor;
			actionHandler.BeginUndoTask("Create saved version", "Create saved version");
			m_backupVersion = GetOrCreateVersion(TeResourceHelper.GetResourceString("kstidSavedVersionDescriptionOriginal"));
		}
Example #11
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Displays the imported books dialog box (virtual to allow tests to supress display
 /// of dialog box).
 /// </summary>
 /// <param name="backupSavedVersion">The saved version for backups of any overwritten
 /// books.</param>
 /// ------------------------------------------------------------------------------------
 protected virtual void DisplayImportedBooksDlg(IScrDraft backupSavedVersion)
 {
     using (ImportedBooks dlg = new ImportedBooks(m_cache, m_styleSheet,
                                                  m_importedSavedVersion, m_importCallbacks.DraftViewZoomPercent,
                                                  m_importCallbacks.FootnoteZoomPercent, backupSavedVersion, m_bookFilter))
     {
         dlg.ShowOrSave(m_mainWnd);
     }
 }
Example #12
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initialize the window
 /// </summary>
 /// <param name="draft">The draft.</param>
 /// ------------------------------------------------------------------------------------
 public void SetDialogInfo(IScrDraft draft)
 {
     m_draft = draft;
     m_cbProtected.Checked = m_draft.Protected;
     m_tbDescription.Text  = m_draft.Description;
     pictVersionType.Image =
         m_imageListTypeIcons.Images[m_draft.Type == ScrDraftType.ImportedVersion ? 0 : 1];
     lblCreatedDate.Text = m_draft.DateCreated.ToString();
 }
Example #13
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Removes the saved version for backups of any overwritten books if it is empty.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public void RemoveEmptyBackupSavedVersion()
 {
     if (m_savedVersion != null && m_savedVersion.BooksOS.Count == 0)
     {
         Debug.Assert(m_suppressor == null);
         m_scr.ArchivedDraftsOC.Remove(m_savedVersion);
         m_savedVersion = null;
     }
 }
Example #14
0
        /// <summary>
        /// This must be called before starting import.
        /// </summary>
        public void StartImportingFiles()
        {
            Debug.Assert(m_cache.DomainDataByFlid.GetActionHandler() != null);
            Debug.Assert(m_cache.DomainDataByFlid.GetActionHandler().CurrentDepth == 0);
            m_hMark = m_cache.DomainDataByFlid.GetActionHandler().Mark();
            IActionHandler actionHandler = m_cache.ActionHandlerAccessor;

            actionHandler.BeginUndoTask("Create saved version", "Create saved version");
            m_backupVersion = GetOrCreateVersion(TeResourceHelper.GetResourceString("kstidSavedVersionDescriptionOriginal"));
        }
Example #15
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Displays the imported books dialog box (virtual to allow tests to suppress display
 /// of dialog box).
 /// </summary>
 /// <param name="backupSavedVersion">The saved version for backups of any overwritten
 /// books.</param>
 /// ------------------------------------------------------------------------------------
 protected virtual void DisplayImportedBooksDlg(IScrDraft backupSavedVersion)
 {
     using (ImportedBooks dlg = new ImportedBooks(m_cache, m_styleSheet,
                                                  ImportedVersion, m_importCallbacks.DraftViewZoomPercent,
                                                  m_importCallbacks.FootnoteZoomPercent, backupSavedVersion, m_importCallbacks.BookFilter,
                                                  UndoManager.ImportedBooks.Keys, m_helpTopicProvider, m_app))
     {
         dlg.ShowOrSave(m_mainWnd, m_fParatextStreamlinedImport);
     }
 }
Example #16
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Undoes the entire import. Presumably there was either nothing in the file, or the
        /// user canceled during the first book.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void UndoEntireImport()
        {
            CollapseAllUndoActions();
            m_cache.ActionHandlerAccessor.Undo();
            m_importedSavedVersion = null;
            m_savedVersion         = null;

            // TODO (TE-4711): Undo any changes to the stylesheet and force application windows
            // to reload their stylesheets.
        }
Example #17
0
        /// --------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="T:ImportedBooks"/> class.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="importVersion">The ScrDraft containing the imported books.</param>
        /// <param name="backupVersion">where to store stuff overwritten or merged.</param>
        /// <param name="helpTopicProvider">The help topic provider.</param>
        /// <param name="app">The app.</param>
        /// --------------------------------------------------------------------------------
        protected ImportedBooks(LcmCache cache, IScrDraft importVersion, IScrDraft backupVersion,
                                IHelpTopicProvider helpTopicProvider, IApp app)
        {
            InitializeComponent();

            m_cache             = cache;
            m_helpTopicProvider = helpTopicProvider;
            m_app           = app;
            m_scr           = m_cache.LangProject.TranslatedScriptureOA;
            m_backupVersion = backupVersion;
            m_importVersion = importVersion;
        }
Example #18
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Removes the saved version for backups of any overwritten books if it is empty.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public void RemoveEmptyBackupSavedVersion()
 {
     if (m_backupVersion != null && m_backupVersion.IsValidObject && m_backupVersion.BooksOS.Count == 0)
     {
         using (UndoableUnitOfWorkHelper uow =
                    new UndoableUnitOfWorkHelper(m_cache.ActionHandlerAccessor, "Remove saved version"))
         {
             m_scr.ArchivedDraftsOC.Remove(m_backupVersion);
             uow.RollBack = false;
         }
         m_backupVersion = null;
     }
 }
Example #19
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets or creates an imported ScrDraft with the specified description.
        /// </summary>
        /// <param name="description">The description of the draft to get.</param>
        /// ------------------------------------------------------------------------------------
        private IScrDraft GetOrCreateVersion(string description)
        {
            IScrDraft draft = m_cache.ServiceLocator.GetInstance <IScrDraftRepository>().GetDraft(
                description, ScrDraftType.ImportedVersion);

            if (draft == null)
            {
                draft = m_cache.ServiceLocator.GetInstance <IScrDraftFactory>().Create(
                    description, ScrDraftType.ImportedVersion);
            }

            return(draft);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Called to make the test data for the tests
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void CreateTestData()
        {
            base.CreateTestData();

#pragma warning disable 219
            // We add a book (without a title)
            IScrBook genesis = AddBookToMockedScripture(1, "Genesis");
#pragma warning restore 219

            // And an archived book (with a title)
            IScrBook archiveBook = AddArchiveBookToMockedScripture(1, "Genesis");
            AddTitleToMockedBook(archiveBook, "Book of Genesis");
            m_importedVersion = (IScrDraft)archiveBook.Owner;
        }
Example #21
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Comparison method that compares the dates of two archive objects for the purpose of
        /// sorting them.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public int Compare(TreeNode obj1, TreeNode obj2)
        {
            IScrDraft archive1 = (IScrDraft)obj1.Tag;
            IScrDraft archive2 = (IScrDraft)obj2.Tag;

            if (m_ascending)
            {
                return(archive1.DateCreated.CompareTo(archive2.DateCreated));
            }
            else             // compare for descending order sort
            {
                return(archive2.DateCreated.CompareTo(archive1.DateCreated));
            }
        }
Example #22
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Make a label for an archive object.  This will include its date/time created
        /// and its description .
        /// </summary>
        /// <param name="archive">the saved version</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        private string GetSavedVersionLabel(IScrDraft archive)
        {
            string description;

            if (archive.Description == null)
            {
                description = DlgResources.ResourceString("kstidEmptyArchiveLabel");
            }
            else
            {
                description = archive.Description;
            }

            return(archive.DateCreated.ToString() + " " + description);
        }
Example #23
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Called to make the test data for the tests
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void CreateTestData()
        {
            base.CreateTestData();

            // We add a book (without a title)
            DummyScrBook genesis = new DummyScrBook(Cache,
                                                    m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis").Hvo);

            // And an archived book (with a title)
            DummyScrBook archiveBook = new DummyScrBook(Cache,
                                                        m_scrInMemoryCache.AddArchiveBookToMockedScripture(1, "Genesis").Hvo);

            m_scrInMemoryCache.AddTitleToMockedBook(archiveBook.Hvo, "Book of Genesis");
            m_importedVersion = new ScrDraft(Cache, archiveBook.OwnerHVO);
        }
Example #24
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handled the click event of the Properties context menu.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event
        /// data.</param>
        /// ------------------------------------------------------------------------------------
        private void propertiesClick(object sender, EventArgs e)
        {
            TreeNode node = m_treeArchives.SelectedNode;

            if (node != null && node.Tag is IScrDraft)
            {
                IScrDraft draft = node.Tag as IScrDraft;                 //JEH
                using (DraftPropertiesDialog dlg = new DraftPropertiesDialog())
                {
                    dlg.SetDialogInfo(draft);
                    if (dlg.ShowDialog(this) == DialogResult.OK)
                    {
                        node.Text = GetSavedVersionLabel(draft);
                    }
                }
            }
        }
Example #25
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:UndoImportInfo"/> class.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="bookFilter">The book filter.</param>
		/// ------------------------------------------------------------------------------------
		public UndoImportManager(FdoCache cache, FilteredScrBooks bookFilter)
		{
			m_cache = cache;
			m_bookFilter = bookFilter;
			m_scr = m_cache.LangProject.TranslatedScriptureOA;

			Debug.Assert(m_cache.ActionHandlerAccessor != null);
			Debug.Assert(m_cache.ActionHandlerAccessor.CurrentDepth == 0);
			m_hMark = m_cache.ActionHandlerAccessor.Mark();
			IActionHandler actionHandler = m_cache.ActionHandlerAccessor;
			m_suppressor = new SuppressSubTasks(m_cache); // don't need to undo setting properties.
			// Create new archive for saving backup versions of imported book
			m_savedVersion = new ScrDraft();
			m_scr.ArchivedDraftsOC.Add(m_savedVersion);
			actionHandler.AddAction(new UndoImportObjectAction(m_savedVersion));
			m_savedVersion.Description =
				TeResourceHelper.GetResourceString("kstidSavedVersionDescriptionOriginal");
		}
Example #26
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="T:UndoImportInfo"/> class.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="bookFilter">The book filter.</param>
        /// ------------------------------------------------------------------------------------
        public UndoImportManager(FdoCache cache, FilteredScrBooks bookFilter)
        {
            m_cache      = cache;
            m_bookFilter = bookFilter;
            m_scr        = m_cache.LangProject.TranslatedScriptureOA;

            Debug.Assert(m_cache.ActionHandlerAccessor != null);
            Debug.Assert(m_cache.ActionHandlerAccessor.CurrentDepth == 0);
            m_hMark = m_cache.ActionHandlerAccessor.Mark();
            IActionHandler actionHandler = m_cache.ActionHandlerAccessor;

            m_suppressor = new SuppressSubTasks(m_cache);             // don't need to undo setting properties.
            // Create new archive for saving backup versions of imported book
            m_savedVersion = new ScrDraft();
            m_scr.ArchivedDraftsOC.Add(m_savedVersion);
            actionHandler.AddAction(new UndoImportObjectAction(m_savedVersion));
            m_savedVersion.Description =
                TeResourceHelper.GetResourceString("kstidSavedVersionDescriptionOriginal");
        }
Example #27
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add a book to the imported saved version. If necessary, create the imported saved version,
        /// and set up an UndoAction so it will be deleted if we Undo. Set or update the description
        /// of the saved version as necessary.
        /// </summary>
        /// <param name="nCanonicalBookNumber"></param>
        /// <param name="description"></param>
        /// <param name="hvoTitle"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        private IScrBook AddBookToImportedSavedVersion(int nCanonicalBookNumber, string description,
                                                       out int hvoTitle)
        {
            IActionHandler actionHandler = SetCurrentBookInternal(nCanonicalBookNumber);

            Debug.Assert(nCanonicalBookNumber > 0);
            if (m_importedSavedVersion == null)
            {
                m_importedSavedVersion = new ScrDraft();
                m_scr.ArchivedDraftsOC.Add(m_importedSavedVersion);
                m_importedSavedVersion.Type = ScrDraftType.ImportedVersion;
                actionHandler.AddAction(new UndoImportObjectAction(m_importedSavedVersion));
            }
            m_importedSavedVersion.Description = description;

            int iBook = 0;

            foreach (IScrBook existingBook in m_importedSavedVersion.BooksOS)
            {
                if (existingBook.CanonicalNum == nCanonicalBookNumber)
                {
                    // For some reason, typically reading multiple independent SF files, we've been
                    // asked to create a book we already have. Just return it.
                    hvoTitle = existingBook.TitleOAHvo;
                    return(existingBook);
                }
                if (existingBook.CanonicalNum > nCanonicalBookNumber)
                {
                    break;
                }
                iBook++;
            }

            IScrBook newScrBook = new ScrBook();

            m_importedSavedVersion.BooksOS.InsertAt(newScrBook, iBook);
            newScrBook.CanonicalNum = nCanonicalBookNumber;
            newScrBook.BookIdRAHvo  = m_scr.Cache.ScriptureReferenceSystem.BooksOS.HvoArray[nCanonicalBookNumber - 1];
            newScrBook.TitleOA      = new StText();
            hvoTitle = newScrBook.TitleOAHvo;
            actionHandler.AddAction(new UndoImportObjectAction(newScrBook));
            return(newScrBook);
        }
Example #28
0
        public void MoveTo_EmptyListTest()
        {
            IFdoServiceLocator servLoc  = Cache.ServiceLocator;
            IScrBookFactory    bookFact = servLoc.GetInstance <IScrBookFactory>();

            // Setup the source sequence using the scripture books sequence.
            IScrBook book0 = bookFact.Create(1);
            IScrBook book1 = bookFact.Create(2);
            IScrBook book2 = bookFact.Create(3);

            // Setup the target sequence so it's able to have items moved to it.
            IScrDraft targetSeq = servLoc.GetInstance <IScrDraftFactory>().Create("MoveTo_EmptyListTest");

            m_scr.ScriptureBooksOS.MoveTo(1, 2, targetSeq.BooksOS, 0);

            Assert.AreEqual(2, targetSeq.BooksOS.Count);
            Assert.AreEqual(1, m_scr.ScriptureBooksOS.Count);
            Assert.AreEqual(book1, targetSeq.BooksOS[0]);
            Assert.AreEqual(book2, targetSeq.BooksOS[1]);
        }
Example #29
0
        public void MoveTo_DestListLargerThenSrcTest()
        {
            IFdoServiceLocator servLoc  = Cache.ServiceLocator;
            IScrBookFactory    bookFact = servLoc.GetInstance <IScrBookFactory>();

            // Setup the source sequence using the scripture books sequence.
            IScrBook book0 = bookFact.Create(1);

            // Setup the target sequence so it's able to have items moved to it.
            IScrDraft targetSeq = servLoc.GetInstance <IScrDraftFactory>().Create("MoveTo_DestListLargerThenSrcTest");
            IScrBook  bookD0    = bookFact.Create(targetSeq.BooksOS, 1);
            IScrBook  bookD1    = bookFact.Create(targetSeq.BooksOS, 2);

            m_scr.ScriptureBooksOS.MoveTo(0, 0, targetSeq.BooksOS, 2);

            Assert.AreEqual(3, targetSeq.BooksOS.Count);
            Assert.AreEqual(0, m_scr.ScriptureBooksOS.Count);
            Assert.AreEqual(bookD0, targetSeq.BooksOS[0]);
            Assert.AreEqual(bookD1, targetSeq.BooksOS[1]);
            Assert.AreEqual(book0, targetSeq.BooksOS[2]);
        }
Example #30
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// User clicked OK button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        private void OnOk(object sender, System.EventArgs e)
        {
            using (new WaitCursor(this))
            {
                StepThroughNodesAndAddToList(m_treeView.Nodes[0]);
                if (m_BooksToSave.Count == 0)
                {
                    Close();
                    return;
                }

                using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(
                           m_cache.ServiceLocator.GetInstance <IActionHandler>()))
                {
                    m_SavedVersion = m_cache.ServiceLocator.GetInstance <IScrDraftFactory>().Create(
                        m_description.Text, m_BooksToSave);
                    undoHelper.RollBack = false;
                }
                Close();
            }
        }
Example #31
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="DummyImportedBooks"/> class.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="booksImported">The books that have been imported.</param>
		/// <param name="backupVersion">where to store stuff overwritten or merged.</param>
		/// ------------------------------------------------------------------------------------
		public DummyImportedBooks(FdoCache cache, IScrDraft booksImported,
			IScrDraft backupVersion) : base(cache, booksImported, backupVersion)
		{
		}
Example #32
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="ImportedBooks"/> class.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="booksImported">The books that have been imported.</param>
		/// <param name="backupVersion">where to store stuff overwritten or merged.</param>
		/// ------------------------------------------------------------------------------------
		protected ImportedBooks(FdoCache cache, IScrDraft booksImported, IScrDraft backupVersion)
		{
			InitializeComponent();

			m_cache = cache;
			m_scr = m_cache.LangProject.TranslatedScriptureOA as Scripture;
			m_backupVersion = backupVersion;
			m_booksImported = booksImported;
		}
Example #33
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="ImportedBooks"/> class.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="styleSheet">The style sheet.</param>
		/// <param name="booksImported">The books that have been imported.</param>
		/// <param name="zoomPercentageDraft">The zoom percentage of the draft view.</param>
		/// <param name="zoomPercentageFootnote">The zoom percentage of the footnote view.</param>
		/// <param name="backupVersion">where to store stuff overwritten or merged.</param>
		/// <param name="bookFilter">bookFilter to which to add new books</param>
		/// ------------------------------------------------------------------------------------
		public ImportedBooks(FdoCache cache, FwStyleSheet styleSheet,
			IScrDraft booksImported, float zoomPercentageDraft, float zoomPercentageFootnote,
			IScrDraft backupVersion, FilteredScrBooks bookFilter) :
			this(cache, booksImported, backupVersion)
		{
			m_styleSheet = styleSheet;
			m_zoomPercentageDraft = zoomPercentageDraft;
			m_zoomPercentageFootnote = zoomPercentageFootnote;
			m_bookFilter = bookFilter;

			foreach (IScrBook rev in booksImported.BooksOS)
			{
				ListViewItem item = new ListViewItem(
					new string[] {rev.Name.UserDefaultWritingSystem, GetBookInfo(rev)});
				item.SubItems.Add(DlgResources.ResourceString("kstidUnknown"));

				IScrBook curBook = m_scr.FindBook(rev.CanonicalNum);
				if (curBook == null)
				{
					SetItemStatus(item, ImportedBookStatus.New);
					int newBookHvo = m_scr.CopyBookToCurrent(rev);
					m_newBooks.Add(newBookHvo);
				}
				else
					item.Tag = new BookMerger(m_cache, styleSheet, rev);
				lstImportedBooks.Items.Add(item);
			}
			lstImportedBooks.Items[0].Selected = true;
		}
Example #34
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// User clicked OK button
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// ------------------------------------------------------------------------------------
		private void OnOk(object sender, System.EventArgs e)
		{
			using (new WaitCursor(this))
			{
				StepThroughNodesAndAddToList(m_treeView.Nodes[0]);
				if (m_BooksToSave.Count == 0)
				{
					Close();
					return;
				}

				using (new SuppressSubTasks(m_cache))
				{
					string sSavePoint;
					m_cache.DatabaseAccessor.SetSavePointOrBeginTrans(out sSavePoint);
					try
					{
						m_SavedVersion = m_scr.CreateSavedVersion(m_description.Text,
							m_BooksToSave.ToArray());
						m_cache.DatabaseAccessor.CommitTrans();
					}
					catch
					{
						m_cache.DatabaseAccessor.RollbackSavePoint(sSavePoint);
						throw;
					}
					finally
					{
						Close();
					}
				}
			}
		}
Example #35
0
		/// --------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:ImportedBooks"/> class.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="importVersion">The ScrDraft containing the imported books.</param>
		/// <param name="backupVersion">where to store stuff overwritten or merged.</param>
		/// <param name="helpTopicProvider">The help topic provider.</param>
		/// <param name="app">The app.</param>
		/// --------------------------------------------------------------------------------
		protected ImportedBooks(FdoCache cache, IScrDraft importVersion, IScrDraft backupVersion,
			IHelpTopicProvider helpTopicProvider, IApp app)
		{
			InitializeComponent();

			m_cache = cache;
			m_helpTopicProvider = helpTopicProvider;
			m_app = app;
			m_scr = m_cache.LangProject.TranslatedScriptureOA;
			m_backupVersion = backupVersion;
			m_importVersion = importVersion;
		}
Example #36
0
        public void DeleteBook()
        {
            using (DummySavedVersionsDialog dlg = new DummySavedVersionsDialog(Cache))
            {
                TreeView tree = dlg.ArchiveTree;

                // Delete the first book from the last archive (Philemon)
                TreeNode archiveNode = null;
                for (int i = 0; i < tree.Nodes.Count; i++)
                {
                    if (tree.Nodes[i].Text.IndexOf("My Archive 2") != -1)
                    {
                        archiveNode = tree.Nodes[i];
                        break;
                    }
                }
                tree.SelectedNode = archiveNode.Nodes[0];
                dlg.SimulateDelete();

                // check the node counts
                Assert.AreEqual(3, tree.Nodes.Count);
                for (int i = 0; i < tree.Nodes.Count; i++)
                {
                    if (tree.Nodes[i].Text.IndexOf("My Archive 0") != -1)
                    {
                        Assert.AreEqual(1, tree.Nodes[i].Nodes.Count);
                    }
                    else if (tree.Nodes[i].Text.IndexOf("My Archive 1") != -1)
                    {
                        Assert.AreEqual(2, tree.Nodes[i].Nodes.Count);
                    }
                    else if (tree.Nodes[i].Text.IndexOf("My Archive 2") != -1)
                    {
                        Assert.AreEqual(2, tree.Nodes[i].Nodes.Count);
                    }
                    else
                    {
                        Assert.Fail("Seems we have an extra archive");
                    }
                }

                // Check the remaining book names for the archive that was deleted from.
                for (int i = 0; i < 2; i++)
                {
                    string bookLabel = archiveNode.Nodes[i].Text;
                    Assert.AreEqual(m_bookScrRange[i + 1], bookLabel);
                }

                // Check the books in the database to make sure the database is correct.
                Assert.AreEqual(3, m_scr.ArchivedDraftsOC.Count);
                IScrDraft archive = (IScrDraft)archiveNode.Tag;
                Assert.AreEqual(2, archive.BooksOS.Count);
                List <int> cannonicalBookNums = new List <int>(new int[] { 59, 65 });
                for (int iArchivedBook = 0; iArchivedBook < archive.BooksOS.Count; iArchivedBook++)
                {
                    IScrBook book = archive.BooksOS[iArchivedBook];
                    Assert.AreEqual(cannonicalBookNums[iArchivedBook], book.CanonicalNum);
                    Assert.AreEqual(m_bookNames[iArchivedBook + 1], book.BestUIName);
                }
            }
        }
Example #37
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initialize the FDO cache and open database
		/// </summary>
		/// <remarks>This method is called before each test</remarks>
		/// ------------------------------------------------------------------------------------
		public override void TestSetup()
		{
			base.TestSetup();
			m_savedVersion = Cache.ServiceLocator.GetInstance<IScrDraftFactory>().Create("ImportedBooksTests");
		}
Example #38
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initialize the FDO cache and open database
		/// </summary>
		/// <remarks>This method is called before each test</remarks>
		/// ------------------------------------------------------------------------------------
		public override void Initialize()
		{
			base.Initialize();
			m_inMemoryCache.InitializeWritingSystemEncodings();
			m_savedVersion = new ScrDraft();
			m_scr.ArchivedDraftsOC.Add(m_savedVersion);
		}
Example #39
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Overrides DisplayImportedBooksDlg for testing.
		/// </summary>
		/// <param name="backupSavedVersion">The saved version for backups of any overwritten
		/// books.</param>
		/// ------------------------------------------------------------------------------------
		protected override void DisplayImportedBooksDlg(IScrDraft backupSavedVersion)
		{
			m_cDisplayImportedBooksDlgCalled++;
			if (m_fSimulateAcceptAllBooks)
			{
				DummyImportedBooks dlg = new DummyImportedBooks(m_cache, ImportedSavedVersion, backupSavedVersion);
				dlg.AcceptAllImportedBooks();
			}
			//else if (m_fSimulateDeleteAllBooks)
			//{
			//    DummyImportedBooks dlg = new DummyImportedBooks(m_cache, ImportedSavedVersion, backupSavedVersion);
			//    dlg.DeleteAllImportedBooks();
			//}
		}
Example #40
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Called to make the test data for the tests
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void CreateTestData()
		{
			base.CreateTestData();

			// We add a book (without a title)
			DummyScrBook genesis = new DummyScrBook(Cache,
				m_scrInMemoryCache.AddBookToMockedScripture(1, "Genesis").Hvo);

			// And an archived book (with a title)
			DummyScrBook archiveBook = new DummyScrBook(Cache,
				m_scrInMemoryCache.AddArchiveBookToMockedScripture(1, "Genesis").Hvo);
			m_scrInMemoryCache.AddTitleToMockedBook(archiveBook.Hvo, "Book of Genesis");
			m_importedVersion = new ScrDraft(Cache, archiveBook.OwnerHVO);
		}
Example #41
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Called to make the test data for the tests
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void CreateTestData()
		{
			base.CreateTestData();

#pragma warning disable 219
			// We add a book (without a title)
			IScrBook genesis = AddBookToMockedScripture(1, "Genesis");
#pragma warning restore 219

			// And an archived book (with a title)
			IScrBook archiveBook = AddArchiveBookToMockedScripture(1, "Genesis");
			AddTitleToMockedBook(archiveBook, "Book of Genesis");
			m_importedVersion = (IScrDraft)archiveBook.Owner;
		}
Example #42
0
		/// ------------------------------------------------------------------------------------
		/// <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;
				}
			}
		}
Example #43
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add book to the specified saved version.
		/// </summary>
		/// <param name="version">The saved version</param>
		/// <param name="hvoBook">HVO of book to add</param>
		/// <returns>The HVO of the saved version of the book</returns>
		/// ------------------------------------------------------------------------------------
		public int AddBookToSavedVersion(IScrDraft version, int hvoBook)
		{
			return AddBookToSavedVersion(version, new ScrBook(Cache, hvoBook));
		}
Example #44
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Add book to the specified saved version.
		/// </summary>
		/// <param name="version">The saved version</param>
		/// <param name="book">book to add</param>
		/// <exception cref="InvalidOperationException">Saved version already contains a copy of
		/// the specified book</exception>
		/// <returns>The HVO of the saved version of the book</returns>
		/// ------------------------------------------------------------------------------------
		public int AddBookToSavedVersion(IScrDraft version, IScrBook book)
		{
			Debug.Assert(version != null);
			if (version.FindBook(book.CanonicalNum) != null)
			{
				throw new InvalidOperationException("Saved version already contains a copy of " +
					book.BookId);
			}
			// Find the first book whose canonical number is greater than the one we're copying
			// in. The copied book should be inserted before that one.
			int hvoDstStart = GetBookFollowing(version.BooksOS, book.CanonicalNum);
			Logger.WriteEvent("Copying book " + book.CanonicalNum + " to saved version");
			int hvoArchivedBook = m_cache.CopyObject(book.Hvo, version.Hvo,
				(int)ScrDraft.ScrDraftTags.kflidBooks, hvoDstStart);

			Logger.WriteEvent("Adjusting objects in book " + book.CanonicalNum);
			AdjustObjectsInArchivedBook(book.Hvo, hvoArchivedBook);
			Logger.WriteEvent("Copying Free Translation for book " + book.CanonicalNum);
			CopyFreeTranslations(book, CmObject.CreateFromDBObject(book.Cache, hvoArchivedBook) as ScrBook);
			Logger.WriteEvent("Completed copy for " + book.CanonicalNum);
			return hvoArchivedBook;
		}
Example #45
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Displays the imported books dialog box (virtual to allow tests to suppress display
		/// of dialog box).
		/// </summary>
		/// <param name="backupSavedVersion">The saved version for backups of any overwritten
		/// books.</param>
		/// ------------------------------------------------------------------------------------
		protected virtual void DisplayImportedBooksDlg(IScrDraft backupSavedVersion)
		{
			using (ImportedBooks dlg = new ImportedBooks(m_cache, m_styleSheet,
				ImportedVersion, m_importCallbacks.DraftViewZoomPercent,
				m_importCallbacks.FootnoteZoomPercent, backupSavedVersion, m_importCallbacks.BookFilter,
				UndoManager.ImportedBooks.Keys, m_helpTopicProvider, m_app))
			{
				dlg.ShowOrSave(m_mainWnd, m_fParatextStreamlinedImport);
			}
		}
Example #46
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Actually does the import, really.
        /// </summary>
        /// <param name="importSettings">The import settings.</param>
        /// <param name="fDisplayUi">if set to <c>true</c> shows the UI.</param>
        /// <returns>The first reference that was imported</returns>
        /// ------------------------------------------------------------------------------------
        private ScrReference InternalImport(IScrImportSet importSettings, bool fDisplayUi)
        {
            ScrReference firstImported = ScrReference.Empty;

            using (new IgnorePropChanged(m_cache))
            {
                bool fRollbackPartialBook = false;
                bool fPartialBtImported   = false;
                try
                {
                    Logger.WriteEvent("Starting import");
                    using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(m_mainWnd))
                    {
                        progressDlg.CancelButtonText =
                            TeResourceHelper.GetResourceString("kstidStopImporting");
                        progressDlg.Title =
                            TeResourceHelper.GetResourceString("kstidImportProgressCaption");
                        progressDlg.StatusMessage =
                            TeResourceHelper.GetResourceString("kstidImportInitializing");
                        if (importSettings == null)                             // XML (OXES) import
                        {
                            progressDlg.ProgressBarStyle = ProgressBarStyle.Continuous;
                        }

                        TeImportUi importUi = CreateTeImportUi(progressDlg);
#if DEBUG_SINGLE_THREADED
                        if (importSettings != null)
                        {
                            firstImported = (ScrReference)progressDlg.RunTask_DebuggingOnly(fDisplayUi,
                                                                                            new BackgroundTaskInvoker(Import),
                                                                                            importSettings, undoImportManager, importUi);
                        }
                        else
                        {
                            firstImported = (ScrReference)progressDlg.RunTask_DebuggingOnly(fDisplayUi,
                                                                                            new BackgroundTaskInvoker(ImportXml),
                                                                                            undoImportManager, importUi);
                        }
#else
                        if (importSettings != null)
                        {
                            firstImported = (ScrReference)progressDlg.RunTask(fDisplayUi,
                                                                              new BackgroundTaskInvoker(ImportSf), importSettings,
                                                                              m_undoImportManager, importUi);
                        }
                        else
                        {
                            firstImported = (ScrReference)progressDlg.RunTask(fDisplayUi,
                                                                              new BackgroundTaskInvoker(ImportXml),
                                                                              m_undoImportManager, importUi);
                        }
#endif
                    }
                }
                catch (WorkerThreadException e)
                {
                    if (e.InnerException is ScriptureUtilsException)
                    {
                        ScriptureUtilsException se = e.InnerException as ScriptureUtilsException;
                        if (FwApp.App != null)
                        {
                            string sCaption = ScriptureUtilsException.GetResourceString(
                                se.IsBackTransError ? "kstidBTImportErrorCaption" : "kstidImportErrorCaption");
                            MessageBox.Show(m_mainWnd, se.Message, sCaption, MessageBoxButtons.OK,
                                            MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, FwApp.App.HelpFile,
                                            HelpNavigator.Topic, se.HelpTopic);
                        }
                        if (se.IsBackTransError && !se.InterleavedImport)
                        {
                            fPartialBtImported = true;
                        }
                        else
                        {
                            fRollbackPartialBook = true;
                        }
                    }
                    else if (e.InnerException is ParatextLoadException)
                    {
                        if (FwApp.App != null)
                        {
                            string        sCaption = ScriptureUtilsException.GetResourceString("kstidImportErrorCaption");
                            Exception     innerE   = e.InnerException;
                            StringBuilder sbMsg    = new StringBuilder(innerE.Message);
                            while (innerE.InnerException != null)
                            {
                                innerE = innerE.InnerException;
                                sbMsg.Append("\r");
                                sbMsg.Append(innerE.Message);
                            }

                            MessageBox.Show(m_mainWnd, sbMsg.ToString(), sCaption, MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }
                        fRollbackPartialBook = true;
                    }
                    else if (e.InnerException is CancelException)
                    {
                        // User cancelled import in the middle of a book
                        fRollbackPartialBook = true;
                    }
                    else
                    {
                        m_undoImportManager.DoneImportingFiles(true);
                        m_undoImportManager.CollapseAllUndoActions();
                        throw;
                    }
                }
                finally
                {
                    m_importedSavedVersion = m_undoImportManager.ImportedSavedVersion;
                    Logger.WriteEvent("Finished importing");
                }
                m_undoImportManager.DoneImportingFiles(fRollbackPartialBook);
                if (m_importedSavedVersion != null && m_importedSavedVersion.BooksOS.Count == 0 &&
                    !fPartialBtImported)
                {
                    // Either there was nothing in the file, or the user canceled during the first book.
                    // In any case, we didn't get any books, so whatever has been done should be undone.
                    m_undoImportManager.UndoEntireImport();
                    m_importedSavedVersion = null;
                    return(null);
                }
            }
            return(firstImported);
        }
Example #47
0
			/// --------------------------------------------------------------------------------
			/// <summary>
			/// Initializes a new instance of the <see cref="DummyImportedBooks"/> class.
			/// </summary>
			/// <param name="cache">The cache.</param>
			/// <param name="booksImported">The books imported.</param>
			/// <param name="backupVersion">The backup version.</param>
			/// --------------------------------------------------------------------------------
			public DummyImportedBooks(FdoCache cache, IScrDraft booksImported,
				IScrDraft backupVersion) : base(cache, null, booksImported, 1.0f, 1.0f,
				backupVersion, new FilteredScrBooks(cache, 987))
			{
			}
Example #48
0
		/// <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>
 /// Initialize the FDO cache and open database
 /// </summary>
 /// <remarks>This method is called before each test</remarks>
 /// ------------------------------------------------------------------------------------
 public override void TestSetup()
 {
     base.TestSetup();
     m_savedVersion = Cache.ServiceLocator.GetInstance <IScrDraftFactory>().Create("ImportedBooksTests");
 }
Example #50
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Removes the saved version for backups of any overwritten books if it is empty.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public void RemoveEmptyBackupSavedVersion()
		{
			if (m_backupVersion != null && m_backupVersion.IsValidObject && m_backupVersion.BooksOS.Count == 0)
			{
				using (UndoableUnitOfWorkHelper uow =
					new UndoableUnitOfWorkHelper(m_cache.ActionHandlerAccessor, "Remove saved version"))
				{
					m_scr.ArchivedDraftsOC.Remove(m_backupVersion);
					uow.RollBack = false;
				}
				m_backupVersion = null;
			}
		}
Example #51
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds the new book (to the saved version...create it if need be) for which the
		/// vernacular is about to be imported.
		/// </summary>
		/// <param name="nCanonicalBookNumber">The canonical book number.</param>
		/// <param name="description">Description to use for the newly created imported version
		/// if necessary.</param>
		/// <param name="title">The title of the newly created book.</param>
		/// <returns>The newly created book (which has been added to the imported version)</returns>
		/// ------------------------------------------------------------------------------------
		public IScrBook AddNewBook(int nCanonicalBookNumber, string description, out IStText title)
		{
			if (m_importedVersion == null)
				m_importedVersion = GetOrCreateVersion(description);
			IScrBook existingBook = SetCurrentBook(nCanonicalBookNumber, true);

			if (existingBook != null)
			{
				if (m_lastBookAddedToImportedBooks == 0)
				{
					// We've been asked to create a book we have already imported (typically
					// reading multiple independent SF files).
					title = existingBook.TitleOA;
					return existingBook;
				}

				// Replace any previous book with the one we're about to import.
				m_importedVersion.BooksOS.Remove(existingBook);
			}

			IScrBook newScrBook = m_cache.ServiceLocator.GetInstance<IScrBookFactory>().Create(m_importedVersion.BooksOS,
				nCanonicalBookNumber, out title);
			return newScrBook;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Overrides DisplayImportedBooksDlg for testing.
		/// </summary>
		/// <param name="backupSavedVersion">The saved version for backups of any overwritten
		/// books.</param>
		/// ------------------------------------------------------------------------------------
		protected override void DisplayImportedBooksDlg(IScrDraft backupSavedVersion)
		{
			m_cDisplayImportedBooksDlgCalled++;
			if (m_fSimulateAcceptAllBooks)
			{
				using (DummyImportedBooks dlg = new DummyImportedBooks(Cache, ImportedVersion, backupSavedVersion))
					dlg.AcceptAllImportedBooks();
			}
		}
Example #53
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Undoes the entire import. Presumably there was either nothing in the file, or the
		/// user canceled during the first book.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public void UndoEntireImport()
		{
			if (CollapseAllUndoActions())
				m_cache.ActionHandlerAccessor.Undo();
			m_importedBooks.Clear();
			m_importedVersion = null;
			m_backupVersion = null;

			// TODO (TE-4711): Undo any changes to the stylesheet and force application windows
			// to reload their stylesheets.
		}
Example #54
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// When dialog closes, finish up the pending stuff.
		/// </summary>
		/// <param name="e">The <see cref="T:System.EventArgs"/> that contains the event data.</param>
		/// ------------------------------------------------------------------------------------
		protected override void OnClosed(EventArgs e)
		{
			using (new WaitCursor(this))
			{
				// User should not see undo tasks, so the strings don't need to be localized.
				UndoableUnitOfWorkHelper.Do("Remove empty", "Remove empty",
					m_cache.ServiceLocator.GetInstance<IActionHandler>(), () =>
				{
					// Enhance JohnT: Normally we would make sure all these changes were a single Undo action,
					// but for now we know this is part of a still larger Undoable task, the whole import.
					// CollapseToMark is used to convert them all into one.

					if (m_bookFilter != null)
					{
						// Insert any new books into bookfilter that need to be visible
						m_bookFilter.Add(m_newBooks);
						UndoChangeFilter undoItem = new UndoChangeFilter(m_bookFilter, m_newBooks, m_overwrittenBooks);
						m_cache.ActionHandlerAccessor.AddAction(undoItem);
					}

					// Delete empty revisions created for this import.
					//if (m_booksImported.BooksOS.Count == 0)
					//    m_booksImported.DeleteUnderlyingObject();
					if (m_backupVersion.BooksOS.Count == 0)
					{
						m_scr.ArchivedDraftsOC.Remove(m_backupVersion);
						m_backupVersion = null;
					}
				});

				if (e != null)
					base.OnClosed(e);
			}
		}
Example #55
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Overrides DisplayImportedBooksDlg for testing - just accepts .
		/// </summary>
		/// <param name="backupSavedVersion">The saved version for backups of any overwritten
		/// books.</param>
		/// ------------------------------------------------------------------------------------
		protected override void DisplayImportedBooksDlg(IScrDraft backupSavedVersion)
		{
			DummyImportedBooks dlg = new DummyImportedBooks(m_cache, ImportedSavedVersion, backupSavedVersion);
			dlg.AcceptAllImportedBooks();
		}
Example #56
0
			/// --------------------------------------------------------------------------------
			/// <summary>
			/// Initializes a new instance of the <see cref="DummyImportedBooks"/> class.
			/// </summary>
			/// <param name="cache">The cache.</param>
			/// <param name="booksImported">The books imported.</param>
			/// <param name="backupVersion">The backup version.</param>
			/// --------------------------------------------------------------------------------
			public DummyImportedBooks(FdoCache cache, IScrDraft booksImported,
				IScrDraft backupVersion) : base(cache, null, booksImported, 1.0f, 1.0f,
				backupVersion, cache.ServiceLocator.GetInstance<IFilteredScrBookRepository>().GetFilterInstance(987),
				new Set<int>(booksImported.BooksOS.Select(b => b.CanonicalNum)), null, null)
			{
			}
 /// --------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="DummyImportedBooks"/> class.
 /// </summary>
 /// <param name="cache">The cache.</param>
 /// <param name="booksImported">The books imported.</param>
 /// <param name="backupVersion">The backup version.</param>
 /// --------------------------------------------------------------------------------
 public DummyImportedBooks(FdoCache cache, IScrDraft booksImported,
                           IScrDraft backupVersion) : base(cache, null, booksImported, 1.0f, 1.0f,
                                                           backupVersion, cache.ServiceLocator.GetInstance <IFilteredScrBookRepository>().GetFilterInstance(987),
                                                           new Set <int>(booksImported.BooksOS.Select(b => b.CanonicalNum)), null, null)
 {
 }
Example #58
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// User clicked OK button
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// ------------------------------------------------------------------------------------
		private void OnOk(object sender, System.EventArgs e)
		{
			using (new WaitCursor(this))
			{
				StepThroughNodesAndAddToList(m_treeView.Nodes[0]);
				if (m_BooksToSave.Count == 0)
				{
					Close();
					return;
				}

				using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(
					m_cache.ServiceLocator.GetInstance<IActionHandler>()))
				{
					m_SavedVersion = m_cache.ServiceLocator.GetInstance<IScrDraftFactory>().Create(
						m_description.Text, m_BooksToSave);
					undoHelper.RollBack = false;
				}
				Close();
			}
		}
Example #59
0
		/// --------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:ImportedBooks"/> class.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="styleSheet">The style sheet.</param>
		/// <param name="importVersion">The ScrDraft containing the imported books.</param>
		/// <param name="zoomPercentageDraft">The zoom percentage of the draft view.</param>
		/// <param name="zoomPercentageFootnote">The zoom percentage of the footnote view.</param>
		/// <param name="backupVersion">where to store stuff overwritten or merged.</param>
		/// <param name="bookFilter">bookFilter to which to add new books</param>
		/// <param name="booksImported">The canonical numbers of the books which were
		/// imported (unordered).</param>
		/// <param name="helpTopicProvider">The help topic provider.</param>
		/// <param name="app">The application.</param>
		/// --------------------------------------------------------------------------------
		public ImportedBooks(FdoCache cache, FwStyleSheet styleSheet,
			IScrDraft importVersion, float zoomPercentageDraft, float zoomPercentageFootnote,
			IScrDraft backupVersion, FilteredScrBooks bookFilter, IEnumerable<int> booksImported,
			IHelpTopicProvider helpTopicProvider, IApp app) :
			this(cache, importVersion, backupVersion, helpTopicProvider, app)
		{
			m_styleSheet = styleSheet;
			m_zoomPercentageDraft = zoomPercentageDraft;
			m_zoomPercentageFootnote = zoomPercentageFootnote;
			m_bookFilter = bookFilter;

			foreach (int bookId in booksImported)
			{
				IScrBook rev = importVersion.FindBook(bookId);

				ListViewItem item = new ListViewItem(
					new string[] {rev.Name.UserDefaultWritingSystem.Text, GetBookInfo(rev)});
				item.SubItems.Add(DlgResources.ResourceString("kstidUnknown"));

				IScrBook curBook = m_scr.FindBook(rev.CanonicalNum);
				if (curBook == null)
				{
					SetItemStatus(item, ImportedBookStatus.New);
					// User should not see this undo task so we don't need to localize the strings.
					UndoableUnitOfWorkHelper.Do("Add book", "Add book",
						m_cache.ServiceLocator.GetInstance<IActionHandler>(), () =>
					{
						m_newBooks.Add(m_scr.CopyBookToCurrent(rev));
					});
				}
				else
					item.Tag = new BookMerger(m_cache, styleSheet, rev);
				lstImportedBooks.Items.Add(item);
			}
			lstImportedBooks.Items[0].Selected = true;
		}
Example #60
0
		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;
		}