/// ------------------------------------------------------------------------------------ /// <summary> /// Creates a picture object and inserts it into the cache's picture collection. /// </summary> /// <returns>The hvo of the picture.</returns> /// ------------------------------------------------------------------------------------ private int CreateAndInsertPicture() { int pictureCount = Cache.LangProject.PicturesOC.Count; int hvoFolder = Cache.CreateObject(CmFolder.kClassId, Cache.LangProject.Hvo, (int)LangProject.LangProjectTags.kflidPictures, 0); CmFolder folder = new CmFolder(Cache, hvoFolder, true, true); CmFile file = new CmFile(); folder.FilesOC.Add(file); int hvoPict = Cache.CreateObject(CmPicture.kclsidCmPicture); CmPicture picture = new CmPicture(Cache, hvoPict, true, true); picture.PictureFileRA = file; // Make sure the picture got added to the cache's picture collection. Assert.AreEqual(pictureCount + 1, Cache.LangProject.PicturesOC.Count); return picture.Hvo; }
public void CmFileFinder_OrigFilesMatch() { CheckDisposed(); // Setup ICmFolder folder = CmFolder.FindOrCreateFolder(Cache, (int)LangProject.LangProjectTags.kflidPictures, StringUtils.LocalPictures); using (DummyFileMaker maker = new DummyFileMaker("garbage.jpg", true)) { ICmFile fileOrig = new CmFile(); folder.FilesOC.Add(fileOrig); fileOrig.InternalPath = maker.Filename; ICmFile file = CmFile.FindOrCreateFile(folder, maker.Filename); Assert.AreEqual(fileOrig, file); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Construct a ScrImportFileInfo from a CmFile owned by a BT source. This is /// used when populating the file list from the database. /// </summary> /// <param name="file">The CmFile</param> /// <param name="mappingList">Sorted list of mappings to which newly found mappings /// should (and will) be added</param> /// <param name="domain">The import domain to which this file belongs</param> /// <param name="icuLocale">The ICU locale of the source to which this file belongs /// (null for Scripture source)</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 ScrImportFileInfo(CmFile file, ScrMappingList mappingList, ImportDomain domain, string icuLocale, bool scanInlineBackslashMarkers): this(file, mappingList, domain, icuLocale, 0, scanInlineBackslashMarkers) { }
public void ConvertFromBlobSettings_Other_Version0x104() { CheckDisposed(); // Create a blob of settings. ArrayList mappingList = new ArrayList(); mappingList.Add(new MappingInfo(@"\btp", null, false, null, MarkerDomain.BackTrans, ScrStyleNames.NormalParagraph, null, false, MappingTargetType.TEStyle)); mappingList.Add(new MappingInfo(@"\btp_fr", null, false, null, MarkerDomain.BackTrans, ScrStyleNames.NormalParagraph, "fr", false, MappingTargetType.TEStyle)); mappingList.Add(new MappingInfo(@"\c", null, false, null, MarkerDomain.Default, ScrStyleNames.ChapterNumber, null, false, MappingTargetType.TEStyle)); mappingList.Add(new MappingInfo(@"|i{", @"}", true, null, MarkerDomain.Default, "Emphasis", null, false, MappingTargetType.TEStyle)); mappingList.Add(new MappingInfo(@"\ex", null, false, null, MarkerDomain.Default, null, null, true, MappingTargetType.TEStyle)); mappingList.Add(new MappingInfo(@"\f", null, false, null, MarkerDomain.Default, ScrStyleNames.NormalFootnoteParagraph, null, false, MappingTargetType.TEStyle)); mappingList.Add(new MappingInfo(@"\fig", null, false, null, MarkerDomain.Default, null, null, false, MappingTargetType.Figure)); mappingList.Add(new MappingInfo(@"\h", null, false, null, MarkerDomain.Default, null, null, false, MappingTargetType.TitleShort)); mappingList.Add(new MappingInfo(@"\id", null, false, null, MarkerDomain.Default, null, null, false, MappingTargetType.TEStyle)); mappingList.Add(new MappingInfo(@"\rem", null, false, null, MarkerDomain.Note, ScrStyleNames.Remark, null, false, MappingTargetType.TEStyle)); mappingList.Add(new MappingInfo(@"\v", null, false, null, MarkerDomain.Default, ScrStyleNames.VerseNumber, null, false, MappingTargetType.TEStyle)); mappingList.Add(new MappingInfo(@"|x{", "}", true, null, MarkerDomain.Default | MarkerDomain.Footnote, ScrStyleNames.CrossRefFootnoteParagraph, null, false, MappingTargetType.TEStyle)); ArrayList fileList = new ArrayList(2); fileList.Add(@"c:\my data\first file.sf"); fileList.Add(@"c:\my data\tom's file.sf"); m_importSettings.ImportType = (int)TypeOfImport.Other; DynamicMock mockStyleSheet = new DynamicMock(typeof(IVwStylesheet)); mockStyleSheet.SetupResultForParams("GetContext", ContextValues.Note, ScrStyleNames.NormalFootnoteParagraph); mockStyleSheet.SetupResultForParams("GetContext", ContextValues.General, new IsAnything()); // We don't care about anything else for these tests ReflectionHelper.SetField(m_importSettings, "m_stylesheet", (IVwStylesheet)mockStyleSheet.MockInstance); // Call ConvertFromBlobSettings, which should cause the blob to be converted. ReflectionHelper.CallMethod(m_importSettings, "ConvertFromBlobSettings", GetEcProjectSettingsArray(mappingList, fileList)); // Make sure that the blob and deprecated footnote settings are eliminated and // that the settings are correct in the database. Assert.AreEqual(0, ImportSettings.Length); Assert.AreEqual(12, m_importSettings.ScriptureMappingsOC.Count); Assert.AreEqual(0, m_importSettings.NoteMappingsOC.Count); IEnumerator<IScrMarkerMapping> mappings = m_importSettings.ScriptureMappingsOC.GetEnumerator(); //mappings.Reset(); // Throws NotSupportedException exception on generic enumerator VerifyNextMapping(mappings, @"\btp", null, MarkerDomain.BackTrans, ScrStyleNames.NormalParagraph, null, false, MappingTargetType.TEStyle); VerifyNextMapping(mappings, @"\btp_fr", null, MarkerDomain.BackTrans, ScrStyleNames.NormalParagraph, "fr", false, MappingTargetType.TEStyle); VerifyNextMapping(mappings, @"\c", null, MarkerDomain.Default /* NOT Default! */, ScrStyleNames.ChapterNumber, null, false, MappingTargetType.TEStyle); VerifyNextMapping(mappings, @"|i{", @"}", MarkerDomain.Default, "Emphasis", null, false, MappingTargetType.TEStyle); VerifyNextMapping(mappings, @"\ex", null, MarkerDomain.Default, null, null, true, MappingTargetType.TEStyle); VerifyNextMapping(mappings, @"\f", null, MarkerDomain.Footnote, ScrStyleNames.NormalFootnoteParagraph, null, false, MappingTargetType.TEStyle); VerifyNextMapping(mappings, @"\fig", null, MarkerDomain.Default, null, null, false, MappingTargetType.Figure); VerifyNextMapping(mappings, @"\h", null, MarkerDomain.Default, null, null, false, MappingTargetType.TitleShort); VerifyNextMapping(mappings, @"\id", null, MarkerDomain.Default, null, null, false, MappingTargetType.TEStyle); VerifyNextMapping(mappings, @"\rem", null, MarkerDomain.Note, ScrStyleNames.Remark, null, false, MappingTargetType.TEStyle); VerifyNextMapping(mappings, @"\v", null, MarkerDomain.Default /* NOT Default! */, ScrStyleNames.VerseNumber, null, false, MappingTargetType.TEStyle); VerifyNextMapping(mappings, @"|x{", "}", MarkerDomain.Footnote, ScrStyleNames.CrossRefFootnoteParagraph, null, false, MappingTargetType.TEStyle); Assert.IsFalse(mappings.MoveNext(), "This is just a sanity check to make sure we remembered to check all the mappings in this test."); Assert.AreEqual(1, m_importSettings.ScriptureSourcesOC.Count); Assert.AreEqual(0, m_importSettings.BackTransSourcesOC.Count); Assert.AreEqual(0, m_importSettings.NoteSourcesOC.Count); ScrImportSFFiles scriptureSource = new ScrImportSFFiles(Cache, m_importSettings.ScriptureSourcesOC.HvoArray[0]); Assert.AreEqual((int)FileFormatType.Other, scriptureSource.FileFormat); Assert.AreEqual(2, scriptureSource.FilesOC.Count); int[] cmFileHvos = scriptureSource.FilesOC.HvoArray; CmFile file = new CmFile(Cache, cmFileHvos[0]); Assert.AreEqual((string)fileList[0], file.AbsoluteInternalPath); file = new CmFile(Cache, cmFileHvos[1]); Assert.AreEqual((string)fileList[1], file.AbsoluteInternalPath); }