/// <summary> /// Handles the DoWork event of the worker control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev05, 2007-08-31</remarks> void worker_DoWork(object sender, DoWorkEventArgs e) { try { Start(); object[] arguments = (object[])e.Argument; DAL.Interfaces.IDictionary dictionary = (DAL.Interfaces.IDictionary)arguments[0]; List <List <string> > data = (List <List <string> >)arguments[1]; IChapter chapter = (IChapter)arguments[2]; Dictionary <Field, int> fields = (Dictionary <Field, int>)arguments[3]; BackgroundWorker worker = (BackgroundWorker)sender; MLifter.DAL.ImportExport.Importer.ImportToDictionary(dictionary, data, chapter, fields, worker, start, checkBoxSplitSynonyms.Checked); } catch (Exception exp) { ((BackgroundWorker)sender).RunWorkerCompleted -= new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); System.Diagnostics.Debug.WriteLine("Import failed: " + Environment.NewLine + exp.ToString()); Finished(false); } }
//�Internal�Methods�(2)� /// <summary> /// Converts an ODF to an ODX file. /// </summary> /// <param name="filename">The filename.</param> /// <returns></returns> /// <remarks>Documented by Dev03, 2007-10-01</remarks> internal string FromOdf(string filename) { string dictionaryPath = String.Empty; string temporaryPath = String.Empty; DAL.Interfaces.IDictionary dictionary = null; m_LoadMsg.InfoMessage = Resources.DIC_IMPORT_OLD_TEXT; m_LoadMsg.SetProgress(0); Cursor.Current = Cursors.WaitCursor; m_LoadMsg.Show(); try { BackgroundWorker backgroundWorker = new BackgroundWorker(); backgroundWorker.WorkerReportsProgress = true; backgroundWorker.WorkerSupportsCancellation = true; backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(Convert_ProgressChanged); Converter converter = new Converter(backgroundWorker); converter.ApplicationPath = Application.StartupPath; temporaryPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + DAL.Helper.OdxExtension); converter.SourceEncoding = Encoding.Default; //this not a 100% clean solution converter.LoginCallback = (MLifter.DAL.GetLoginInformation)LoginForm.OpenLoginForm; dictionary = converter.Load(filename, temporaryPath); } catch (DAL.DictionaryFormatNotSupported) { if (dictionary != null) { dictionary.Dispose(); } MessageBox.Show(Resources.DIC_NOT_SUPPORTED_TEXT, Resources.DIC_NOT_SUPPORTED_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } catch (DAL.InvalidImportFormatException) { if (dictionary != null) { dictionary.Dispose(); } MessageBox.Show(String.Format(Resources.DIC_INVALID_FORMAT_TEXT, filename), Resources.DIC_MEDIA_ERROR_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } finally { if (dictionary != null) { dictionary.Dispose(); } Cursor.Current = Cursors.Default; m_LoadMsg.Hide(); } string dictionaryBasePath = Settings.Default.DicDir; string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filename); // Ask user for target directory dictionaryPath = Path.Combine(dictionaryBasePath, fileNameWithoutExtension); try { if (!Directory.Exists(dictionaryPath)) { Directory.CreateDirectory(dictionaryPath); } } catch { dictionaryPath = dictionaryBasePath; } bool pathExists = false; bool overwrite = false; DirDialog.SelectedPath = dictionaryPath; do { if (DirDialog.ShowDialog(m_LoadMsg) == DialogResult.OK) { dictionaryPath = DirDialog.SelectedPath; } else { return(null); } if (File.Exists(Path.Combine(dictionaryPath, fileNameWithoutExtension + DAL.Helper.OdxExtension))) { pathExists = true; DialogResult result = MLifter.Controls.TaskDialog.ShowTaskDialogBox(Resources.CONVERT_DICTIONARY_EXISTS_MBX_CAPTION, Resources.CONVERT_DICTIONARY_EXISTS_MBX_TEXT, Resources.CONVERT_DICTIONARY_EXISTS_MBX_CONTENT, String.Empty, String.Empty, String.Empty, String.Empty, String.Format("{0}|{1}|{2}", Resources.CONVERT_DICTIONARY_EXISTS_MBX_OPTION_YES, Resources.CONVERT_DICTIONARY_EXISTS_MBX_OPTION_NO, Resources.CONVERT_DICTIONARY_EXISTS_MBX_OPTION_CANCEL), MLifter.Controls.TaskDialogButtons.None, MLifter.Controls.TaskDialogIcons.Question, MLifter.Controls.TaskDialogIcons.Warning); switch (MLifter.Controls.TaskDialog.CommandButtonResult) { case 0: break; case 2: continue; case 1: default: return(null); } } else if (Directory.GetFiles(dictionaryPath, "*" + DAL.Helper.OdxExtension).Length > 0) { pathExists = true; DialogResult result = MLifter.Controls.TaskDialog.ShowTaskDialogBox(Resources.CONVERT_DICTIONARY_FOLDER_EXISTS_MBX_CAPTION, Resources.CONVERT_DICTIONARY_FOLDER_EXISTS_MBX_TEXT, Resources.CONVERT_DICTIONARY_FOLDER_EXISTS_MBX_CONTENT, String.Empty, String.Empty, String.Empty, String.Empty, String.Format("{0}|{1}|{2}", Resources.CONVERT_DICTIONARY_FOLDER_EXISTS_MBX_OPTION_YES, Resources.CONVERT_DICTIONARY_FOLDER_EXISTS_MBX_OPTION_NO, Resources.CONVERT_DICTIONARY_FOLDER_EXISTS_MBX_OPTION_CANCEL), MLifter.Controls.TaskDialogButtons.None, MLifter.Controls.TaskDialogIcons.Warning, MLifter.Controls.TaskDialogIcons.Warning); switch (MLifter.Controls.TaskDialog.CommandButtonResult) { case 0: break; case 2: continue; case 1: default: return(null); } } pathExists = false; }while (pathExists); dictionaryPath = Path.Combine(dictionaryPath, fileNameWithoutExtension + DAL.Helper.OdxExtension); m_LoadMsg.InfoMessage = Resources.CONVERT_TMOVEMSG; m_LoadMsg.SetProgress(0); Cursor.Current = Cursors.WaitCursor; m_LoadMsg.Show(); try { BackgroundWorker backgroundWorker = new BackgroundWorker(); backgroundWorker.WorkerReportsProgress = true; backgroundWorker.WorkerSupportsCancellation = true; backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(Move_ProgressChanged); dictionary.BackgroundWorker = backgroundWorker; dictionary.Move(dictionaryPath, overwrite); } finally { if (dictionary != null) { dictionary.Dispose(); } Cursor.Current = Cursors.Default; m_LoadMsg.Hide(); } return(dictionaryPath); }
/// <summary> /// This method unpacks arrayList dictionary in arrayList dzp file (ZIP). /// Unit Test necessary /// </summary> /// <param name="filename">name of file to extract</param> /// <returns>The dictionary path.</returns> /// <remarks>Documented by Dev04, 2007-07-19</remarks> internal string UnpackDic(string filename) { DialogResult dialogResult; bool ignoreInvalidHeader = false; string dictionaryPath = String.Empty; DAL.Interfaces.IDictionary dictionary = null; string fileNameWithoutExtension = String.Empty; if (!DAL.Pack.Packer.IsValidArchive(filename)) { TaskDialog.ShowTaskDialogBox(Resources.UNPACK_NOT_ORIGINAL_CAPTION, Resources.UNPACK_NOT_ORIGINAL_TEXT, Resources.UNPACK_NOT_ORIGINAL_CONTENT, string.Empty, string.Empty, string.Empty, string.Empty, Resources.UNPACK_NOT_ORIGINAL_OPTION_YES + "|" + Resources.UNPACK_NOT_ORIGINAL_OPTION_NO, TaskDialogButtons.None, TaskDialogIcons.Question, TaskDialogIcons.Information); switch (TaskDialog.CommandButtonResult) { case 1: default: return(String.Empty); case 0: ignoreInvalidHeader = true; break; } } fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filename); dictionaryPath = GenerateDictionaryPath(filename); dialogResult = MLifter.Controls.TaskDialog.ShowTaskDialogBox(Resources.UNPACK_DEFAULT_MBX_CAPTION, Resources.UNPACK_DEFAULT_MBX_TEXT, String.Format(Resources.UNPACK_DEFAULT_MBX_CONTENT, dictionaryPath), String.Empty, String.Empty, String.Empty, String.Empty, String.Format("{0}|{1}|{2}", Resources.UNPACK_DEFAULT_OPTION_YES, Resources.UNPACK_DEFAULT_MBX_OPTION_NO, Resources.UNPACK_DEFAULT_MBX_OPTION_CANCEL), MLifter.Controls.TaskDialogButtons.None, MLifter.Controls.TaskDialogIcons.Question, MLifter.Controls.TaskDialogIcons.Warning); switch (MLifter.Controls.TaskDialog.CommandButtonResult) { case 0: break; case 1: if (Directory.Exists(dictionaryPath)) { DirDialog.SelectedPath = dictionaryPath; } else { DirDialog.SelectedPath = Settings.Default.DicDir; } if (DirDialog.ShowDialog(m_LoadMsg) == DialogResult.OK) { dictionaryPath = DirDialog.SelectedPath; } else { return(String.Empty); } break; case 2: default: return(String.Empty); } try { if (!Directory.Exists(dictionaryPath)) { Directory.CreateDirectory(dictionaryPath); } } catch { dictionaryPath = Settings.Default.DicDir; } bool ignore = false; bool pathExists = false; do { if (File.Exists(Path.Combine(dictionaryPath, fileNameWithoutExtension + DAL.Helper.OdxExtension))) { pathExists = true; dialogResult = MLifter.Controls.TaskDialog.ShowTaskDialogBox(Resources.UNPACK_DICTIONARY_EXISTS_MBX_CAPTION, Resources.UNPACK_REPLACE_FILES_MBX_TEXT, Resources.UNPACK_DICTIONARY_EXISTS_MBX_CONTENT, String.Empty, String.Empty, String.Empty, String.Empty, String.Format("{0}|{1}|{2}", Resources.UNPACK_DICTIONARY_EXISTS_MBX_OPTION_YES, Resources.UNPACK_DICTIONARY_EXISTS_MBX_OPTION_NO, Resources.UNPACK_DICTIONARY_EXISTS_MBX_OPTION_CANCEL), MLifter.Controls.TaskDialogButtons.None, MLifter.Controls.TaskDialogIcons.Question, MLifter.Controls.TaskDialogIcons.Warning); switch (MLifter.Controls.TaskDialog.CommandButtonResult) { case 0: ignore = true; break; case 2: DirDialog.SelectedPath = dictionaryPath; if (DirDialog.ShowDialog(m_LoadMsg) == DialogResult.OK) { dictionaryPath = DirDialog.SelectedPath; } else { return(String.Empty); } continue; case 1: default: return(String.Empty); } } else if (Directory.GetFiles(dictionaryPath, "*" + DAL.Helper.OdxExtension).Length > 0) { pathExists = true; dialogResult = MLifter.Controls.TaskDialog.ShowTaskDialogBox(Resources.UNPACK_DICTIONARY_FOLDER_EXISTS_MBX_CAPTION, Resources.UNPACK_DICTIONARY_FOLDER_EXISTS_MBX_TEXT, Resources.UNPACK_DICTIONARY_FOLDER_EXISTS_MBX_CONTENT, String.Empty, String.Empty, String.Empty, String.Empty, String.Format("{0}|{1}|{2}", Resources.UNPACK_DICTIONARY_FOLDER_EXISTS_MBX_OPTION_YES, Resources.UNPACK_DICTIONARY_FOLDER_EXISTS_MBX_OPTION_NO, Resources.UNPACK_DICTIONARY_FOLDER_EXISTS_MBX_OPTION_CANCEL), MLifter.Controls.TaskDialogButtons.None, MLifter.Controls.TaskDialogIcons.Warning, MLifter.Controls.TaskDialogIcons.Warning); switch (MLifter.Controls.TaskDialog.CommandButtonResult) { case 0: ignore = true; break; case 2: DirDialog.SelectedPath = dictionaryPath; if (DirDialog.ShowDialog(m_LoadMsg) == DialogResult.OK) { dictionaryPath = DirDialog.SelectedPath; } else { return(String.Empty); } break; case 1: default: return(String.Empty); } } else { pathExists = false; } }while (pathExists && !ignore); m_LoadMsg.InfoMessage = Resources.UNPACK_TLOADMSG; m_LoadMsg.SetProgress(0); Cursor.Current = Cursors.WaitCursor; m_LoadMsg.Show(); try { BackgroundWorker backgroundWorker = new BackgroundWorker(); backgroundWorker.WorkerReportsProgress = true; backgroundWorker.WorkerSupportsCancellation = true; backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(Unzip_ProgressChanged); MLifter.DAL.Pack.Packer packer = new MLifter.DAL.Pack.Packer(backgroundWorker); packer.TemporaryFolder = dictionaryPath; packer.LoginCallback = (MLifter.DAL.GetLoginInformation)LoginForm.OpenLoginForm; dictionary = packer.Unpack(filename, ignoreInvalidHeader); //dictionaryPath = Path.Combine(dictionaryPath, fileNameWithoutExtension + DAL.DictionaryFactory.OdxExtension); dictionaryPath = dictionary.Connection; } catch (DAL.NoValidArchiveHeaderException ex) { Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message); if (dictionary != null) { dictionary.Dispose(); } MessageBox.Show(String.Format(Properties.Resources.DIC_ERROR_LOADING_TEXT, filename), Properties.Resources.DIC_ERROR_LOADING_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return(String.Empty); } catch (DAL.NoValidArchiveException ex) { Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message); if (dictionary != null) { dictionary.Dispose(); } MessageBox.Show(String.Format(Properties.Resources.DIC_ERROR_LOADING_TEXT, filename), Properties.Resources.DIC_ERROR_LOADING_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return(String.Empty); } catch (System.Xml.XmlException ex) { Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message); if (dictionary != null) { dictionary.Dispose(); } MessageBox.Show(String.Format(Properties.Resources.DIC_ERROR_LOADING_TEXT, filename), Properties.Resources.DIC_ERROR_LOADING_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return(String.Empty); } catch (IOException ex) { Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message); if (dictionary != null) { dictionary.Dispose(); } MessageBox.Show(String.Format(Properties.Resources.DIC_ERROR_LOADING_TEXT, filename), Properties.Resources.DIC_ERROR_LOADING_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return(String.Empty); } catch (ICSharpCode.SharpZipLib.Zip.ZipException ex) { Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message); if (dictionary != null) { dictionary.Dispose(); } MessageBox.Show(String.Format(Properties.Resources.DIC_ERROR_LOADING_TEXT, filename), Properties.Resources.DIC_ERROR_LOADING_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error); return(String.Empty); } catch (MLifter.DAL.DictionaryFormatNotSupported ex) { Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message); if (dictionary != null) { dictionary.Dispose(); } MessageBox.Show(Properties.Resources.DIC_ERROR_NEWERVERSION_TEXT, Properties.Resources.DIC_ERROR_NEWERVERSION_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); return(String.Empty); } catch (MLifter.DAL.DictionaryNotDecryptedException ex) { Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message); if (dictionary != null) { dictionary.Dispose(); } MessageBox.Show(Properties.Resources.DIC_ERROR_NOT_DECRYPTED_TEXT, Properties.Resources.DIC_ERROR_NOT_DECRYPTED_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Information); return(String.Empty); } finally { if (dictionary != null) { dictionary.Dispose(); } Cursor.Current = Cursors.Default; m_LoadMsg.Hide(); } return(dictionaryPath); }