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(ScrImportSFFiles source, ScrMappingList mappingList,
                             ImportDomain importDomain, bool scanInlineBackslashMarkers, string helpFile) : this(null)
        {
            List <int> deleteList = new List <int>();
            // Load the files into an in-memory list
            foreach (ICmFile file in source.FilesOC)
            {
                try
                {
                    ScrImportFileInfo info = new ScrImportFileInfo(file, mappingList, importDomain,
                                                                   source.ICULocale, source.NoteTypeRAHvo, scanInlineBackslashMarkers);
                    Add(info);
                }
                catch (ScriptureUtilsException e)
                {
                    MessageBox.Show(string.Format(ScrFdoResources.kstidImportBadFile, e.Message), "", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, helpFile, HelpNavigator.Topic, e.HelpTopic);
                    deleteList.Add(file.Hvo);
                }
            }

            // delete all of the files that caused errors
            foreach (int deleteItem in deleteList)
            {
                source.Cache.DeleteObject(deleteItem);
            }

            m_modified = false;
        }
Esempio n. 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Add a new ScrImportFileInfo to the list
        /// </summary>
        /// <param name="value">a ScrImportFileInfo object</param>
        /// <returns>The <c>ArrayList</c> index at which the value has been added or
        /// -1 if it was not added</returns>
        /// ------------------------------------------------------------------------------------
        public override int Add(object value)
        {
            ScrImportFileInfo fileToAdd = (ScrImportFileInfo)value;

            // TODO: make sure it does not already exist
            if (fileToAdd.IsReadable)
            {
                if (!CheckForOverlaps(fileToAdd))
                {
                    return(-1);
                }
                for (int index = 0; index < Count; index++)
                {
                    ScrImportFileInfo file = (ScrImportFileInfo)this[index];
                    if (file.StartRef > fileToAdd.StartRef)
                    {
                        base.Insert(index, fileToAdd);
                        m_modified = true;
                        return(index);
                    }
                }
            }
            m_modified = true;
            return(base.Add(fileToAdd));
        }
Esempio n. 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Open the next source file to read. Skip over any files that do not contain
        /// data in the desired range.
        /// </summary>
        /// <returns>true if a file was opened, else false and there are no more
        /// files available</returns>
        /// ------------------------------------------------------------------------------------
        private bool OpenNextSourceFile(BCVRef startRef, BCVRef endRef)
        {
            // Clear the indicator that tells that an ID line has been encountered
            m_seenIdInFile = false;
            m_lineNumber   = 0;

            // If the first file is being opened, then initialize the reference
            if (m_currentFile == null)
            {
                m_currentStartRef = new BCVRef();
                m_currentEndRef   = new BCVRef();
            }
            // Find the next book in the project that has books in the import range
            bool fileHasBooksInRange = false;

            while (!fileHasBooksInRange)
            {
                if (!m_importSourceEnum.MoveNext())
                {
                    return(false);
                }
                m_currentFile = (ScrImportFileInfo)m_importSourceEnum.Current;

                if (m_domain != ImportDomain.Main)
                {
                    m_prevDataEncoding = GetEncodingConverterForLocale(m_currentFile.IcuLocale,
                                                                       ScrImportSet.s_markerBook);
                }

                // make sure the file contains books in the desired range
                foreach (int book in m_currentFile.BooksInFile)
                {
                    if (book >= startRef.Book && book <= endRef.Book)
                    {
                        fileHasBooksInRange = true;
                        break;
                    }
                }
            }

            try
            {
                // ASCII encoding will convert all high-bit characters to a '?'.
                // The magic code page will map all high-bit characters to the same
                // value with a high-byte of 0 in unicode. For example, character 0x84
                // will end up as 0x0084.
                Encoding useEncoding = (m_currentFile.FileEncoding == Encoding.ASCII) ?
                                       Encoding.GetEncoding(kMagicCodePage) : m_currentFile.FileEncoding;

                m_sfFileReader = new StreamReader(m_currentFile.FileName, useEncoding);
            }
            catch (Exception e)
            {
                throw new ScriptureUtilsException(SUE_ErrorCode.FileError, m_currentFile.FileName, e);
            }
            return(true);
        }
