Beispiel #1
0
		/// <summary>
		/// This messy process simulates what the real import wizard does to import a string like input,
		/// with the given field mappings, and verifies that it produces the expected number of new lexEntries.
		/// </summary>
		/// <param name="input"></param>
		/// <param name="sfmInfo"></param>
		/// <param name="expectedCreations"></param>
		private void DoImport(string input, List<FieldHierarchyInfo> sfmInfo, int expectedCreations)
		{
			var tempLocation = Path.GetTempFileName();
			File.Delete(tempLocation);
			var tempDir = Path.ChangeExtension(tempLocation, "") + Path.DirectorySeparatorChar;
			Directory.CreateDirectory(tempDir);
			try
			{
				string sTransformDir = Path.Combine(FwDirectoryFinder.CodeDirectory,
					String.Format("Language Explorer{0}Import{0}", Path.DirectorySeparatorChar));
				var sut = new LexImport(Cache, tempDir, sTransformDir);

				string databaseFileName = Path.GetTempFileName();
				File.WriteAllText(databaseFileName, input, Encoding.UTF8);

				var entryRepo = Cache.ServiceLocator.GetInstance<ILexEntryRepository>();
				// JohnT: I don't know why this is needed, the base class is supposed to Undo anything we create.
				// But somehow things are getting left over from one test and messing up another.
				foreach (var entry in entryRepo.AllInstances())
					entry.Delete();
				Assert.That(entryRepo.AllInstances().Count(), Is.EqualTo(0));

				// Create the map file that controls the import

				var uiLangsNew = new Hashtable();
				var infoEn = new LanguageInfoUI("English", "English", "", "en");
				var vernId = Cache.LangProject.DefaultVernacularWritingSystem.Id;
				var infoV = new LanguageInfoUI("Vernacular", "Vern", "", vernId);
				uiLangsNew[infoEn.Key] = infoEn;
				uiLangsNew["Vernacular"] = infoV;

				var lexFields = new LexImportFields();
				lexFields.ReadLexImportFields(sTransformDir + "ImportFields.xml");
				var customFields = new LexImportFields();

				var ifMarker = new List<ClsInFieldMarker>();
				string mapFile = Path.GetTempFileName();

				STATICS.NewMapFileBuilder(uiLangsNew, lexFields, customFields, sfmInfo, ifMarker, mapFile);

				var phase1Output = Path.Combine(tempDir, LexImport.s_sPhase1FileName);

				var converter = new LexImportWizard.FlexConverter(Cache);
				converter.AddPossibleAutoField("Entry", "eires"); // found these by running an example.
				converter.AddPossibleAutoField("Sense", "sires");
				converter.AddPossibleAutoField("Subentry", "seires");
				converter.AddPossibleAutoField("Variant", "veires");
				converter.Convert(databaseFileName, mapFile, phase1Output);

				m_actionHandler.EndUndoTask(); // import starts its own.

				sut.Import(new DummyProgressDlg(), new object[]
				{
					true, // run to completion
					5, // last step to execute => all of them
					0, // phase already completed
					phase1Output,
					3, // lex entries in file
					false, // don't want to display import report
					"", // phase 1 html report, only used in generating messages, I think.
					LexImport.s_sPhase1FileName // required always
				});
				Assert.That(entryRepo.AllInstances().Count(), Is.EqualTo(expectedCreations), "wrong number of entries created");

			}
			finally
			{
				Directory.Delete(tempDir, true);
			}
		}
