Esempio n. 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the next paratext segment for import.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void GetNextParatextSegment(out string sText, out string sMarker)
        {
            sMarker = null;
            sText   = string.Empty;
            while (m_ptCurrentToken < m_ptBookTokens.Count())
            {
                IUsfmToken token = m_ptBookTokens[m_ptCurrentToken];
                if (token.Type == TokenType.Text)
                {
                    sText += token.Text;
                }
                else
                {
                    if (sMarker != null)
                    {
                        break;                         // Found another marker so we got all the text for this one
                    }
                    sMarker = @"\" + token.Marker;     // We expect the marker to have the slash
                }
                m_ptParserState.UpdateState(m_ptBookTokens, m_ptCurrentToken);

                if (!ScrImportFileInfo.IsValidMarker(sMarker))
                {
                    throw new ScriptureUtilsException(SUE_ErrorCode.InvalidCharacterInMarker, null, 0,
                                                      sMarker + sText, SegmentFirstRef);
                }
                m_ptCurrentToken++;
            }
        }
Esempio n. 2
0
        public void TestCheckForOverlaps_MultipleOverlaps_KeepOneFile_RemoveTwo()
        {
            // Add temp file to the project
            using (TempSFFileMaker filemaker = new TempSFFileMaker())
            {
                ScrImportFileInfo f1 = new ScrImportFileInfo(
                    filemaker.CreateFile("MAT", new string[] { @"\c 1", @"\c 2", @"\c 3" }),
                    m_mappingList, ImportDomain.Main, null, 0, false);

                ScrImportFileInfo f2 = new ScrImportFileInfo(
                    filemaker.CreateFile("MAT", new string[] { @"\c 4", @"\c 5", @"\c 6" }),
                    m_mappingList, ImportDomain.Main, null, 0, false);

                m_expectedRemovedFiles.Add(f1);
                m_expectedRemovedFiles.Add(f2);

                ScrImportFileInfo f3 = new ScrImportFileInfo(
                    filemaker.CreateFile("MAT", new string[] { @"\c 1", @"\c 2", @"\c 3", @"\c 4", @"\c 5", @"\c 6" }),
                    m_mappingList, ImportDomain.Main, null, 0, false);

                m_resolver.ExpectAndReturn("ChooseFileToRemove", f1, f3, f1);
                m_resolver.ExpectAndReturn("ChooseFileToRemove", f2, f3, f2);

                m_fileList.Add(f1);
                m_fileList.Add(f2);
                m_fileList.Add(f3);

                Assert.AreEqual(1, m_fileList.Count);
                Assert.AreEqual(f3, m_fileList[0]);
            }
            m_resolver.Verify();
            Assert.AreEqual(m_expectedRemovedFiles.Count, m_callCountForVerifyFileRemoved);
        }
        /// -------------------------------------------------------------------------------
        /// <summary>
        /// Add the given SF scripture file to the list and select the first one if none
        /// is selected.
        /// </summary>
        /// <param name="listView">The list view to add the files to</param>
        /// <param name="fileInfo">list of files to be added</param>
        /// <param name="warnOnError">display an error if a file is not valid and
        /// do not add it to the list.  If this is false then invalid files will
        /// be added to the list anyway.</param>
        /// -------------------------------------------------------------------------------
        public void CallAddFileToListView(ListView listView, ScrImportFileInfo fileInfo,
                                          bool warnOnError)
        {
            CheckDisposed();

            base.AddFileToListView(listView, fileInfo, warnOnError);
        }
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Display the Overlapping files dialog to allow the user to decide which file to
 /// remove from a pair of files which have overlapping references.
 /// </summary>
 /// <param name="file1">file info 1</param>
 /// <param name="file2">file info 2</param>
 /// <returns>The file to remove</returns>
 /// ------------------------------------------------------------------------------------
 public ScrImportFileInfo ChooseFileToRemove(ScrImportFileInfo file1, ScrImportFileInfo file2)
 {
     m_file1 = file1;
     m_file2 = file2;
     try
     {
         if (ShowDialog() == DialogResult.OK)
         {
             return(FileToRemove);
         }
     }
     finally
     {
         m_file1 = null;
         m_file2 = null;
     }
     throw new CancelException("Import fCanceled by user.");
 }
Esempio n. 5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Advance the scripture text object enumerator to the next segment.
        /// </summary>
        /// <remarks>Virtual to support testing</remarks>
        /// <param name="sText">Set to the text of the current segment</param>
        /// <param name="sMarker">Set to the marker of the current segment tag</param>
        /// <param name="domain">Set to the domain of the stream being processed</param>
        /// <returns>True if successful. False if there are no more segments.</returns>
        /// ------------------------------------------------------------------------------------
        public virtual bool GetNextSegment(out string sText, out string sMarker,
                                           out ImportDomain domain)
        {
            int result = 0;

            domain = m_currentDomain;

            if (TypeOfImport == TypeOfImport.Paratext6)
            {
                result = m_scParatextTextEnum.Next(m_scParatextTextSegment);
                if (result != 0)
                {
                    sText   = m_scParatextTextSegment.Text;
                    sMarker = @"\" + m_scParatextTextSegment.Tag.Marker;

                    if (!ScrImportFileInfo.IsValidMarker(sMarker))
                    {
                        throw new ScriptureUtilsException(SUE_ErrorCode.InvalidCharacterInMarker, null, 0,
                                                          sMarker + sText, m_scParatextTextSegment.FirstReference.BBCCCVVV);
                    }
                    return(true);
                }
                else
                {
                    switch (m_currentDomain)
                    {
                    case ImportDomain.Main:
                    {
                        if (LoadParatextBackTranslationProject())
                        {
                            return(GetNextSegment(out sText, out sMarker, out domain));
                        }
                        goto case ImportDomain.BackTrans;
                    }

                    case ImportDomain.BackTrans:
                    {
                        if (LoadParatextNotesProject())
                        {
                            return(GetNextSegment(out sText, out sMarker, out domain));
                        }
                        break;
                    }
                    }
                }
            }
            else if (TypeOfImport == TypeOfImport.Other || TypeOfImport == TypeOfImport.Paratext5)
            {
                m_scTextSegment = m_scTextEnum.Next();
                if (m_scTextSegment != null)
                {
                    sText   = m_scTextSegment.Text;
                    sMarker = m_scTextSegment.Marker;
                    return(true);
                }
                else
                {
                    switch (m_currentDomain)
                    {
                    case ImportDomain.Main:
                    {
                        m_currentDomain = ImportDomain.BackTrans;
                        m_scSfmText     = new SCScriptureText(m_settings, ImportDomain.BackTrans);
                        // Now initialize the TextEnum with the range of scripture text we want
                        m_scTextEnum = m_scSfmText.TextEnum(m_settings.StartRef, m_settings.EndRef);
                        return(GetNextSegment(out sText, out sMarker, out domain));
                    }

                    case ImportDomain.BackTrans:
                    {
                        m_currentDomain = ImportDomain.Annotations;
                        m_scSfmText     = new SCScriptureText(m_settings, ImportDomain.Annotations);
                        // Now initialize the TextEnum with the range of scripture text we want
                        m_scTextEnum = m_scSfmText.TextEnum(m_settings.StartRef, m_settings.EndRef);
                        return(GetNextSegment(out sText, out sMarker, out domain));
                    }
                    }
                }
            }
            else
            {
                throw new Exception("GetNextSegment has an invalid import type");
            }

            sText   = null;
            sMarker = null;
            return(false);
        }