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>
        /// <param name="helpFile">The path of the application help file.</param>
        /// ------------------------------------------------------------------------------------
        public ScrSfFileList(IScrImportSFFiles source, ScrMappingList mappingList,
                             ImportDomain importDomain, bool scanInlineBackslashMarkers, string helpFile)
            : this(null)
        {
            List <ICmFile> 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)
                {
                    MessageBoxUtils.Show(string.Format(ScrFdoResources.kstidImportBadFile, e.Message), "", MessageBoxButtons.OK,
                                         MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, helpFile, HelpNavigator.Topic, 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>
        /// 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 <IFdoUI>();
                    userAction.DisplayMessage(MessageType.Error, string.Format(ScrFdoResources.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. 3
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. 4
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);
            }
        }
		/// -------------------------------------------------------------------------------
		/// <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);
		}
Esempio n. 6
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<IFdoUI>();
					userAction.DisplayMessage(MessageType.Error, string.Format(ScrFdoResources.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;
		}