Beispiel #2
0
        /// <summary>
        /// This messy process simulates what the real import wizard does to import a string like input,
        /// with the given field mappings, and verifies that it produces the expected number of new lexEntries.
        /// </summary>
        /// <param name="input"></param>
        /// <param name="sfmInfo"></param>
        /// <param name="expectedCreations"></param>
        private void DoImport(string input, List <FieldHierarchyInfo> sfmInfo, int expectedCreations)
        {
            var tempLocation = Path.GetTempFileName();

            File.Delete(tempLocation);
            var tempDir = Path.ChangeExtension(tempLocation, "") + Path.DirectorySeparatorChar;

            Directory.CreateDirectory(tempDir);
            try
            {
                string sTransformDir = Path.Combine(FwDirectoryFinder.CodeDirectory,
                                                    String.Format("Language Explorer{0}Import{0}", Path.DirectorySeparatorChar));
                var sut = new LexImport(Cache, tempDir, sTransformDir);

                string databaseFileName = Path.GetTempFileName();
                File.WriteAllText(databaseFileName, input, Encoding.UTF8);

                var entryRepo = Cache.ServiceLocator.GetInstance <ILexEntryRepository>();
                // JohnT: I don't know why this is needed, the base class is supposed to Undo anything we create.
                // But somehow things are getting left over from one test and messing up another.
                foreach (var entry in entryRepo.AllInstances())
                {
                    entry.Delete();
                }
                Assert.That(entryRepo.AllInstances().Count(), Is.EqualTo(0));

                // Create the map file that controls the import

                var uiLangsNew = new Hashtable();
                var infoEn     = new LanguageInfoUI("English", "English", "", "en");
                var vernId     = Cache.LangProject.DefaultVernacularWritingSystem.Id;
                var infoV      = new LanguageInfoUI("Vernacular", "Vern", "", vernId);
                uiLangsNew[infoEn.Key]   = infoEn;
                uiLangsNew["Vernacular"] = infoV;

                var lexFields = new LexImportFields();
                lexFields.ReadLexImportFields(sTransformDir + "ImportFields.xml");
                var customFields = new LexImportFields();

                var    ifMarker = new List <ClsInFieldMarker>();
                string mapFile  = Path.GetTempFileName();

                STATICS.NewMapFileBuilder(uiLangsNew, lexFields, customFields, sfmInfo, ifMarker, mapFile);

                var phase1Output = Path.Combine(tempDir, LexImport.s_sPhase1FileName);

                var converter = new LexImportWizard.FlexConverter(Cache);
                converter.AddPossibleAutoField("Entry", "eires");                 // found these by running an example.
                converter.AddPossibleAutoField("Sense", "sires");
                converter.AddPossibleAutoField("Subentry", "seires");
                converter.AddPossibleAutoField("Variant", "veires");
                converter.Convert(databaseFileName, mapFile, phase1Output);

                m_actionHandler.EndUndoTask();                 // import starts its own.

                sut.Import(new DummyProgressDlg(), new object[]
                {
                    true,                       // run to completion
                    5,                          // last step to execute => all of them
                    0,                          // phase already completed
                    phase1Output,
                    3,                          // lex entries in file
                    false,                      // don't want to display import report
                    "",                         // phase 1 html report, only used in generating messages, I think.
                    LexImport.s_sPhase1FileName // required always
                });
                Assert.That(entryRepo.AllInstances().Count(), Is.EqualTo(expectedCreations), "wrong number of entries created");
            }
            finally
            {
                Directory.Delete(tempDir, true);
            }
        }
		private void btnAddLangDesc_Click(object sender, EventArgs e)
		{
			using (var dlg = new LexImportWizardLanguage(m_cache, m_uiLangs, m_helpTopicProvider, m_app, m_stylesheet))
			{
			if (dlg.ShowDialog(this) == DialogResult.OK)
			{
				string langDesc, ws, ec, wsId;
				// retrieve the new WS information from the dlg
				dlg.GetCurrentLangInfo(out langDesc, out ws, out ec, out wsId);

				// now put the lang info into the language list view
				if (LexImportWizard.Wizard().AddLanguage(langDesc, ws, ec, wsId))
				{
					// this was added to the list of languages, so add it to the dlg and select it
					var langInfo = new LanguageInfoUI(langDesc, ws, ec, wsId);
					if (cbLangDesc.FindStringExact(langInfo.ToString()) < 0)
					{
						cbLangDesc.Items.Add(langInfo);
					}
					cbLangDesc.SelectedItem = langInfo;
					}
				}
			}
		}