/// ----------------------------------------------------------------------------------- /// <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); }
/// ------------------------------------------------------------------------------------ /// <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); } }