Esempio n. 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Initializes a new instance of the <see cref="ScrSfFileList"/> class based on an
        /// existing ScrImportSFFiles in the DB.
        /// </summary>
        /// <param name="source">A DB-based collection of Standard Format files</param>
        /// <param name="mappingList">The mapping list to which mappings will be added if any
        /// new ones are found when scanning the files</param>
        /// <param name="importDomain">Main (vernacular Scripture), BT or Annotations</param>
        /// <param name="scanInlineBackslashMarkers"><c>true</c> to look for backslash markers
        /// in the middle of lines. (Toolbox dictates that fields tagged with backslash markers
        /// must start on a new line, but Paratext considers all backslashes in the data to be
        /// SF markers.)</param>
        /// ------------------------------------------------------------------------------------
        public ScrSfFileList(IScrImportSFFiles source, ScrMappingList mappingList,
                             ImportDomain importDomain, bool scanInlineBackslashMarkers)
            : this(null)
        {
            var deleteList = new List <ICmFile>();
            // Load the files into an in-memory list
            foreach (ICmFile file in source.FilesOC)
            {
                try
                {
                    IScrImportFileInfo info = new ScrImportFileInfo(file, mappingList, importDomain,
                                                                    source.WritingSystem, source.NoteTypeRA, scanInlineBackslashMarkers);
                    Add(info);
                }
                catch (ScriptureUtilsException e)
                {
                    var userAction = source.Services.GetInstance <ILcmUI>();
                    userAction.DisplayMessage(MessageType.Error, string.Format(ScrResources.kstidImportBadFile, e.Message), Strings.ksErrorCaption, e.HelpTopic);
                    deleteList.Add(file);
                }
            }

            // delete all of the files that caused errors
            foreach (ICmFile deleteItem in deleteList)
            {
                source.FilesOC.Remove(deleteItem);
            }

            m_modified = false;
        }
Esempio n. 2
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Check to see if this file overlaps any other files. Resolve the conflict and
        /// insert this file if it is ok.
        /// </summary>
        /// <param name="fileToAdd"></param>
        /// <returns>true if fileToAdd should be inserted into the list, else false</returns>
        /// ------------------------------------------------------------------------------------
        private bool CheckForOverlaps(IScrImportFileInfo fileToAdd)
        {
            if (m_resolver == null)
            {
                return(true);
            }

            List <IScrImportFileInfo> removedList = new List <IScrImportFileInfo>();

            foreach (IScrImportFileInfo file2 in this)
            {
                if (ScrImportFileInfo.CheckForOverlap(fileToAdd, file2))
                {
                    IScrImportFileInfo removedFile;
                    // TE-4808: First make sure file2 is still accessible. If not, just let
                    // the added file replace it quietly.
                    if (file2.IsStillReadable)
                    {
                        removedFile = m_resolver.ChooseFileToRemove(fileToAdd, file2);
                        // If we're removing the file being added, no need to continue looking for overlaps
                        if (removedFile == fileToAdd)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        removedFile = file2;
                    }
                    removedList.Add(removedFile);
                }
            }

            // Remove all of the overlapping files from the import files collection
            // that we decided we didn't want.
            foreach (IScrImportFileInfo file in removedList)
            {
                Remove(file);
            }

            return(true);
        }
Esempio n. 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Check all files in the given reference range to see if there are any reference
        /// overlaps. If so, resolve the conflict.
        /// </summary>
        /// <param name="start">Start reference</param>
        /// <param name="end">End Reference</param>
        /// ------------------------------------------------------------------------------------
        internal void CheckForOverlappingFilesInRange(ScrReference start, ScrReference end)
        {
            List <IScrImportFileInfo> removedList = new List <IScrImportFileInfo>();

            foreach (IScrImportFileInfo file1 in this)
            {
                if (removedList.Contains(file1))
                {
                    continue;
                }
                foreach (ReferenceRange range in file1.BookReferences)
                {
                    if (range.OverlapsRange(start, end))
                    {
                        foreach (IScrImportFileInfo file2 in this)
                        {
                            if (file1 == file2 || removedList.Contains(file2))
                            {
                                continue;
                            }
                            if (ScrImportFileInfo.CheckForOverlap(file1, file2))
                            {
                                Debug.Assert(m_resolver != null, "Must set OverlappingFileResolver before calling CheckForOverlappingFilesInRange.");
                                removedList.Add(m_resolver.ChooseFileToRemove(file1, file2));
                            }
                        }
                    }
                }
            }
            // Remove all of the overlapping files from the import files collection
            // that we decided we didn't want.
            foreach (IScrImportFileInfo file in removedList)
            {
                Remove(file);
            }
        }