Ejemplo n.º 1
0
		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();
					}
				}
			}
		}
Ejemplo n.º 2
0
		protected void DoExport(string outPath, bool fLiftOutput)
		{
			string fxtPath = (string)m_exportList.SelectedItems[0].Tag;
			FxtType ft = m_rgFxtTypes[FxtIndex(fxtPath)];
			using (new SIL.FieldWorks.Common.Utils.WaitCursor(this))
			{
				using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(this))
				{
					try
					{
						progressDlg.Title = String.Format(xWorksStrings.Exporting0,
							m_exportList.SelectedItems[0].SubItems[0].Text);
						progressDlg.Message = xWorksStrings.Exporting_;

						switch (ft.m_ft)
						{
							case FxtTypes.kftFxt:
								using (m_dumper = new XDumper(m_cache))
								{
									m_dumper.UpdateProgress +=
										new XDumper.ProgressHandler(OnDumperUpdateProgress);
									m_dumper.SetProgressMessage +=
										new EventHandler<XDumper.MessageArgs>(OnDumperSetProgressMessage);
									progressDlg.SetRange(0, m_dumper.GetProgressMaximum());
									progressDlg.CancelButtonVisible = true;
									progressDlg.Restartable = true;
									progressDlg.ProgressBarStyle = ProgressBarStyle.Continuous;
									progressDlg.Cancel += new CancelHandler(Onm_progressDlg_Cancel);

									progressDlg.RunTask(true, new BackgroundTaskInvoker(ExportFxt),
										outPath, fxtPath, fLiftOutput);
								}
								break;
							case FxtTypes.kftConfigured:
							case FxtTypes.kftReversal:
								progressDlg.SetRange(0, m_seqView.ObjectCount);
								progressDlg.CancelButtonVisible = true;
								progressDlg.Cancel += new CancelHandler(ce_Cancel);

								progressDlg.RunTask(true, new BackgroundTaskInvoker(ExportConfiguredDocView),
									outPath, fxtPath, ft);
								break;
						}
					}
					catch (WorkerThreadException e)
					{
						if (e.InnerException is CancelException)
						{
							MessageBox.Show(this, e.InnerException.Message);
							m_ce = null;
						}
						else
						{
							string msg = xWorksStrings.ErrorExporting_ProbablyBug + "\n" + e.InnerException.Message;
							MessageBox.Show(this, msg);
						}
					}
					finally
					{
						m_progressDlg = null;
						m_dumper = null;
						this.Close();
					}
				}
			}
		}
Ejemplo n.º 3
0
		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();
						}
					}
				}
			}
		}
Ejemplo n.º 4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Export all of scripture
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void ExportScripture()
		{
			int sectionCount = 0;
			for (int i = 0; i < m_bookFilter.BookCount; i++)
				sectionCount += m_bookFilter.GetBook(i).SectionsOS.Count;
			using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(Form.ActiveForm))
			{
				progressDlg.SetRange(0, sectionCount);
				progressDlg.Title = DlgResources.ResourceString("kstidExportXmlProgress");
				progressDlg.CancelButtonVisible = true;
				progressDlg.Cancel += new CancelHandler(OnExportCancel);

				progressDlg.RunTask(true, new BackgroundTaskInvoker(ExportScripture));
			}
		}
Ejemplo n.º 5
0
		private void DoImport()
		{
			using (new SuppressSubTasks(m_cache, true, true))
			{
				using (new SIL.FieldWorks.Common.Utils.WaitCursor(this))
				{
					using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(this))
					{
						progressDlg.SetRange(0, 100);
						//progressDlg.CancelButtonVisible = true;
						progressDlg.ProgressBarStyle = ProgressBarStyle.Continuous;
						progressDlg.Restartable = true;
						progressDlg.Title = String.Format(LexTextControls.ksImportingFrom0, tbPath.Text);
						progressDlg.Cancel += new CancelHandler(progressDlg_Cancel);
						m_fCancelNow = false;
						m_sLogFile = (string)progressDlg.RunTask(true, new BackgroundTaskInvoker(ImportLIFT), tbPath.Text);
					}
				}
			}
		}
Ejemplo n.º 6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// When the footnote sequence option changes, all of the existing footnotes in the
		/// database will need to be updated.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void RedoFootnoteSequencing()
		{
			// Show a progress dialog for this operation
			using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(this))
			{
				progressDlg.SetRange(0, m_scr.ScriptureBooksOS.Count);
				progressDlg.Title = DlgResources.ResourceString("kstidFootnoteResequenceCaption");
				progressDlg.CancelButtonVisible = false;

				progressDlg.RunTask(true, new BackgroundTaskInvoker(RedoFootnoteSequencing));
			}
		}
Ejemplo n.º 7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// When the verse bridge character changes, this will update all of the verse bridges
		/// in scripture.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void UpdateVerseBridges(string oldBridge)
		{
			// Show a progress dialog for this operation
			using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(this))
			{
				progressDlg.SetRange(0, m_scr.ScriptureBooksOS.Count);
				progressDlg.Title = DlgResources.ResourceString("kstidUpdateVerseBridges");
				progressDlg.CancelButtonVisible = false;

				progressDlg.RunTask(true, new BackgroundTaskInvoker(UpdateVerseBridges), oldBridge);
			}
		}