Esempio n. 4
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(ScrImportFileInfo fileToAdd)
        {
            if (m_resolver == null)
            {
                return(true);
            }

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

            foreach (ScrImportFileInfo file2 in this)
            {
                if (ScrImportFileInfo.CheckForOverlap(fileToAdd, file2))
                {
                    ScrImportFileInfo 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 (ScrImportFileInfo file in removedList)
            {
                Remove(file);
            }

            return(true);
        }
Esempio n. 5
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Check two ScrImportFileInfo objects for overlap.
 /// </summary>
 /// <param name="map1">first ScrImportFileInfo to compare</param>
 /// <param name="map2">second ScrImportFileInfo to compare</param>
 /// <returns>true if an overlap exists, false otherwise</returns>
 /// ------------------------------------------------------------------------------------
 public static bool CheckForOverlap(ScrImportFileInfo map1, ScrImportFileInfo map2)
 {
     foreach (ReferenceRange range1 in map1.BookReferences)
     {
         foreach (ReferenceRange range2 in map2.BookReferences)
         {
             if (range1.Book == range2.Book)
             {
                 if (range1.StartChapter >= range2.StartChapter && range1.StartChapter <= range2.EndChapter)
                 {
                     return(true);
                 }
                 if (range2.StartChapter >= range1.StartChapter && range2.StartChapter <= range1.EndChapter)
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Esempio n. 6
0
		public void TestCheckForOverlaps_KeepFile2()
		{
			// 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);

				m_expectedRemovedFiles.Add(f1);

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

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

				ScrImportFileInfo f4 = new ScrImportFileInfo("c:\\Idontexist.blurb",
					m_mappingList, ImportDomain.Main, null, 0, false);

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

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

				Assert.AreEqual(3, m_fileList.Count);
				Assert.AreEqual(f2, m_fileList[0]);
				Assert.AreEqual(f3, m_fileList[1]);
				Assert.AreEqual(f4, m_fileList[2]);
			}
			m_resolver.Verify();
			Assert.AreEqual(m_expectedRemovedFiles.Count, m_callCountForVerifyFileRemoved);
		}
Esempio n. 7
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 <ScrImportFileInfo> removedList = new List <ScrImportFileInfo>();

            foreach (ScrImportFileInfo file1 in this)
            {
                if (removedList.Contains(file1))
                {
                    continue;
                }
                foreach (ReferenceRange range in file1.BookReferences)
                {
                    if (range.OverlapsRange(start, end))
                    {
                        foreach (ScrImportFileInfo 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 (ScrImportFileInfo file in removedList)
            {
                Remove(file);
            }
        }
		public void OverlapWhenOneFileContainsSubset()
		{
			using (TempSFFileMaker filemaker = new TempSFFileMaker())
			{
				string fileName1 = filemaker.CreateFile("MAT", new string[] {@"\c 3",  @"\c 4", @"\c 5", @"\c 6"});
				ScrImportFileInfo map1 = new ScrImportFileInfo(fileName1, m_mappingList,
					ImportDomain.Main, null, 0);

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

				Assert.IsTrue(ScrImportFileInfo.CheckForOverlap(map1, map2));
				Assert.IsTrue(ScrImportFileInfo.CheckForOverlap(map2, map1));
			}
		}
		public void FigureEntries_good_SplitAcrossLine_LineWithMarkerFollowing()
		{
			using (TempSFFileMaker fileMaker = new TempSFFileMaker())
			{
				string sFilename = fileMaker.CreateFile("ROM",
					new string[] {@"\mt Romans",
						@"\c 1",
						@"\v 1 Hello",
						@"\fig stuff1|stuff2|stuff3|stuff that",
						@"is for 4|stuff5|stuff6",
						@"\v 2 This is Paul."},
					Encoding.UTF8, false);

				m_mappingList.Add(new ImportMappingInfo(@"\fig", null, false, MappingTargetType.Figure, MarkerDomain.Default, null, null));

				ScrImportFileInfo fileInfo = new ScrImportFileInfo(sFilename, m_mappingList,
					ImportDomain.Main, null, 0, true);
				// Use strict checking to make sure no error occurs.
				fileInfo.PerformStrictScan();
			}
		}
Esempio n. 10
0
		public void NoOverlapInOneBook()
		{
			using (TempSFFileMaker filemaker = new TempSFFileMaker())
			{
				string fileName1 = filemaker.CreateFile("MAT", new string[] {@"\c 1", @"\c 2", @"\c 3", @"\c 4"});
				ScrImportFileInfo map1 = new ScrImportFileInfo(fileName1, m_mappingList,
					ImportDomain.Main, null, 0);

				string fileName2 = filemaker.CreateFile("MAT", new string[] {@"\c 5", @"\c 6", @"\c 8", @"\c 18"});
				ScrImportFileInfo map2 = new ScrImportFileInfo(fileName2, m_mappingList,
					ImportDomain.Main, null, 0);

				Assert.IsFalse(ScrImportFileInfo.CheckForOverlap(map1, map2));
				Assert.IsFalse(ScrImportFileInfo.CheckForOverlap(map2, map1));
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <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. 12
0
		public void FigureEntries_bad_tooFewTokens()
		{
			using (TempSFFileMaker fileMaker = new TempSFFileMaker())
			{
				string sFilename = fileMaker.CreateFile("ROM",
					new string[] {	 @"\mt Romans",
									 @"\c 1",
									 @"\v 1 Hello",
									 @"\fig stuff1|stuff2|stuff3|stuff4|stuff5"},
					Encoding.UTF8, false);

				m_mappingList.Add(new ImportMappingInfo(@"\fig", null, false, MappingTargetType.Figure, MarkerDomain.Default, null, null));

				// Try it first without strict checking to make sure it does not throw an exception
				ScrImportFileInfo fileInfo = new ScrImportFileInfo(sFilename, m_mappingList, ImportDomain.Main, null, 0);

				try
				{
					// Use strict checking to make sure the error occurs.
					fileInfo.PerformStrictScan();
				}
				catch (ScriptureUtilsException e)
				{
					Assert.AreEqual(SUE_ErrorCode.BadFigure, e.ErrorCode);
					return;
				}
				Assert.Fail("The expected exception did not happen");
			}
		}
Esempio n. 13
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="fileinfo">File that was removed</param>
 /// ------------------------------------------------------------------------------------
 public ScrImportFileEventArgs(ScrImportFileInfo fileinfo)
 {
     m_fileinfo = fileinfo;
 }
Esempio n. 14
0
		/// -------------------------------------------------------------------------------
		/// <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>
		/// -------------------------------------------------------------------------------
		protected void AddFileToListView(ListView listView, ScrImportFileInfo fileInfo,
			bool warnOnError)
		{
			Debug.Assert(listView != null);
			Debug.Assert(fileInfo != null);

			string filename = fileInfo.FileName;
					ListViewItem lvi = new ListViewItem(filename);

			StringBuilder booksInFile = new StringBuilder();

					// If the file does not exist then keep the name but do not try to read it.
					// It will be displayed in gray with <not found> for the list of books.
			if (fileInfo.IsReadable)
					{
						// Build a comma-delimited string of the 3 letter book abbreviations to go
						// into the second column in the listview.
				if (fileInfo != null)
				{
					foreach (int bookID in fileInfo.BooksInFile)
						{
							if (bookID >= 0 && bookID <= 66)
							{
								if (booksInFile.Length > 0)
								booksInFile.Append(", ");

							booksInFile.Append(ScrReference.NumberToBookCode(bookID));
						}
							}
						}

						// Add the book list as a sub item of the file name. Then add the filename
						// as the item in the listview.
				lvi.SubItems.Add(booksInFile.ToString());

//				if (listView != scrFileList)
//				{
//					lvi.SubItems.Add(GetWritingSystemNameForLocale(fileInfo.IcuLocale));
//				}

						// Add file encoding
				lvi.SubItems.Add(fileInfo == null ?
					Encoding.ASCII.EncodingName : fileInfo.FileEncoding.EncodingName);
					}
			else
					{
						// If we want to issue an error on missing files.
						if (warnOnError)
						{
							ShowBadFileMessage(DriveUtil.FileNameOnly(filename));
					return;
						}

						lvi.SubItems.Add(m_resources.GetString("kstidNoBooks"));
						lvi.SubItems.Add(m_resources.GetString("kstidFileMissing"));
					}

			// Store the file info in the list view item tag
			lvi.Tag = fileInfo;

					// Check to make sure the file is not already in the list
					bool found = false;
					ListViewItem item = null;
					int i;
			for (i = 0; i < listView.Items.Count; i++)
					{
				item = listView.Items[i];
						if (item.SubItems[0].Text.ToLower() == lvi.Text.ToLower())
						{
							found = true;
							break;
						}
					}

					if (!found)
			{
				// If the file is new, then find the place to insert it based on the
				// starting reference of the file
				bool inserted = false;
				for (i = 0; i < listView.Items.Count; i++)
				{
					ScrImportFileInfo listItemInfo = (ScrImportFileInfo)listView.Items[i].Tag;
					if (fileInfo.StartRef < listItemInfo.StartRef)
					{
						listView.Items.Insert(i, lvi);
						inserted = true;
						break;
					}
						}
				if (!inserted)
					listView.Items.Add(lvi);
					}
			else
			{
				if (i < listView.Items.Count)
				{
					lvi.Selected = listView.Items[i].Selected;
					listView.Items[i] = lvi;
				}
			}
			}
Esempio n. 15
0
		public void OverlapInTwoMaps()
		{
			using (TempSFFileMaker filemaker = new TempSFFileMaker())
			{
				string fileName1 = filemaker.CreateFile("MAT", new string[] {@"\c 1", @"\c 2", @"\c 3",
																			@"\id MRK", @"\c 1", @"\c 2", @"\c 3"});
				ScrImportFileInfo map1 = new ScrImportFileInfo(fileName1, m_mappingList,
					ImportDomain.Main, null, 0);

				string fileName2 = filemaker.CreateFile("MRK", new string[] {@"\c 3",
																				@"\id LUK", @"\c 1", @"\c 2", @"\c 3"});
				ScrImportFileInfo map2 = new ScrImportFileInfo(fileName2, m_mappingList,
					ImportDomain.Main, null, 0);

				Assert.IsTrue(ScrImportFileInfo.CheckForOverlap(map1, map2));
				Assert.IsTrue(ScrImportFileInfo.CheckForOverlap(map2, map1));
			}
		}
Esempio n. 16
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Open the next source file to read. Skip over any files that do not contain
		/// data in the desired range.
		/// </summary>
		/// <returns>true if a file was opened, else false and there are no more
		/// files available</returns>
		/// ------------------------------------------------------------------------------------
		private bool OpenNextSourceFile(BCVRef startRef, BCVRef endRef)
		{
			// Clear the indicator that tells that an ID line has been encountered
			m_seenIdInFile = false;
			m_lineNumber = 0;

			// If the first file is being opened, then initialize the reference
			if (m_currentFile == null)
			{
				m_currentStartRef = new BCVRef();
				m_currentEndRef = new BCVRef();
			}
			// Find the next book in the project that has books in the import range
			bool fileHasBooksInRange = false;
			while (!fileHasBooksInRange)
			{
				if (!m_importSourceEnum.MoveNext())
					return false;
				m_currentFile = (ScrImportFileInfo)m_importSourceEnum.Current;

				if (m_domain != ImportDomain.Main)
					m_prevDataEncoding = GetEncodingConverterForLocale(m_currentFile.IcuLocale,
						ScrImportSet.s_markerBook);

				// make sure the file contains books in the desired range
				foreach (int book in m_currentFile.BooksInFile)
				{
					if (book >= startRef.Book && book <= endRef.Book)
					{
						fileHasBooksInRange = true;
						break;
					}
				}
			}

			try
			{
				// ASCII encoding will convert all high-bit characters to a '?'.
				// The magic code page will map all high-bit characters to the same
				// value with a high-byte of 0 in unicode. For example, character 0x84
				// will end up as 0x0084.
				Encoding useEncoding = (m_currentFile.FileEncoding == Encoding.ASCII) ?
					Encoding.GetEncoding(kMagicCodePage) : m_currentFile.FileEncoding;

				m_sfFileReader = new StreamReader(m_currentFile.FileName, useEncoding);
			}
			catch (Exception e)
			{
				throw new ScriptureUtilsException(SUE_ErrorCode.FileError, m_currentFile.FileName, e);
			}
			return true;
		}
Esempio n. 17
0
		public void FigureEntries_good_WithEndMarker()
		{
			using (TempSFFileMaker fileMaker = new TempSFFileMaker())
			{
				// Note that ending \fig* is optional even if it is in mapping.
				string sFilename = fileMaker.CreateFile("ROM",
					new string[] {	 @"\mt Romans",
									 @"\c 1",
									 @"\v 1 Hello",
									 @"\fig stuff1|stuff2|stuff3|stuff4|stuff5|stuff6\fig* etc.",
									 @"\fig stuff1|stuff2|stuff3|stuff4|stuff5|stuff6"},
					Encoding.UTF8, false);

				m_mappingList.Add(new ImportMappingInfo(@"\fig", @"\fig*", false,
					MappingTargetType.Figure, MarkerDomain.Default, null, null));

				ScrImportFileInfo fileInfo = new ScrImportFileInfo(sFilename, m_mappingList,
					ImportDomain.Main, null, 0, true);
				// Use strict checking to make sure no error occurs.
				fileInfo.PerformStrictScan();
			}
		}
Esempio n. 18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Attempt to add a file to the project. If an error occurs, then show the message
		/// </summary>
		/// <param name="fileName"></param>
		/// <param name="info">returns a ScrImportFileInfo object representing the added
		/// file.</param>
		/// <returns>true if the file was added to the project</returns>
		/// ------------------------------------------------------------------------------------
		private bool AddFileToProject(string fileName, out ScrImportFileInfo info)
		{
			try
			{
				info = m_ImportSettings.AddFile(fileName, m_domain, m_icuLocale, m_noteTypeHvo, m_fileRemovedHandler);
				return (info != null);
			}
			catch (ScriptureUtilsException e)
			{
				Form parentWindow = FindForm();
				if (parentWindow != null)
				{
					MessageBox.Show(parentWindow, e.Message,
						ScriptureUtilsException.GetResourceString("kstidImportErrorCaption"),
						MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0,
						FwApp.App.HelpFile, HelpNavigator.Topic, e.HelpTopic);
				}

				info = null;
				return false;
			}
		}
Esempio n. 19
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="fileinfo">File that was removed</param>
		/// ------------------------------------------------------------------------------------
		public ScrImportFileEventArgs(ScrImportFileInfo fileinfo)
		{
			m_fileinfo = fileinfo;
		}
Esempio n. 20
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(ScrImportFileInfo fileToAdd)
		{
			if (m_resolver == null)
				return true;

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

			foreach (ScrImportFileInfo file2 in this)
			{
				if (ScrImportFileInfo.CheckForOverlap(fileToAdd, file2))
				{
					ScrImportFileInfo 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 (ScrImportFileInfo file in removedList)
				Remove(file);

			return true;
		}
Esempio n. 21
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(ScrImportSFFiles source, ScrMappingList mappingList,
			ImportDomain importDomain, bool scanInlineBackslashMarkers, string helpFile) : this(null)
		{
			List<int> deleteList = new List<int>();
			// Load the files into an in-memory list
			foreach (ICmFile file in source.FilesOC)
			{
				try
				{
					ScrImportFileInfo info = new ScrImportFileInfo(file, mappingList, importDomain,
						source.ICULocale, source.NoteTypeRAHvo, scanInlineBackslashMarkers);
					Add(info);
				}
				catch (ScriptureUtilsException e)
				{
					MessageBox.Show(string.Format(ScrFdoResources.kstidImportBadFile, e.Message), "", MessageBoxButtons.OK,
						MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, helpFile, HelpNavigator.Topic, e.HelpTopic);
					deleteList.Add(file.Hvo);
				}
			}

			// delete all of the files that caused errors
			foreach (int deleteItem in deleteList)
				source.Cache.DeleteObject(deleteItem);

			m_modified = false;
		}
Esempio n. 22
0
		public void DataFileInvalid_NonExcludedMarkersBeforeIdLine()
		{
			using (TempSFFileMaker fileMaker = new TempSFFileMaker())
			{
				string sFilename = fileMaker.CreateFileNoID(
					new string[] {@"\rem Ignore",
									 @"\mt Genesis",
									 @"\id GEN",
									 @"\c 1",
									 @"\v 1 Valid"});

				// Try it first without strict checking to make sure it does not throw an exception
				ScrImportFileInfo fileInfo = new ScrImportFileInfo(sFilename, m_mappingList, ImportDomain.Main, null, 0);

				// Now use strict checking to make sure the error occurs.
				try
				{
					fileInfo.PerformStrictScan();
					Assert.Fail("Failed to throw an exception.");
				}
				catch (ScriptureUtilsException e)
				{
					Assert.AreEqual(SUE_ErrorCode.UnexcludedDataBeforeIdLine, e.ErrorCode);
				}
			}
		}
Esempio n. 23
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Check two ScrImportFileInfo objects for overlap.
		/// </summary>
		/// <param name="map1">first ScrImportFileInfo to compare</param>
		/// <param name="map2">second ScrImportFileInfo to compare</param>
		/// <returns>true if an overlap exists, false otherwise</returns>
		/// ------------------------------------------------------------------------------------
		public static bool CheckForOverlap(ScrImportFileInfo map1, ScrImportFileInfo map2)
		{
			foreach (ReferenceRange range1 in map1.BookReferences)
			{
				foreach (ReferenceRange range2 in map2.BookReferences)
				{
					if (range1.Book == range2.Book)
					{
						if (range1.StartChapter >= range2.StartChapter && range1.StartChapter <= range2.EndChapter)
							return true;
						if (range2.StartChapter >= range1.StartChapter && range2.StartChapter <= range1.EndChapter)
							return true;
					}
				}
			}
			return false;
		}
Esempio n. 24
0
		public void TwoFigureEntries_good_NotScanningInline()
		{
			using (TempSFFileMaker fileMaker = new TempSFFileMaker())
			{
				// Note that ending \fig* is optional even if it is in mapping.
				string sFilename = fileMaker.CreateFile("ROM",
					new string[] {	 @"\c 1",
									 @"\v 1 Hello",
									 @"\fig stuff1|stuff2|stuff3|stuff4|stuff5|stuff6\fig*",
									 @"\new will I be seen?",
									 @"\v 2 I'm a verse, too.",
									 @"\btfig stuff1|stuff2|stuff3|stuff4|stuff5|stuff6\btfig*"},
					Encoding.UTF8, false);

				m_mappingList.Add(new ImportMappingInfo(@"\fig", @"\fig*", false,
					MappingTargetType.Figure, MarkerDomain.Default, null, null));

				ScrImportFileInfo fileInfo = new ScrImportFileInfo(sFilename, m_mappingList,
					ImportDomain.Main, null, 0, false);

				m_mappingList.Delete(m_mappingList[@"\new"]);
				Assert.IsNull(m_mappingList[@"\new"]);

				// Use strict checking to make sure no error occurs.
				fileInfo.PerformStrictScan();

				Assert.IsNotNull(m_mappingList[@"\new"]);
			}
		}
Esempio n. 25
0
		/// -------------------------------------------------------------------------------
		/// <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);
		}