예제 #1
0
        /// <summary>
        /// This method packs arrayList dictionary in arrayList dzp file (ZIP).
        /// It just collects all Media-files from the root-directory (= directory where the odx-file is located)
        /// and all Media-files from the sub-folders.
        /// Unit Test necessary
        /// </summary>
        /// <remarks>Documented by Dev04, 2007-07-19</remarks>
        internal void PackDic()
        {
            SaveDialog.Title    = Resources.PACKDIC_SAVEDIALOG_TITLE;
            SaveDialog.FileName = Path.GetFileNameWithoutExtension(Dictionary.DictionaryPath) + DAL.Pack.Packer.Extension;
            if (SaveDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //m_LoadMsg = new LoadStatusMessage(Resources.PACK_TLOADMSG, 100, true);
            m_LoadMsg.InfoMessage = Resources.PACK_TLOADMSG;
            m_LoadMsg.SetProgress(0);
            Cursor.Current = Cursors.WaitCursor;
            m_LoadMsg.Show();

            BackgroundWorker backgroundWorker = new BackgroundWorker();

            backgroundWorker.WorkerReportsProgress      = true;
            backgroundWorker.WorkerSupportsCancellation = true;
            backgroundWorker.ProgressChanged           += new ProgressChangedEventHandler(Zip_ProgressChanged);
            try
            {
                MLifter.DAL.Pack.Packer packer = new MLifter.DAL.Pack.Packer(backgroundWorker);
                string packedDict = packer.Pack(Dictionary.DictionaryDAL, SaveDialog.FileName);
            }
            catch (IOException)
            {
                MessageBox.Show(Properties.Resources.PACK_IOEXCEPTION_TEXT, Properties.Resources.PACK_IOEXCEPTION_CAPTION, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
                m_LoadMsg.Hide();
            }
        }
예제 #2
0
 /// <summary>
 /// Hides the status message and activates the form.
 /// </summary>
 /// <remarks>Documented by Dev02, 2008-09-29</remarks>
 private void HideStatusMessage()
 {
     LearnLogic.CopyToFinished -= new EventHandler(LearnLogic_CopyToFinished);
     ParentForm.Enabled         = true;
     loadStatusMessageImport.Hide();
     UpdateList();
 }
예제 #3
0
 /// <summary>
 /// Hides the status message and activates the form.
 /// </summary>
 /// <remarks>Documented by Dev02, 2008-09-29</remarks>
 private void HideStatusMessage()
 {
     loadStatusMessageImport.Invoke((MethodInvoker) delegate
     {
         LearnLogic.CopyToFinished -= new EventHandler(LearnLogic_CopyToFinished);
         loadStatusMessageImport.Hide();
     });
 }
예제 #4
0
        private void HideStatusMessage()
        {
            if (SetStatusDelegate != null)
            {
                return;
            }

            if (m_LoadMsg.InvokeRequired)
            {
                m_LoadMsg.Invoke((MethodInvoker) delegate
                {
                    m_LoadMsg.Hide();
                });
            }
        }
예제 #5
0
        private string UnpackDic(string filename)
        {
            bool   ignoreInvalidHeader = false;
            string dictionaryPath      = String.Empty;

            MLifter.DAL.Interfaces.IDictionary dictionary = null;
            string fileNameWithoutExtension = String.Empty;

            if (!MLifter.DAL.Pack.Packer.IsValidArchive(filename))
            {
                throw new Exception("Invalid Archiv");
            }

            fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filename);
            dictionaryPath           = GenerateDictionaryPath(filename);

            try
            {
                if (!Directory.Exists(dictionaryPath))
                {
                    Directory.CreateDirectory(dictionaryPath);
                }
            }
            catch
            {
                throw new Exception("Cannot Create Dictionary Folder for Unpacking");
            }

            bool pathExists = false;

            do
            {
                if (File.Exists(Path.Combine(dictionaryPath, fileNameWithoutExtension + MLifter.DAL.Helper.OdxExtension)))
                {
                    pathExists = true;
                }
                else if (Directory.GetFiles(dictionaryPath, "*" + MLifter.DAL.Helper.OdxExtension).Length > 0)
                {
                    pathExists = true;
                }
                else
                {
                    pathExists = false;
                }
            }while (pathExists);

            ShowStatusMessage("Unpacking");


            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 (MLifter.DAL.NoValidArchiveHeaderException ex)
            {
                Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message);
                return(String.Empty);
            }
            catch (MLifter.DAL.NoValidArchiveException ex)
            {
                Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message);
                return(String.Empty);
            }
            catch (System.Xml.XmlException ex)
            {
                Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message);
                return(String.Empty);
            }
            catch (IOException ex)
            {
                Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message);
                return(String.Empty);
            }
            catch (MLifter.DAL.DictionaryFormatNotSupported ex)
            {
                Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message);
                return(String.Empty);
            }
            catch (MLifter.DAL.DictionaryNotDecryptedException ex)
            {
                Debug.WriteLine("Pack.Unpack() - " + filename + " - " + ex.Message);
                return(String.Empty);
            }
            catch
            {
                if (dictionary != null)
                {
                    dictionary.Dispose();
                }
                return(String.Empty);
            }
            finally
            {
                if (dictionary != null)
                {
                    dictionary.Dispose();
                }
                Cursor.Current = Cursors.Default;
                m_LoadMsg.Hide();
            }

            return(dictionaryPath);
        }
예제 #6
0
        //�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);
        }
예제 #7
0
 /// <summary>
 /// Hides the status message and activates the form.
 /// </summary>
 /// <remarks>Documented by Dev02, 2008-09-29</remarks>
 private void HideStatusMessage()
 {
     LearnLogic.CopyToFinished -= new EventHandler(LearnLogic_CopyToFinished);
     this.Enabled = true;
     loadStatusMessageImport.Hide();
 }