コード例 #1
0
		protected override void OnFinishButton()
		{
			if (UsesInvalidFileNames(false))
				return;

			base.OnFinishButton();

			bool runToCompletion = true;
			int lastStep = 5;
			// if the shift key is down, then just build the phaseNoutput files
			if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
			{
				runToCompletion = false;
				lastStep = 4;
			}

			SaveSettings();

			using (var dlg = new ProgressDialogWithTask(this))
			{
				dlg.AllowCancel = true;
				dlg.Maximum = 200;
				using (new WaitCursor(this, true))
				{
					int startPhase = GetDictionaryFileAsPhaseFileNumber();	// see if starting with phase file
					// XSLT files
					string sTransformDir = Path.Combine(FwDirectoryFinder.CodeDirectory,
						String.Format("Language Explorer{0}Import{0}", Path.DirectorySeparatorChar));

					LexImport lexImport = new LexImport(m_cache, m_sTempDir, sTransformDir);
					lexImport.Error += OnImportError;
					bool fRet = (bool)dlg.RunTask(true, lexImport.Import,
						runToCompletion, lastStep, startPhase, m_DatabaseFileName.Text, m_cEntries,
						m_DisplayImportReport.Checked, m_sPhase1HtmlReport, LexImport.s_sPhase1FileName);

					if (fRet)
						DialogResult = DialogResult.OK;	// only 'OK' if not exception
				}
			}
		}
コード例 #2
0
ファイル: LexImportTests.cs プロジェクト: sillsdev/FieldWorks
		/// <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);
			}
		}
コード例 #3
0
ファイル: LexImportWizard.cs プロジェクト: sillsdev/WorldPad
		protected override void OnFinishButton()
		{
			if (UsesInvalidFileNames(false))
				return;

			base.OnFinishButton();

			bool runToCompletion = true;
			int lastStep = 5;
			// if the shift key is down, then just build the phaseNoutput files
			if ((Control.ModifierKeys & Keys.Shift) == Keys.Shift)
			{
				runToCompletion = false;
				lastStep = 4;
			}

			SaveSettings();

			using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(this))
			{
				dlg.CancelButtonVisible = true;
				dlg.Maximum = 200;
				dlg.Value = 0;
				using (new WaitCursor(this, true))
				{
					int startPhase = GetDictionaryFileAsPhaseFileNumber();	// see if starting with phase file
					// XSLT files
					string sTransformDir = Path.Combine(DirectoryFinder.FWCodeDirectory,
						"Language Explorer\\Import\\");

					LexImport lexImport = new LexImport(m_cache, m_sTempDir, sTransformDir);
					dlg.Cancel += new CancelHandler(lexImport.OnProgressDlgCancel);
					lexImport.Error += new LexImport.ErrorHandler(OnImportError);
					bool fRet = (bool)dlg.RunTask(true, new BackgroundTaskInvoker(lexImport.Import),
						runToCompletion, lastStep, startPhase, m_DatabaseFileName.Text, m_cEntries,
						m_DisplayImportReport.Checked, m_sPhase1HtmlReport, LexImport.s_sPhase1FileName);

					if (fRet)
						DialogResult = DialogResult.OK;	// only 'OK' if not exception
				}
			}
		}