public void TestProvidedTextUsedIfPresent() { string xml = "<document><interlinear-text>" + "<item type=\"title\" lang=\"en\">wordspace</item>" + "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" + "<paragraphs><paragraph><phrases><phrase>" + "<item type=\"txt\" lang=\"en\">Text not built from words.</item>" + "<item type=\"note\" lang=\"pt\">origem: mary poppins</item>" + "<words><word><item type=\"txt\" lang=\"en\">a</item></word>" + "<word><item type=\"txt\" lang=\"en\">space</item></word>" + "<word><item type=\"txt\" lang=\"en\">space</item></word>" + "</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>"; LinguaLinksImport li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray()))) { li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text); using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator()) { firstEntry.MoveNext(); var imported = firstEntry.Current; var para = imported.ContentsOA[0]; Assert.IsTrue(para.Contents.Text.Equals("Text not built from words.")); } } }
public void OneOfEachElementTypeTest() { string title = "atrocious"; string abbr = "atroc"; //an interliner text example xml string string xml = "<document><interlinear-text>" + "<item type=\"title\" lang=\"en\">" + title + "</item>" + "<item type=\"title-abbreviation\" lang=\"en\">" + abbr + "</item>" + "<paragraphs><paragraph><phrases><phrase>" + "<item type=\"reference-number\" lang=\"en\">1 Musical</item>" + "<item type=\"note\" lang=\"pt\">origem: mary poppins</item>" + "<words><word><item type=\"txt\" lang=\"en\">supercalifragilisticexpialidocious</item>" + "<item type=\"gls\" lang=\"pt\">absurdo</item></word>" + "</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>"; LinguaLinksImport li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray()))) { li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text); using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator()) { firstEntry.MoveNext(); var imported = firstEntry.Current; //The title imported Assert.True(imported.Name.get_String(Cache.WritingSystemFactory.get_Engine("en").Handle).Text.Equals(title)); //The title abbreviation imported Assert.True(imported.Abbreviation.get_String(Cache.WritingSystemFactory.get_Engine("en").Handle).Text.Equals(abbr)); } } }
public void TestImportCreatesReusesExistingSpeaker() { string xml = "<document><interlinear-text guid=\"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA\">" + "<item type=\"title\" lang=\"en\">wordspace</item>" + "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" + "<paragraphs><paragraph><phrases><phrase speaker=\"Jimmy Dorante\" media-file=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" guid=\"BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB\" begin-time-offset=\"1\" end-time-offset=\"2\">" + "<item type=\"text\">This is a test with text.</item><word>This</word></phrase></phrases></paragraph></paragraphs>" + "<languages><language lang=\"en\" font=\"latin\" vernacular=\"false\"/></languages>" + "<media-files offset-type=\"milliseconds\"><media guid=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" location=\"file:\\\\test.wav\"/></media-files></interlinear-text></document>"; ICmPerson newPerson = null; //Create and add Jimmy to the project. NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () => { Cache.LanguageProject.PeopleOA = Cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create(); //person not found create one and add it. newPerson = Cache.ServiceLocator.GetInstance <ICmPersonFactory>().Create(); Cache.LanguageProject.PeopleOA.PossibilitiesOS.Add(newPerson); newPerson.Name.set_String(Cache.DefaultVernWs, "Jimmy Dorante"); }); Assert.NotNull(newPerson); LinguaLinksImport li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray()))) { li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text); //If the import sets the speaker in the segment to our Jimmy, and not a new Jimmy then all is well Assert.AreEqual(newPerson, text.ContentsOA[0].SegmentsOS[0].SpeakerRA, "Speaker not reused."); } }
public void TestImportFullELANData() { string xml = "<document><interlinear-text guid=\"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA\">" + "<item type=\"title\" lang=\"en\">wordspace</item>" + "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" + "<paragraphs><paragraph><phrases><phrase media-file=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" guid=\"BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB\" begin-time-offset=\"1\" end-time-offset=\"2\">" + "<item type=\"text\">This is a test with text.</item><word>This</word></phrase></phrases></paragraph></paragraphs>" + "<languages><language lang=\"en\" font=\"latin\" vernacular=\"false\"/></languages>" + "<media-files offset-type=\"milliseconds\"><media guid=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" location=\"file:\\\\test.wav\"/></media-files></interlinear-text></document>"; LinguaLinksImport li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray()))) { li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text); using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator()) { firstEntry.MoveNext(); var imported = firstEntry.Current; Assert.True(imported.ContentsOA.ParagraphsOS.Count > 0, "Paragraph was not imported as text content."); var para = imported.ContentsOA[0]; Assert.NotNull(para, "The imported paragraph is null?"); Assert.True(para.SegmentsOS[0].Guid.ToString().ToUpper().Equals("BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB"), "Segment guid not maintained on import."); VerifyMediaLink(imported); } } }
protected override void DoStage2Conversion(byte[] stage1, IThreadedProgress dlg) { var stage2Converter = new LinguaLinksImport(m_cache, null, null); // Until we have a better idea, assume we're half done with the import when we've produced the intermediate. // TODO: we could do progress based on number of words to import. dlg.Position += 50; stage2Converter.ImportWordsFrag(() => new MemoryStream(stage1), LinguaLinksImport.ImportAnalysesLevel.WordGloss); }
public void TestSpacesAroundSpanishPunct() { string xml = "<document><interlinear-text>" + "<item type=\"title\" lang=\"en\">wordspace</item>" + "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" + "<paragraphs><paragraph><phrases><phrase>" + "<item type=\"reference-number\" lang=\"en\">1 Musical</item>" + "<item type=\"note\" lang=\"pt\">origem: mary poppins</item>" + "<words>" + "<word><item type=\"txt\" lang=\"en\">s</item></word>" + "<word><item type=\"punct\" lang=\"en\">.¡</item></word>" + // spanish begin exclamation "<word><item type=\"txt\" lang=\"en\">s</item></word>" + "<word><item type=\"punct\" lang=\"en\">!¿</item></word>" + // spanish begin question "<word><item type=\"txt\" lang=\"en\">s</item></word>" + "<word><item type=\"punct\" lang=\"en\">?</item></word>" + "<word><item type=\"txt\" lang=\"en\">s</item></word>" + "<word><item type=\"punct\" lang=\"en\">. ¿</item></word>" + "<word><item type=\"txt\" lang=\"en\">s</item></word>" + "<word><item type=\"punct\" lang=\"en\">? "¿</item></word>" + "<word><item type=\"txt\" lang=\"en\">s</item></word>" + "<word><item type=\"punct\" lang=\"en\">¿</item></word>" + "<word><item type=\"txt\" lang=\"en\">s</item></word>" + "</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>"; // -------------------------- // 01234567890123456789012345 // s. es! qs? s. qs? "qs qs (e=spanish beg. exclamation, q=spanish beg. question) // -------------------------- LinguaLinksImport li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray()))) { li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text); using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator()) { firstEntry.MoveNext(); var imported = firstEntry.Current; // why is this null?! var para = imported.ContentsOA[0]; var spaceArray = new char[] { ' ' }; var spaceOne = para.Contents.Text.Substring(2, 1); //should be: " " var spaceTwo = para.Contents.Text.Substring(6, 1); //should be: " " var spaceThree = para.Contents.Text.Substring(10, 1); var spaceFour = para.Contents.Text.Substring(13, 1); var spaceFive = para.Contents.Text.Substring(17, 1); var spaceSix = para.Contents.Text.Substring(21, 1); //test to make sure no space was inserted before the comma, this is probably captured by the other assert Assert.AreEqual(7, para.Contents.Text.Split(spaceArray).Length); //capture correct number of spaces, and no double spaces //test to make sure spaces were inserted in each expected place CollectionAssert.AreEqual(new[] { " ", " ", " ", " ", " ", " " }, new[] { spaceOne, spaceTwo, spaceThree, spaceFour, spaceFive, spaceSix }); } } }
private void m_btnOK_Click(object sender, EventArgs e) { using (var dlg = new ProgressDialogWithTask(this)) { dlg.AllowCancel = false; dlg.Minimum = 0; dlg.Maximum = 500; using (new WaitCursor(this, true)) { var import = new LinguaLinksImport(m_cache, Path.Combine(Path.GetTempPath(), "LanguageExplorer" + Path.DirectorySeparatorChar), Path.Combine(FwDirectoryFinder.CodeDirectory, Path.Combine("Language Explorer", "Import" + Path.DirectorySeparatorChar))); import.NextInput = m_tbFilename.Text; import.Error += import_Error; try { var fSuccess = (bool)dlg.RunTask(true, import.ImportInterlinear, m_tbFilename.Text); if (fSuccess) { DialogResult = DialogResult.OK; // only 'OK' if not exception var firstNewText = import.FirstNewText; if (firstNewText != null && m_mediator != null) { m_mediator.SendMessage("JumpToRecord", firstNewText.Hvo); } } else { DialogResult = DialogResult.Abort; // unsuccessful import string message = ITextStrings.ksInterlinImportFailed + Environment.NewLine + Environment.NewLine; message += m_messages.ToString(); MessageBox.Show(this, message, ITextStrings.ksImportFailed, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Close(); } catch (WorkerThreadException ex) { System.Diagnostics.Debug.WriteLine("Error: " + ex.InnerException.Message); MessageBox.Show(String.Format(import.ErrorMessage, ex.InnerException.Message), ITextStrings.ksUnhandledError, MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; // only 'OK' if not exception Close(); } } } }
private void m_btnOK_Click(object sender, EventArgs e) { using (var dlg = new ProgressDialogWithTask(this)) { dlg.AllowCancel = false; dlg.Minimum = 0; dlg.Maximum = 500; using (new WaitCursor(this, true)) { var import = new LinguaLinksImport(m_cache, Path.Combine(Path.GetTempPath(), "LanguageExplorer" + Path.DirectorySeparatorChar), Path.Combine(FwDirectoryFinder.CodeDirectory, Path.Combine("Language Explorer", "Import" + Path.DirectorySeparatorChar))); import.NextInput = m_tbFilename.Text; import.Error += import_Error; try { var fSuccess = (bool) dlg.RunTask(true, import.ImportInterlinear, m_tbFilename.Text); if (fSuccess) { DialogResult = DialogResult.OK; // only 'OK' if not exception var firstNewText = import.FirstNewText; if (firstNewText != null && m_mediator != null) { m_mediator.SendMessage("JumpToRecord", firstNewText.Hvo); } } else { DialogResult = DialogResult.Abort; // unsuccessful import string message = ITextStrings.ksInterlinImportFailed + Environment.NewLine + Environment.NewLine; message += m_messages.ToString(); MessageBox.Show(this, message, ITextStrings.ksImportFailed, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Close(); } catch (WorkerThreadException ex) { System.Diagnostics.Debug.WriteLine("Error: " + ex.InnerException.Message); MessageBox.Show(String.Format(import.ErrorMessage, ex.InnerException.Message), ITextStrings.ksUnhandledError, MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; // only 'OK' if not exception Close(); } } } }
protected virtual void DoStage2Conversion(byte[] stage1, IThreadedProgress dlg) { using (var stage2Input = new MemoryStream(stage1)) { var stage2Converter = new LinguaLinksImport(m_cache, null, null); // Until we have a better idea, assume we're half done with the import when we've produced the intermediate. // Allocate 5 progress units to the ImportInterlinear, in case it can do better resolution. // Enhance JohnT: we could divide the progress up based on the lengths of the files, // and possibly converter.Convert could move the bar along based on how far through the file it is. // ImportInterlinear could do something similar. However, procesing a single file is so quick // that this very crude approximation is good enough. dlg.Position += 50; stage2Converter.ImportInterlinear(dlg, stage2Input, 50, ref m_firstNewText); } }
private void m_btnOK_Click(object sender, EventArgs e) { using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(this)) { dlg.CancelButtonVisible = false; dlg.SetRange(0, 500); using (new WaitCursor(this, true)) { LinguaLinksImport import = new LinguaLinksImport(m_cache, Path.Combine(Path.GetTempPath(), "LanguageExplorer\\"), Path.Combine(SIL.FieldWorks.Common.Utils.DirectoryFinder.FWCodeDirectory, "Language Explorer\\Import\\")); import.NextInput = m_tbFilename.Text; import.Error += new LinguaLinksImport.ErrorHandler(import_Error); dlg.Cancel += new CancelHandler(import.On_ProgressDlg_Cancel); try { bool fSuccess = (bool)dlg.RunTask(true, new BackgroundTaskInvoker(import.ImportInterlinear), m_tbFilename.Text); if (fSuccess) { this.DialogResult = DialogResult.OK; // only 'OK' if not exception } else { this.DialogResult = DialogResult.Abort; // unsuccessful import string message = ITextStrings.ksInterlinImportFailed + "\n\n"; message += m_messages.ToString(); MessageBox.Show(this, message, ITextStrings.ksImportFailed, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Close(); } catch (WorkerThreadException ex) { System.Diagnostics.Debug.WriteLine("Error: " + ex.InnerException.Message); MessageBox.Show(String.Format(import.ErrorMessage, ex.InnerException.Message), ITextStrings.ksUnhandledError, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.Cancel; // only 'OK' if not exception Close(); } } } }
private void m_btnOK_Click(object sender, EventArgs e) { using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(this)) { dlg.CancelButtonVisible = false; dlg.SetRange(0, 500); using (new WaitCursor(this, true)) { LinguaLinksImport import = new LinguaLinksImport(m_cache, Path.Combine(Path.GetTempPath(), "LanguageExplorer\\"), Path.Combine(SIL.FieldWorks.Common.Utils.DirectoryFinder.FWCodeDirectory, "Language Explorer\\Import\\")); import.NextInput = m_tbFilename.Text; import.Error += new LinguaLinksImport.ErrorHandler(import_Error); dlg.Cancel += new CancelHandler(import.On_ProgressDlg_Cancel); try { bool fSuccess = (bool)dlg.RunTask(true, new BackgroundTaskInvoker(import.ImportInterlinear), m_tbFilename.Text); if (fSuccess) this.DialogResult = DialogResult.OK; // only 'OK' if not exception else { this.DialogResult = DialogResult.Abort; // unsuccessful import string message = ITextStrings.ksInterlinImportFailed + "\n\n"; message += m_messages.ToString(); MessageBox.Show(this, message, ITextStrings.ksImportFailed, MessageBoxButtons.OK, MessageBoxIcon.Warning); } Close(); } catch (WorkerThreadException ex) { System.Diagnostics.Debug.WriteLine("Error: " + ex.InnerException.Message); MessageBox.Show(String.Format(import.ErrorMessage, ex.InnerException.Message), ITextStrings.ksUnhandledError, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.Cancel; // only 'OK' if not exception Close(); } } } }
public void ImportParatextExportBasic() { string path = Path.Combine(DirectoryFinder.FwSourceDirectory, @"LexText/Interlinear/ITextDllTests/FlexTextImport"); string file = Path.Combine(path, "FlexTextExportOutput.flextext"); using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read)) { LinguaLinksImport li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; var options = new LinguaLinksImport.ImportInterlinearOptions { Progress = new DummyProgressDlg(), BirdData = fileStream, AllottedProgress = 0, CheckAndAddLanguages = DummyCheckAndAddLanguagesInternal }; bool result = li.ImportInterlinear(options, ref text); Assert.True(result, "ImportInterlinear was not successful."); } }
public void TestImportCreatesPersonForSpeaker() { string xml = "<document><interlinear-text guid=\"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA\">" + "<item type=\"title\" lang=\"en\">wordspace</item>" + "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" + "<paragraphs><paragraph><phrases><phrase speaker=\"Jimmy Dorante\" media-file=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" guid=\"BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB\" begin-time-offset=\"1\" end-time-offset=\"2\">" + "<item type=\"text\">This is a test with text.</item><word>This</word></phrase></phrases></paragraph></paragraphs>" + "<languages><language lang=\"en\" font=\"latin\" vernacular=\"false\"/></languages>" + "<media-files offset-type=\"milliseconds\"><media guid=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" location=\"file:\\\\test.wav\"/></media-files></interlinear-text></document>"; LinguaLinksImport li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray()))) { li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text); Assert.AreEqual("Jimmy Dorante", (Cache.LanguageProject.PeopleOA.PossibilitiesOS[0] as ICmPerson).Name.get_String(Cache.DefaultVernWs).Text, "Speaker was not created during the import."); } }
public void TestEmptyParagraph() { string xml = "<document><interlinear-text>" + "<item type=\"title\" lang=\"en\">wordspace</item>" + "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" + "<paragraphs><paragraph/></paragraphs></interlinear-text></document>"; LinguaLinksImport li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray()))) { li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text); using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator()) { firstEntry.MoveNext(); var imported = firstEntry.Current; Assert.True(imported.ContentsOA.ParagraphsOS.Count > 0, "Empty paragraph was not imported as text content."); var para = imported.ContentsOA[0]; Assert.NotNull(para, "The imported paragraph is null?"); } } }
public void TestSpacesBetweenWords() { string xml = "<document><interlinear-text>" + "<item type=\"title\" lang=\"en\">wordspace</item>" + "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" + "<paragraphs><paragraph><phrases><phrase>" + "<item type=\"reference-number\" lang=\"en\">1 Musical</item>" + "<item type=\"note\" lang=\"pt\">origem: mary poppins</item>" + "<words><word><item type=\"txt\" lang=\"en\">a</item></word>" + "<word><item type=\"txt\" lang=\"en\">space</item></word>" + "<word><item type=\"txt\" lang=\"en\">space</item></word>" + "</words></phrase></phrases></paragraph></paragraphs></interlinear-text></document>"; LinguaLinksImport li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray()))) { li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text); using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator()) { firstEntry.MoveNext(); var imported = firstEntry.Current; var para = imported.ContentsOA[0]; var spaceOne = para.Contents.Text.Substring(1, 1); //should be: " " var wordAfter = para.Contents.Text.Substring(2, 5); //should be: "space" var spaceTwo = para.Contents.Text.Substring(7, 1); //should be: " " //test to make sure no space was inserted before the first word. Assert.IsFalse(" ".Equals(para.Contents.GetSubstring(0, 1))); //test to make sure spaces were inserted between "a" and "space", and between "space" and "space" //any extra spaces would result in the "space" word looking like " spac" Assert.IsTrue(spaceOne.Equals(spaceTwo)); Assert.IsTrue(wordAfter.Equals("space")); } } }
public void TestImportFullELANData() { const string xml = "<document><interlinear-text guid=\"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA\">" + "<item type=\"title\" lang=\"en\">wordspace</item>" + "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" + "<paragraphs><paragraph><phrases>" + "<phrase media-file=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" guid=\"BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB\" begin-time-offset=\"1\" end-time-offset=\"2\">" + "<item type=\"text\">This is a test with text.</item><word>This</word></phrase></phrases></paragraph></paragraphs>" + "<languages><language lang=\"en\" font=\"latin\" vernacular=\"false\"/></languages>" + @"<media-files offset-type=""milliseconds""><media guid=""FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"" location=""file:\\test.wav""/></media-files></interlinear-text></document>"; LinguaLinksImport li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray()))) { li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text); using (var firstEntry = Cache.LanguageProject.Texts.GetEnumerator()) { firstEntry.MoveNext(); var imported = firstEntry.Current; Assert.True(imported.ContentsOA.ParagraphsOS.Count > 0, "Paragraph was not imported as text content."); var para = imported.ContentsOA[0]; Assert.NotNull(para, "The imported paragraph is null?"); Assert.AreEqual(new Guid("BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB"), para.SegmentsOS[0].Guid, "Segment guid not maintained on import."); VerifyMediaLink(imported); } } }
public void UglyEmptyDataShouldNotCrash() { const string textGuid = "eb0770f4-23aa-4f7b-b45d-fe745a3790a2"; //an interliner text example xml string const string xml = "<document><interlinear-text guid='" + textGuid + "'>" + "<paragraphs><paragraph guid='819742f3-3840-479e-9300-51755880680b'/></paragraphs><languages/>" + "</interlinear-text></document>"; var li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; using(var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray()))) { Assert.DoesNotThrow(()=> li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text)); using(var firstEntry = Cache.LanguageProject.Texts.GetEnumerator()) { firstEntry.MoveNext(); var imported = firstEntry.Current; //The empty ugly text imported as its empty ugly self Assert.AreEqual(imported.Guid.ToString(), textGuid); } } }
public void ImportParatextExportBasic() { string path = Path.Combine(FwDirectoryFinder.SourceDirectory, @"LexText/Interlinear/ITextDllTests/FlexTextImport"); string file = Path.Combine(path, "FlexTextExportOutput.flextext"); using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read)) { LinguaLinksImport li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; var options = new LinguaLinksImport.ImportInterlinearOptions{Progress = new DummyProgressDlg(), BirdData = fileStream, AllottedProgress = 0, CheckAndAddLanguages = DummyCheckAndAddLanguagesInternal }; bool result = li.ImportInterlinear(options, ref text); Assert.True(result, "ImportInterlinear was not successful."); } }
private void btnImport_Click(object sender, EventArgs e) { // if the shift key is down, then just build the phaseNoutput files bool runToCompletion = ((ModifierKeys & Keys.Shift) != Keys.Shift); using (var dlg = new ProgressDialogWithTask(this)) { dlg.AllowCancel = true; LanguageMapping[] languageMappings = new LanguageMapping[listViewMapping.Items.Count]; for (int i = 0; i < listViewMapping.Items.Count; i++) languageMappings[i] = new LanguageMapping(listViewMapping.Items[i].SubItems); dlg.Minimum = 0; dlg.Maximum = 500; using (new WaitCursor(this, true)) { // This needs to be reset when cancel is pressed with out clicking the // browse button. This resolves a noted issue in the code where an exception // is processed when run a second time... m_nextInput = m_LinguaLinksXmlFileName.Text; var import = new LinguaLinksImport(m_cache, m_sTempDir, m_sRootDir); import.NextInput = m_nextInput; import.Error += OnImportError; Debug.Assert(m_nextInput == m_LinguaLinksXmlFileName.Text); // Ensure the idle time processing for change record doesn't cause problems // because the import creates a record to change to. See FWR-3700. var clerk = m_mediator.PropertyTable.GetValue("ActiveClerk") as RecordClerk; var fSuppressedSave = false; try { if (clerk != null) { fSuppressedSave = clerk.SuppressSaveOnChangeRecord; clerk.SuppressSaveOnChangeRecord = true; } bool fSuccess = (bool)dlg.RunTask(true, import.Import, runToCompletion, languageMappings, m_startPhase); if (fSuccess) { MessageBox.Show(this, String.Format(ITextStrings.ksSuccessLoadingLL, Path.GetFileName(m_LinguaLinksXmlFileName.Text), m_cache.ProjectId.Name, Environment.NewLine, import.LogFile), ITextStrings.ksLLImportSucceeded, MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; // only 'OK' if not exception } else { DialogResult = DialogResult.Abort; // unsuccessful import } Close(); m_nextInput = import.NextInput; } catch (WorkerThreadException ex) { if (ex.InnerException is InvalidDataException) { // Special handling for this case... ShowFinishLabel(); CheckImportEnabled(); } else { Debug.WriteLine("Error: " + ex.InnerException.Message); MessageBox.Show(String.Format(import.ErrorMessage, ex.InnerException.Message), ITextStrings.ksUnhandledError, MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; // only 'OK' if not exception Close(); } } finally { if (clerk != null) clerk.SuppressSaveOnChangeRecord = fSuppressedSave; } } } }
private void btnImport_Click(object sender, System.EventArgs e) { // if the shift key is down, then just build the phaseNoutput files bool runToCompletion = ((Control.ModifierKeys & Keys.Shift) != Keys.Shift); using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(this)) { dlg.CancelButtonVisible = true; LanguageMapping[] languageMappings = new LanguageMapping[listViewMapping.Items.Count]; for (int i = 0; i < listViewMapping.Items.Count; i++) { languageMappings[i] = new LanguageMapping(listViewMapping.Items[i].SubItems); } dlg.SetRange(0, 500); using (new WaitCursor(this, true)) { // This needs to be reset when cancel is pressed with out clicking the // browse button. This resolves a noted issue in the code where an exception // is processed when run a second time... m_nextInput = m_LinguaLinksXmlFileName.Text; LinguaLinksImport import = new LinguaLinksImport(m_cache, m_sTempDir, m_sRootDir); import.NextInput = m_nextInput; import.Error += new LinguaLinksImport.ErrorHandler(OnImportError); dlg.Cancel += new CancelHandler(import.On_ProgressDlg_Cancel); Debug.Assert(m_nextInput == m_LinguaLinksXmlFileName.Text); try { bool fSuccess = (bool)dlg.RunTask(true, new BackgroundTaskInvoker(import.Import), runToCompletion, languageMappings, m_startPhase); if (fSuccess) { string sLogFile = m_sTempDir + "LLPhase3Output-Import.log"; MessageBox.Show(this, String.Format(ITextStrings.ksSuccessLoadingLL, Path.GetFileName(m_LinguaLinksXmlFileName.Text), m_cache.DatabaseName, System.Environment.NewLine, sLogFile), ITextStrings.ksLLImportSucceeded, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; // only 'OK' if not exception } else { this.DialogResult = DialogResult.Abort; // unsuccessful import } Close(); m_nextInput = import.NextInput; } catch (WorkerThreadException ex) { if (ex.InnerException is InvalidDataException) { // Special handling for this case... ShowFinishLabel(); CheckImportEnabled(); } else { System.Diagnostics.Debug.WriteLine("Error: " + ex.InnerException.Message); MessageBox.Show(String.Format(import.ErrorMessage, ex.InnerException.Message), ITextStrings.ksUnhandledError, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.Cancel; // only 'OK' if not exception Close(); } } } } }
public void TestImportCreatesReusesExistingSpeaker() { string xml = "<document><interlinear-text guid=\"AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA\">" + "<item type=\"title\" lang=\"en\">wordspace</item>" + "<item type=\"title-abbreviation\" lang=\"en\">ws</item>" + "<paragraphs><paragraph><phrases><phrase speaker=\"Jimmy Dorante\" media-file=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" guid=\"BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB\" begin-time-offset=\"1\" end-time-offset=\"2\">" + "<item type=\"text\">This is a test with text.</item><word>This</word></phrase></phrases></paragraph></paragraphs>" + "<languages><language lang=\"en\" font=\"latin\" vernacular=\"false\"/></languages>" + "<media-files offset-type=\"milliseconds\"><media guid=\"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF\" location=\"file:\\\\test.wav\"/></media-files></interlinear-text></document>"; ICmPerson newPerson = null; //Create and add Jimmy to the project. NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () => { Cache.LanguageProject.PeopleOA = Cache.ServiceLocator.GetInstance<ICmPossibilityListFactory>().Create(); //person not found create one and add it. newPerson = Cache.ServiceLocator.GetInstance<ICmPersonFactory>().Create(); Cache.LanguageProject.PeopleOA.PossibilitiesOS.Add(newPerson); newPerson.Name.set_String(Cache.DefaultVernWs, "Jimmy Dorante"); }); Assert.NotNull(newPerson); LinguaLinksImport li = new LinguaLinksImport(Cache, null, null); FDO.IText text = null; using (var stream = new MemoryStream(Encoding.ASCII.GetBytes(xml.ToCharArray()))) { li.ImportInterlinear(new DummyProgressDlg(), stream, 0, ref text); //If the import sets the speaker in the segment to our Jimmy, and not a new Jimmy then all is well Assert.AreEqual(newPerson, text.ContentsOA[0].SegmentsOS[0].SpeakerRA, "Speaker not reused."); } }
private void btnImport_Click(object sender, System.EventArgs e) { // if the shift key is down, then just build the phaseNoutput files bool runToCompletion = ((Control.ModifierKeys & Keys.Shift) != Keys.Shift); using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(this)) { dlg.CancelButtonVisible = true; LanguageMapping[] languageMappings = new LanguageMapping[listViewMapping.Items.Count]; for (int i = 0; i < listViewMapping.Items.Count; i++) languageMappings[i] = new LanguageMapping(listViewMapping.Items[i].SubItems); dlg.SetRange(0, 500); using (new WaitCursor(this, true)) { // This needs to be reset when cancel is pressed with out clicking the // browse button. This resolves a noted issue in the code where an exception // is processed when run a second time... m_nextInput = m_LinguaLinksXmlFileName.Text; LinguaLinksImport import = new LinguaLinksImport(m_cache, m_sTempDir, m_sRootDir); import.NextInput = m_nextInput; import.Error += new LinguaLinksImport.ErrorHandler(OnImportError); dlg.Cancel += new CancelHandler(import.On_ProgressDlg_Cancel); Debug.Assert(m_nextInput == m_LinguaLinksXmlFileName.Text); try { bool fSuccess = (bool)dlg.RunTask(true, new BackgroundTaskInvoker(import.Import), runToCompletion, languageMappings, m_startPhase); if (fSuccess) { string sLogFile = m_sTempDir + "LLPhase3Output-Import.log"; MessageBox.Show(this, String.Format(ITextStrings.ksSuccessLoadingLL, Path.GetFileName(m_LinguaLinksXmlFileName.Text), m_cache.DatabaseName, System.Environment.NewLine, sLogFile), ITextStrings.ksLLImportSucceeded, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; // only 'OK' if not exception } else { this.DialogResult = DialogResult.Abort; // unsuccessful import } Close(); m_nextInput = import.NextInput; } catch (WorkerThreadException ex) { if (ex.InnerException is InvalidDataException) { // Special handling for this case... ShowFinishLabel(); CheckImportEnabled(); } else { System.Diagnostics.Debug.WriteLine("Error: " + ex.InnerException.Message); MessageBox.Show(String.Format(import.ErrorMessage, ex.InnerException.Message), ITextStrings.ksUnhandledError, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.Cancel; // only 'OK' if not exception Close(); } } } } }
private void btnImport_Click(object sender, EventArgs e) { // if the shift key is down, then just build the phaseNoutput files bool runToCompletion = ((ModifierKeys & Keys.Shift) != Keys.Shift); using (var dlg = new ProgressDialogWithTask(this, m_cache.ThreadHelper)) { dlg.AllowCancel = true; LanguageMapping[] languageMappings = new LanguageMapping[listViewMapping.Items.Count]; for (int i = 0; i < listViewMapping.Items.Count; i++) { languageMappings[i] = new LanguageMapping(listViewMapping.Items[i].SubItems); } dlg.Minimum = 0; dlg.Maximum = 500; using (new WaitCursor(this, true)) { // This needs to be reset when cancel is pressed with out clicking the // browse button. This resolves a noted issue in the code where an exception // is processed when run a second time... m_nextInput = m_LinguaLinksXmlFileName.Text; var import = new LinguaLinksImport(m_cache, m_sTempDir, m_sRootDir); import.NextInput = m_nextInput; import.Error += OnImportError; Debug.Assert(m_nextInput == m_LinguaLinksXmlFileName.Text); // Ensure the idle time processing for change record doesn't cause problems // because the import creates a record to change to. See FWR-3700. var clerk = m_mediator.PropertyTable.GetValue("ActiveClerk") as RecordClerk; var fSuppressedSave = false; try { if (clerk != null) { fSuppressedSave = clerk.SuppressSaveOnChangeRecord; clerk.SuppressSaveOnChangeRecord = true; } bool fSuccess = (bool)dlg.RunTask(true, import.Import, runToCompletion, languageMappings, m_startPhase); if (fSuccess) { MessageBox.Show(this, String.Format(ITextStrings.ksSuccessLoadingLL, Path.GetFileName(m_LinguaLinksXmlFileName.Text), m_cache.ProjectId.Name, Environment.NewLine, import.LogFile), ITextStrings.ksLLImportSucceeded, MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; // only 'OK' if not exception } else { DialogResult = DialogResult.Abort; // unsuccessful import } Close(); m_nextInput = import.NextInput; } catch (WorkerThreadException ex) { if (ex.InnerException is InvalidDataException) { // Special handling for this case... ShowFinishLabel(); CheckImportEnabled(); } else { Debug.WriteLine("Error: " + ex.InnerException.Message); MessageBox.Show(String.Format(import.ErrorMessage, ex.InnerException.Message), ITextStrings.ksUnhandledError, MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; // only 'OK' if not exception Close(); } } finally { if (clerk != null) { clerk.SuppressSaveOnChangeRecord = fSuppressedSave; } } } } }