Esempio n. 1
0
        /// <summary>
        /// This method should be used any time the user takes an action that would result in marking a book
        /// for inclusion in the project. (It does not need to be called when a book is being removed.)
        /// Currently, this can be either when they click a check-box for an individual book or when they use one of
        /// the "select all" menu items. There are several quick-return paths, but in the "interesting" case,
        /// the purpose of this method is to check whether the book in question is currently in a state (as reported
        /// by Paratext) where the required basic checks all pass. If not, the user needs to confirm that they indeed
        /// wish to include the book and thus override this requirement.
        /// </summary>
        /// <param name="grid">Either the OT grid or the NT grid</param>
        /// <param name="rowIndex">The row index in the grid also corresponds to an entry in the available OT or
        /// NT books list.</param>
        /// <returns></returns>
        private bool IsValidToIncludeBook(DataGridView grid, int rowIndex)
        {
            if (!m_project.IsLiveParatextProject)
            {
                return(true);
            }
            var books = grid.Equals(m_otBooksGrid) ? m_availableOtBooks : m_availableNtBooks;
            var book  = books[rowIndex];

            if (book.IncludeInScript)
            {
                return(true);                // Always valid to exclude
            }
            var bookCode = book.Code;

            if (m_project.DoesBookScriptFileExist(bookCode))
            {
                return(true);                // Might try to get an updated version later but this one is valid.
            }
            GetParatextScrTextWrapperIfNeeded();
            var bookNum = Canon.BookIdToNumber(bookCode);

            if (!m_paratextScrTextWrapper.CanonicalBookNumbersInProject.Contains(bookNum))
            {
                ReportParatextBookNoLongerAvailable(bookCode);
                grid.CurrentRow.DefaultCellStyle.ForeColor = GlyssenColorPalette.ColorScheme.Warning;
                return(false);
            }
            else if (grid.CurrentRow.DefaultCellStyle.ForeColor == GlyssenColorPalette.ColorScheme.Warning)
            {
                grid.CurrentRow.DefaultCellStyle.ForeColor = grid.DefaultCellStyle.ForeColor;
            }

            if (m_paratextScrTextWrapper.DoesBookPassChecks(bookNum, true))
            {
                return(true);
            }

            var failureMessage = Format(LocalizationManager.GetString("DialogBoxes.ScriptureRangeSelectionDlg.FailedChecksForBook",
                                                                      "{0} is not reporting a current successful status for {1} in project {2} for the following basic checks " +
                                                                      "that {3} usually requires to pass:\r\n{4}",
                                                                      "Param 0: \")Paratext\" (product name); " +
                                                                      "Param 1: 3-letter Scripture book code; " +
                                                                      "Param 2: Paratext project short name (unique project identifier); " +
                                                                      "Param 3: \"Glyssen\" (product name); " +
                                                                      "Param 4: List of failing Paratext check names"),
                                        ParatextScrTextWrapper.kParatextProgramName,
                                        bookCode,
                                        m_project.ParatextProjectName,
                                        GlyssenInfo.kProduct,
                                        Join(", ", m_paratextScrTextWrapper.GetCheckFailuresForBook(bookCode)));

            var msg = failureMessage + Environment.NewLine + Environment.NewLine +
                      Format(LocalizationManager.GetString("DialogBoxes.ScriptureRangeSelectionDlg.ConfirmInclusionOfParatextBookThatDoesNotPassChecks",
                                                           "Depending on the specific errors, {0} might fail to process the data for this book properly, which could " +
                                                           "give the appearance of data loss or corruption and could even cause {0} to stop responding. " +
                                                           "Do you want to include this book in the {1} project anyway?",
                                                           "Param 0: \"Glyssen\" (product name); " +
                                                           "Param 1: Glyssen recording project name"),
                             GlyssenInfo.kProduct,
                             m_project.Name);

            if (DialogResult.No == MessageBox.Show(this, msg, GlyssenInfo.kProduct, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation))
            {
                return(false);
            }
            Logger.WriteEvent($"Including book {bookCode} even though " + failureMessage);
            return(true);
        }