Ejemplo n.º 8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// When Script number options have changed, all of the chapter and verse numbers in the
		/// database will be updated.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected void ConvertChapterVerseNumbers()
		{
			// Show a progress dialog for this operation
			using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(this))
			{

				progressDlg.SetRange(0, m_scr.ScriptureBooksOS.Count);
				progressDlg.Title = DlgResources.ResourceString("kstidConvertChapterVerseNumbersCaption");
				progressDlg.CancelButtonVisible = false;

				progressDlg.RunTask(true, new BackgroundTaskInvoker(ConvertChapterVerseNumbers));
			}
		}
Ejemplo n.º 9
0
		private void ExportLiftData(string outPath)
		{
			// TODO: if file exists, read it to obtain the list of entries it contains, including
			// deleted entries.  Then use this information in exporting to identify deleted entries
			// in the LIFT file.  This will require something other than FXT to export LIFT files.
			using (m_progressDlg = new ProgressDialogWithTask(this))
			{
				m_progressDlg.CancelButtonVisible = true;
				m_progressDlg.Restartable = true;
				m_progressDlg.Cancel += new CancelHandler(OnProgressDlgCancel);
				m_progressDlg.Message = "Exporting data in preparation for synchronization";
				using (m_dumper = new SIL.FieldWorks.Common.FXT.XDumper(m_cache))
				{
					m_dumper.UpdateProgress += new XDumper.ProgressHandler(OnDumperUpdateProgress);
					m_progressDlg.SetRange(0, m_dumper.GetProgressMaximum());
					m_progressDlg.RunTask(true, new BackgroundTaskInvoker(ExportLift), outPath);
				}
			}
			m_progressDlg = null;
		}
Ejemplo n.º 10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Run the export
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public void Run()
		{
			CheckDisposed();

			bool[] writeFiles = new bool[m_bookFilter.BookCount];
			if (m_splitByBook)
			{
				for (int bookIndex = 0; bookIndex < m_bookFilter.BookCount; bookIndex++)
				{
					writeFiles[bookIndex] = true;
					string filename = GetExportFileSpec(bookIndex);

					// if user hasn't indicated they want to overwrite the file and the file exists...
					if (!m_overwriteAll && File.Exists(filename))
					{
						// and there is more than one book to export...
						if (m_bookFilter.BookCount > 1)
						{
							// determine options for overwriting file(s).
							using (FilesOverwriteDialog dlg = new FilesOverwriteDialog(filename))
							{
								DialogResult result = dlg.ShowDialog();
								switch (result)
								{
									// overwrite all files ("Yes to all")
									case DialogResult.OK:
										// Don't set m_overwriteAll here since that would also overwrite
										// the files the user already said not to overwrite.
										for (int i = bookIndex; i < m_bookFilter.BookCount; i++)
											writeFiles[i] = true;
										bookIndex = m_bookFilter.BookCount;
										break;
									// overwrite current file
									case DialogResult.Yes:
										writeFiles[bookIndex] = true;
										break;
									// do not overwrite this file
									case DialogResult.No:
										writeFiles[bookIndex] = false;
										break;
									// do not overwrite any file ("No to All")
									case DialogResult.Cancel:
									default:
										for (int i = bookIndex; i < m_bookFilter.BookCount; i++)
											writeFiles[i] = false;
										bookIndex = m_bookFilter.BookCount;
										break;
								}
							}
						}
						else // only one file: use simple confirmation dialog
						{
							DialogResult result = MessageBox.Show(Form.ActiveForm,
								m_outputSpec + Environment.NewLine + TeResourceHelper.GetResourceString("kstidFileExists"),
								"", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
							writeFiles[bookIndex] = (result == DialogResult.Yes);
						}
					}
				}
			}
			else
			{
				if (File.Exists(m_outputSpec))
				{
					// File exists. Determine if user wants to overwrite it.
					DialogResult result = MessageBox.Show(Form.ActiveForm,
						m_outputSpec + Environment.NewLine + TeResourceHelper.GetResourceString("kstidFileExists"),
						"", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
					if (result != DialogResult.Yes)
						return;
				}
			}

			using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(Form.ActiveForm))
			{
				try
				{
					// count up the number of sections in the filtered books so the progress bar
					// can increment once for each section
					int sectionCount = 0;
					for (int i = 0; i < m_bookFilter.BookCount; i++)
					{
						if (writeFiles[i] || !m_splitByBook)
							sectionCount += m_bookFilter.GetBook(i).SectionsOS.Count;
					}
					progressDlg.SetRange(0, sectionCount + 1);
					progressDlg.Title = DlgResources.ResourceString("kstidExportUSFMProgress");
					progressDlg.CancelButtonVisible = true;
					progressDlg.Cancel += new CancelHandler(OnExportCancel);

					progressDlg.RunTask(true, new BackgroundTaskInvoker(Export), writeFiles);
				}
				catch (WorkerThreadException e)
				{
					if (e.InnerException is InvalidOrMissingStyFileException)
					{
						string msg = string.Format(
							TeResourceHelper.GetResourceString("kstidExportUsfmErrorTryReinstall"),
							e.InnerException.Message);
						MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK,
							MessageBoxIcon.Error);
					}
					else if (e.InnerException is UnauthorizedAccessException)
					{
						string msg = string.Format(TeResourceHelper.GetResourceString("kstidExportUsfmFileError"),
							e.InnerException.Message);
						MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK,
							MessageBoxIcon.Error);
					}
					else
					{
						throw new SIL.Utils.ContinuableErrorException("Unknown exception during export.", e);
					}
				}
				finally
				{
					CloseFile();
				}
			}
		}