Beispiel #1
0
 /// <summary>
 /// Run the utility on command from the main utility dialog.
 /// </summary>
 public void Process()
 {
     Debug.Assert(m_dlg != null);
     using (var dlg = new FixErrorsDlg())
     {
         try
         {
             if (dlg.ShowDialog(m_dlg) == DialogResult.OK)
             {
                 string pathname = Path.Combine(
                     Path.Combine(FwDirectoryFinder.ProjectsDirectory, dlg.SelectedProject),
                     dlg.SelectedProject + FdoFileHelper.ksFwDataXmlFileExtension);
                 if (File.Exists(pathname))
                 {
                     using (new WaitCursor(m_dlg))
                     {
                         using (var progressDlg = new ProgressDialogWithTask(m_dlg))
                         {
                             string fixes = (string)progressDlg.RunTask(true, FixDataFile, pathname);
                             if (fixes.Length > 0)
                             {
                                 MessageBox.Show(fixes, Strings.ksErrorsFoundOrFixed);
                                 File.WriteAllText(pathname.Replace(FdoFileHelper.ksFwDataXmlFileExtension, "fixes"), fixes);
                             }
                         }
                     }
                 }
             }
         }
         catch
         {
         }
     }
 }
Beispiel #2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Exposes the <see cref="TeScrInitializer.CreateScrBookRefs"/> method
 /// </summary>
 /// <param name="cache"></param>
 /// ------------------------------------------------------------------------------------
 public void CallCreateScrBookRefs(FdoCache cache)
 {
     using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(Form.ActiveForm))
     {
         CreateScrBookRefs(progressDlg);
     }
 }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// If the current Scripture Note categories list version in the Db doesn't match that of
        /// the current XML file, update the DB.
        /// </summary>
        /// <param name="lp">The language project</param>
        /// <param name="existingProgressDlg">The existing progress dialog, if any.</param>
        /// ------------------------------------------------------------------------------------
        public static void EnsureCurrentScrNoteCategories(ILangProject lp,
                                                          IAdvInd4 existingProgressDlg)
        {
            XmlNode    scrNoteCategories = LoadScrNoteCategoriesDoc();
            IScripture scr        = lp.TranslatedScriptureOA;
            Guid       newVersion = Guid.Empty;

            try
            {
                XmlNode version = scrNoteCategories.Attributes.GetNamedItem("version");
                newVersion = new Guid(version.Value);
            }
            catch (Exception e)
            {
                ReportInvalidInstallation("List version attribute invalid in TeScrNoteCategories.xml", e);
            }
            if (scr.NoteCategoriesOA == null || newVersion != scr.NoteCategoriesOA.ListVersion)
            {
                using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(Form.ActiveForm))
                {
                    dlg.RunTask(existingProgressDlg, true,
                                new BackgroundTaskInvoker(CreateScrNoteCategories), scrNoteCategories, scr);
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Export the FieldWorks lexicon into the LIFT file.
 /// The file may, or may not, exist.
 /// </summary>
 /// <returns>True, if the import successful, otherwise false.</returns>
 /// <remarks>
 /// This method calls an overloaded ExportLiftLexicon, which is run in a thread.
 /// </remarks>
 public bool ExportLiftLexicon()
 {
     using (new WaitCursor(_parentForm))
     {
         using (var helper = new ThreadHelper())                 // not _cache.ThreadHelper, which might be for a different thread
             using (var progressDlg = new ProgressDialogWithTask(_parentForm, helper))
             {
                 _progressDlg = progressDlg;
                 progressDlg.ProgressBarStyle = ProgressBarStyle.Continuous;
                 try
                 {
                     progressDlg.Title = ResourceHelper.GetResourceString("kstidExportLiftLexicon");
                     var outPath = (string)progressDlg.RunTask(true, ExportLiftLexicon, _liftPathname);
                     var retval  = (!String.IsNullOrEmpty(outPath));
                     if (!retval)
                     {
                         UndoExport();
                     }
                     return(retval);
                 }
                 catch
                 {
                     UndoExport();
                     return(false);
                 }
                 finally
                 {
                     _progressDlg = null;
                 }
             }
     }
 }
Beispiel #5
0
 private void DoImport()
 {
     using (new WaitCursor(this))
     {
         using (var progressDlg = new ProgressDialogWithTask(this))
         {
             progressDlg.Minimum     = 0;
             progressDlg.Maximum     = 100;
             progressDlg.AllowCancel = true;
             progressDlg.Restartable = true;
             progressDlg.Title       = String.Format(LexTextControls.ksImportingFrom0, tbPath.Text);
             try
             {
                 m_cache.DomainDataByFlid.BeginNonUndoableTask();
                 m_sLogFile = (string)progressDlg.RunTask(true, ImportLIFT, tbPath.Text);
             }
             finally
             {
                 // This can indirectly try to access Views code in all the PropChanged
                 // handling.  This is why the UOW handling has been moved from ImportLIFT
                 // (which executes on a different thread).  See FWR-3057.
                 m_cache.DomainDataByFlid.EndNonUndoableTask();
             }
         }
     }
 }
Beispiel #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Make sure the stylesheet for the specified object is current.
        /// </summary>
        /// <param name="progressDlg">The progress dialog if one is already up.</param>
        /// ------------------------------------------------------------------------------------
        public void EnsureCurrentResource(IAdvInd4 progressDlg)
        {
            T    doc        = LoadDoc();
            Guid newVersion = new Guid();

            try
            {
                newVersion = GetVersion(doc);
            }
            catch (Exception e)
            {
                ReportInvalidInstallation(string.Format(
                                              FrameworkStrings.ksInvalidResourceFileVersion, ResourceFileName), e);
            }

            // Get the current version of the settings used in this project.
            CmResource resource = CmResource.GetResource(ResourceOwner.Cache, ResourceOwner.Hvo,
                                                         ResourcesFlid, ResourceName);

            // Re-load the factory settings if they are not at current version.
            if (resource == null || newVersion != resource.Version)
            {
                using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(
                           Application.OpenForms.Count > 0 ? Application.OpenForms[0] : null))
                {
                    ProcessResources(dlg, progressDlg, doc);
#if DEBUG
                    Debug.Assert(m_fVersionUpdated);
#endif
                }
            }
        }
Beispiel #7
0
        private void m_backUp_Click(object sender, EventArgs e)
        {
            if (!Path.IsPathRooted(DestinationFolder))
            {
                MessageBox.Show(this, FwCoreDlgs.ksBackupErrorRelativePath, FwCoreDlgs.ksErrorCreatingBackupDirCaption,
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                m_destinationFolder.Select();
                DialogResult = DialogResult.None;
                return;
            }

            if (!Directory.Exists(DestinationFolder))
            {
                try
                {
                    Directory.CreateDirectory(DestinationFolder);
                }
                catch (Exception e1)
                {
                    MessageBox.Show(this, e1.Message, FwCoreDlgs.ksErrorCreatingBackupDirCaption,
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    m_destinationFolder.Select();
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            if (!DestinationFolder.Equals(FwDirectoryFinder.DefaultBackupDirectory))
            {
                using (var dlgChangeDefaultBackupLocation = new ChangeDefaultBackupDir(m_helpTopicProvider))
                {
                    if (dlgChangeDefaultBackupLocation.ShowDialog(this) == DialogResult.Yes)
                    {
                        FwDirectoryFinder.DefaultBackupDirectory = DestinationFolder;
                    }
                }
            }

            if (m_presenter.FileNameProblems(this))
            {
                return;
            }

            try
            {
                using (new WaitCursor(this))
                    using (var progressDlg = new ProgressDialogWithTask(this))
                    {
                        BackupFilePath = m_presenter.BackupProject(progressDlg);
                    }
            }
            catch (FwBackupException be)
            {
                MessageBox.Show(this, string.Format(FwCoreDlgs.ksBackupErrorCreatingZipfile, be.ProjectName, be.Message),
                                FwCoreDlgs.ksBackupErrorCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DialogResult = DialogResult.None;
            }
        }
Beispiel #8
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="T:TeImportUi"/> class.
 /// </summary>
 /// <param name="progressDialog">The progress dialog.</param>
 /// ------------------------------------------------------------------------------------
 public TeImportUi(ProgressDialogWithTask progressDialog)
 {
     m_progressDialog = progressDialog;
     if (m_progressDialog != null)               // might be null for tests
     {
         m_progressDialog.Cancel += new CancelHandler(OnCancelPressed);
     }
     m_ctrl = new Control();
     m_ctrl.CreateControl();
 }
Beispiel #9
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Performs a partial overwrite of the book using the imported portion of the book.
 /// </summary>
 /// <param name="bookMerger">The book merger.</param>
 /// <param name="sectionsToRemove">The sections to remove as the first step (before
 /// calling the auto-merge code).</param>
 /// ------------------------------------------------------------------------------------
 protected virtual void PartialOverwrite(BookMerger bookMerger,
                                         List <IScrSection> sectionsToRemove)
 {
     Logger.WriteEvent("Performing partial Overwrite of book: " + bookMerger.BookCurr.BookId);
     using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this))
     {
         progress.Title = Properties.Resources.kstidOverwriteCaption;
         progress.RunTask(bookMerger.DoPartialOverwrite, sectionsToRemove);
     }
 }
Beispiel #10
0
        private void CommonAddWS(bool isAnalysis, MenuItem selectedMI)
        {
            IWritingSystem ws = null;

            if (selectedMI.Text == LexTextControls.ks_DefineNew_)
            {
                IEnumerable <IWritingSystem> newWritingSystems;
                if (WritingSystemPropertiesDialog.ShowNewDialog(FindForm(), m_cache, m_cache.ServiceLocator.WritingSystemManager,
                                                                m_cache.ServiceLocator.WritingSystems, m_helpTopicProvider, m_app, m_stylesheet, true, null,
                                                                out newWritingSystems))
                {
                    ws = newWritingSystems.First();
                }
            }
            else
            {
                ws = selectedMI.Tag as IWritingSystem;
            }

            if (ws != null)
            {
                m_wsNew = ws;
                // now add the ws to the FDO list for it
                NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
                {
                    // Add a global writing system to the local writing system store.  (Replace
                    // does this if there's nothing to replace.)
                    if (m_wsNew.Handle == 0)
                    {
                        m_cache.ServiceLocator.WritingSystemManager.Replace(m_wsNew);
                    }
                    if (isAnalysis)
                    {
                        m_cache.ServiceLocator.WritingSystems.AnalysisWritingSystems.Add(m_wsNew);
                        if (!m_cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems.Contains(m_wsNew))
                        {
                            m_cache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems.Add(m_wsNew);
                        }
                    }
                    else
                    {
                        m_cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Add(m_wsNew);
                        if (!m_cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Contains(m_wsNew))
                        {
                            m_cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Add(m_wsNew);
                        }
                    }
                    ProgressDialogWithTask.ImportTranslatedListsForWs(this.FindForm(), m_cache, m_wsNew.IcuLocale);
                });
                if (WritingSystemAdded != null)
                {
                    WritingSystemAdded(this, new EventArgs());
                }
            }
        }
Beispiel #11
0
 private void ImportNewLiftData(string outPath)
 {
     using (m_progressDlg = new ProgressDialogWithTask(this))
     {
         m_progressDlg.CancelButtonVisible = true;
         m_progressDlg.Restartable         = true;
         m_progressDlg.Cancel += new CancelHandler(OnProgressDlgCancel);
         m_progressDlg.RunTask(true, new BackgroundTaskInvoker(ImportLift), outPath);
     }
     m_progressDlg = null;
 }
Beispiel #12
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="TeImportUi"/> class.
 /// </summary>
 /// <param name="progressDialog">The progress dialog.</param>
 /// <param name="helpTopicProvider">The help topic provider.</param>
 /// ------------------------------------------------------------------------------------
 public TeImportUi(ProgressDialogWithTask progressDialog, IHelpTopicProvider helpTopicProvider)
 {
     m_progressDialog = progressDialog;
     if (m_progressDialog != null)
     {
         m_progressDialog.Canceling += OnCancelPressed;
     }
     m_helpTopicProvider = helpTopicProvider;
     m_ctrl = new Control();
     m_ctrl.CreateControl();
 }
Beispiel #13
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a new language project showing a progress dialog.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void CreateNewLangProjWithProgress()
        {
            try
            {
                using (var progressDlg = new ProgressDialogWithTask(this, null))
                {
                    progressDlg.Title = string.Format(FwCoreDlgs.kstidCreateLangProjCaption, ProjectName);

                    using (new WaitCursor())
                    {
                        RemoveWs(m_newVernWss, m_cbVernWrtSys.SelectedItem);                         // just keep additional ones
                        RemoveWs(m_newAnalysisWss, m_cbAnalWrtSys.SelectedItem);                     // just keep additional ones
                        using (var threadHelper = new ThreadHelper())
                        {
                            m_dbFile = (string)progressDlg.RunTask(DisplayUi, FdoCache.CreateNewLangProj,
                                                                   ProjectName, threadHelper, m_cbAnalWrtSys.SelectedItem, m_cbVernWrtSys.SelectedItem,
                                                                   m_wsManager.UserWritingSystem.IcuLocale, m_newAnalysisWss, m_newVernWss);
                        }
                    }
                }
            }
            catch (WorkerThreadException wex)
            {
                Exception e = wex.InnerException;
                if (e.GetBaseException() is PathTooLongException)
                {
                    Show();
                    m_fIgnoreClose = true;
                    MessageBox.Show(String.Format(FwCoreDlgs.kstidErrorProjectNameTooLong, ProjectName),
                                    FwUtils.ksSuiteName);
                }
                else if (e is ApplicationException)
                {
                    MessageBox.Show(string.Format(FwCoreDlgs.kstidErrorNewDb, e.Message),
                                    FwUtils.ksSuiteName);

                    m_fIgnoreClose = true;
                    DialogResult   = DialogResult.Cancel;
                }
                else if (e is FwStartupException)
                {
                    MessageBox.Show(string.Format(FwCoreDlgs.kstidErrorNewDb, e.Message),
                                    FwUtils.ksSuiteName);

                    DialogResult = DialogResult.Cancel;
                }
                else
                {
                    m_fIgnoreClose = true;
                    DialogResult   = DialogResult.Cancel;
                    throw new Exception(FwCoreDlgs.kstidErrApp, e);
                }
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handle the View Differences button. Display the Review Differences window to
        /// view/merge differences between the current scripture and selected book in the tree.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void m_btnDiff_Click(object sender, System.EventArgs e)
        {
            // If the selected item is not a book, then don't do a diff.
            TreeNode node = m_treeArchives.SelectedNode;

            if (node == null)
            {
                return;
            }

            ScrBook bookRev = node.Tag as ScrBook;

            if (bookRev == null)
            {
                return;
            }

            //ScrDraft archive = node.Parent.Tag as ScrDraft;

            using (BookMerger merger = new BookMerger(m_cache, m_styleSheet, bookRev))
            {
                using (ProgressDialogWithTask progress = new ProgressDialogWithTask(this))
                {
                    progress.Title   = DlgResources.ResourceString("kstidCompareCaption");
                    progress.Message = string.Format(
                        DlgResources.ResourceString("kstidMergeProgress"), bookRev.BestUIName);
                    progress.RunTask(true, new BackgroundTaskInvoker(merger.DetectDifferences));
                }

                // always hide diffs that could cause deletion of current sections, if reverted
                merger.UseFilteredDiffList();

                // If there were differences detected then show the diff dialog
                if (merger.NumberOfDifferences != 0)
                {
                    using (DiffDialog dlg = new DiffDialog(merger, m_cache, m_styleSheet, m_zoomDraft,
                                                           m_zoomFootnote))
                    {
                        // We have to pass the owner (this), so that the dialog shows when the
                        // user clicks on the TE icon in the taskbar. Otherwise only the Archive
                        // dialog would pop up and beeps; diff dialog could only be regained by Alt-Tab.
                        dlg.ShowDialog(this);
                    }
                }
                else
                {
                    // Tell users that no differences were found in the merge
                    MessageBox.Show(this,
                                    string.Format(DlgResources.ResourceString("kstidNoDifferencesDetected"),
                                                  bookRev.BestUIName), Application.ProductName, MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
            }
        }
Beispiel #15
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Expose the ExportBook method
        /// </summary>
        /// <param name="book"></param>
        /// ------------------------------------------------------------------------------------
        public void ExportBook(IScrBook book)
        {
            CheckDisposed();

            CreateStyleTables();
            m_nonInterleavedBtWs = m_requestedAnalWS[0];
            base.CreateAnnotationList(m_currentBookOrd);
            using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(Form.ActiveForm))
            {
                base.ExportBook(dlg, book);
            }
        }
Beispiel #16
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Exposes the ExportSection method for testing
        /// </summary>
        /// <param name="section">The section.</param>
        /// <param name="outputImplicitChapter">if set to <c>true</c> [output implicit chapter].</param>
        /// ------------------------------------------------------------------------------------
        public void ExportSection(IScrSection section, bool outputImplicitChapter)
        {
            CheckDisposed();

            CreateStyleTables();
            m_nonInterleavedBtWs = m_requestedAnalWS[0];
            base.CreateAnnotationList(m_currentBookOrd);
            using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(Form.ActiveForm))
            {
                base.ExportSection(dlg, section, outputImplicitChapter);
            }
        }
Beispiel #17
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Do the actual export.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void DoExport(string outPath)
        {
            string  fxtPath = (string)m_exportList.SelectedItems[0].Tag;
            FxtType ft      = m_rgFxtTypes[FxtIndex(fxtPath)];

            using (new WaitCursor(this))
            {
                using (var progressDlg = new ProgressDialogWithTask(this))
                {
                    try
                    {
                        progressDlg.Title = String.Format(xWorksStrings.Exporting0,
                                                          m_exportList.SelectedItems[0].Text);
                        progressDlg.Message = xWorksStrings.Exporting_;
                        switch (ft.m_ft)
                        {
                        case FxtTypes.kftFxt:
                            progressDlg.RunTask(true, ExportNotebook, outPath, fxtPath, ft);
                            break;

                        case FxtTypes.kftConfigured:
                            progressDlg.Minimum     = 0;
                            progressDlg.Maximum     = m_seqView.ObjectCount;
                            progressDlg.AllowCancel = true;

                            IVwStylesheet vss = m_seqView.RootBox == null ? null : m_seqView.RootBox.Stylesheet;
                            progressDlg.RunTask(true, ExportConfiguredDocView,
                                                outPath, fxtPath, ft, vss);
                            break;
                        }
                    }
                    catch (WorkerThreadException e)
                    {
                        if (e.InnerException is CancelException)
                        {
                            MessageBox.Show(this, e.InnerException.Message);
                            m_ce = null;
                        }
                        else
                        {
                            string msg = xWorksStrings.ErrorExporting_ProbablyBug + Environment.NewLine + e.InnerException.Message;
                            MessageBox.Show(this, msg);
                        }
                    }
                    finally
                    {
                        m_progressDlg = null;
                        Close();
                    }
                }
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <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.Minimum     = 0;
                progressDlg.Maximum     = m_scr.ScriptureBooksOS.Count;
                progressDlg.Title       = DlgResources.ResourceString("kstidUpdateVerseBridges");
                progressDlg.AllowCancel = false;

                progressDlg.RunTask(UpdateVerseBridges, oldBridge);
            }
        }
        /// ------------------------------------------------------------------------------------
        /// <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.Minimum     = 0;
                progressDlg.Maximum     = m_scr.ScriptureBooksOS.Count;
                progressDlg.Title       = DlgResources.ResourceString("kstidConvertChapterVerseNumbersCaption");
                progressDlg.AllowCancel = false;

                progressDlg.RunTask(ConvertChapterVerseNumbers);
            }
        }
Beispiel #20
0
        private void Run()
        {
            string outPath = GetOutputPathname();

            try
            {
                // 1. Export or update external lift file.
                ExportLiftData(outPath);
                // 2. Run Chorus (just run a stub for now until Chorus is real) which will
                //    a. talk to the user if there is no version control system, asking where
                //       the file to merge is, else just check-in the work, grab work from
                //       teammates, and then
                //    b. do the smart merge
                SynchronizeWithExternalSource();
                // 3. Import the lift file, wiping out anything that differs from it
                ImportNewLiftData(outPath);
            }
            catch (WorkerThreadException e)
            {
                if (e.InnerException is CancelException)
                {
                    MessageBox.Show(e.InnerException.Message);
                    return;
                }
                else if (m_dumper != null)
                {
                    MessageBox.Show("error exporting");
                }
            }
            finally
            {
                m_dumper      = null;
                m_progressDlg = null;
                if (m_fTempFiles && File.Exists(outPath))
                {
                    File.Delete(outPath);
                    string x = Path.ChangeExtension(outPath, "lift-ranges");
                    if (File.Exists(x))
                    {
                        File.Delete(x);
                    }
                    string y = x.Replace(".lift-ranges", "-ImportLog.htm");
                    if (File.Exists(y))
                    {
                        File.Delete(y);
                    }
                }
            }
        }
        private void m_btnOK_Click(object sender, EventArgs e)
        {
            using (var dlg = new ProgressDialogWithTask(this))
            {
                dlg.AllowCancel = false;
                dlg.Minimum     = 0;
                dlg.Maximum     = 500;
                using (new WaitCursor(this, true))
                {
                    var import = new LinguaLinksImport(m_cache,
                                                       Path.Combine(Path.GetTempPath(), "LanguageExplorer" + Path.DirectorySeparatorChar),
                                                       Path.Combine(FwDirectoryFinder.CodeDirectory, Path.Combine("Language Explorer", "Import" + Path.DirectorySeparatorChar)));
                    import.NextInput = m_tbFilename.Text;
                    import.Error    += import_Error;
                    try
                    {
                        var fSuccess = (bool)dlg.RunTask(true, import.ImportInterlinear, m_tbFilename.Text);
                        if (fSuccess)
                        {
                            DialogResult = DialogResult.OK;                             // only 'OK' if not exception
                            var firstNewText = import.FirstNewText;
                            if (firstNewText != null && m_mediator != null)
                            {
                                m_mediator.SendMessage("JumpToRecord", firstNewText.Hvo);
                            }
                        }
                        else
                        {
                            DialogResult = DialogResult.Abort;                             // unsuccessful import
                            string message = ITextStrings.ksInterlinImportFailed + Environment.NewLine + Environment.NewLine;
                            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);
                        DialogResult = DialogResult.Cancel;                             // only 'OK' if not exception
                        Close();
                    }
                }
            }
        }
Beispiel #22
0
        private void m_btnMerge_Click(object sender, EventArgs e)
        {
            using (new SIL.FieldWorks.Common.Utils.WaitCursor(this))
            {
                using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(this))
                {
                    progressDlg.ProgressBarStyle = ProgressBarStyle.Continuous;
                    m_progressDlg = progressDlg as IAdvInd4;
                    try
                    {
                        progressDlg.Title = "Chorus Merge Process";
                        // 1. export lexicon
                        string outPath = Path.GetTempFileName();
                        outPath = (string)progressDlg.RunTask(true, new BackgroundTaskInvoker(ExportLexicon), outPath);
                        if (outPath == null)
                        {
                            // TODO: some sort of error report?
                            return;
                        }

                        // 2. merge via chorus
                        string inPath = (string)progressDlg.RunTask(true, new BackgroundTaskInvoker(ChorusMerge), outPath);
                        if (inPath == null)
                        {
                            // TODO: some sort of error report?
                            return;
                        }
                        // 3. re-import lexicon, overwriting current contents.
                        string logFile = (string)progressDlg.RunTask(true, new BackgroundTaskInvoker(ImportLexicon), inPath);
                        if (logFile == null)
                        {
                            // TODO: some sort of error report?
                            return;
                        }
                        else
                        {
                        }
                    }
                    catch
                    {
                    }
                    finally
                    {
                    }
                }
            }
            DialogResult = DialogResult.OK;
            Close();
        }
Beispiel #23
0
        private void OnFinishClick(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;

            // The progress dialog takes a few seconds to appear. Disable all controls so the user doesn't think they can click anything.
            Enabled = false;

            using (new WaitCursor(this))
                using (var threadHelper = new ThreadHelper())
                    using (var progressDialog = new ProgressDialogWithTask(threadHelper))
                    {
                        m_dbFile = m_model.CreateNewLangProj(progressDialog, threadHelper);
                    }
            Close();
        }
Beispiel #24
0
 /// <summary>
 /// Import the lift file using the given MergeStyle:
 ///		FlexLiftMerger.MergeStyle.MsKeepNew (aka 'merciful', in that all entries from lift file and those in FLEx are retained)
 ///		FlexLiftMerger.MergeStyle.MsKeepOnlyNew (aka 'merciless',
 ///			in that the Flex lexicon ends up with the same entries as in the lift file, even if some need to be deleted in FLEx.)
 /// </summary>
 /// <param name="mergeStyle">FlexLiftMerger.MergeStyle.MsKeepNew or FlexLiftMerger.MergeStyle.MsKeepOnlyNew</param>
 /// <returns>'true' if the import succeeded, otherwise 'false'.</returns>
 private bool ImportLiftCommon(FlexLiftMerger.MergeStyle mergeStyle)
 {
     using (new WaitCursor(_parentForm))
     {
         using (var helper = new ThreadHelper())                 // not _cache.ThreadHelper, which might be for a different thread
             using (var progressDlg = new ProgressDialogWithTask(_parentForm, helper))
             {
                 _progressDlg = progressDlg;
                 progressDlg.ProgressBarStyle = ProgressBarStyle.Continuous;
                 try
                 {
                     progressDlg.Title = ResourceHelper.GetResourceString("kstidImportLiftlexicon");
                     var logFile = (string)progressDlg.RunTask(true, ImportLiftLexicon, new object[] { _liftPathname, mergeStyle });
                     return(logFile != null);
                 }
                 catch (WorkerThreadException error)
                 {
                     // It appears to be an analyst issue to sort out how we should report this.
                     // LT-12340 however says we must report it somehow.
                     var sMsg = String.Format(LexEdStrings.kProblemImportWhileMerging, _liftPathname, error.InnerException.Message);
                     // RandyR says JohnH isn't excited about this approach to reporting an import error, that is, copy it to the
                     // clipboard (and presumably say something about it in kProblemImportWhileMerging).
                     // But it would be nice to get the details if it is a crash.
                     //try
                     //{
                     //    var bldr = new StringBuilder();
                     //    bldr.AppendFormat(Resources.kProblem, m_liftPathname);
                     //    bldr.AppendLine();
                     //    bldr.AppendLine(error.Message);
                     //    bldr.AppendLine();
                     //    bldr.AppendLine(error.StackTrace);
                     //    if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
                     //        ClipboardUtils.SetDataObject(bldr.ToString(), true);
                     //}
                     //catch
                     //{
                     //}
                     MessageBox.Show(sMsg, LexEdStrings.kProblemMerging,
                                     MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     return(false);
                 }
                 finally
                 {
                     _progressDlg = null;
                 }
             }
     }
 }
Beispiel #25
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Ensures the given localization is at the current version.
        /// </summary>
        /// <param name="locale">The locale representing the required localization.</param>
        /// <param name="caller">The form that is calling this method (used as the owner
        /// of the progress dialog box - can be null if progress dialog is supplied).</param>
        /// <param name="existingProgressDlg">The existing progress dialog box if any.</param>
        /// ------------------------------------------------------------------------------------
        private void EnsureCurrentLocalization(string locale, Form caller,
                                               IProgress existingProgressDlg)
        {
            string localizationFile = DirectoryFinder.GetKeyTermsLocFilename(locale);

            if (!FileUtils.FileExists(localizationFile))
            {
                return;                 // There is no localization available for this locale, so we're as current as we're going to get.
            }
            BiblicalTermsLocalization loc;

            try
            {
                loc = DeserializeBiblicalTermsLocFile(localizationFile);
            }
            catch (InstallationException e)
            {
                ErrorReporter.ReportException(e, m_app.SettingsKey, m_app.SupportEmailAddress, caller, false);
                return;
            }

            string resourceName = GetLocalizationResourceName(locale);

            if (IsResourceOutdated(resourceName, loc.Version))
            {
                NonUndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(m_servLoc.GetInstance <IActionHandler>(),
                                                                   () => {
                    if (existingProgressDlg is IThreadedProgress)
                    {
                        ((IThreadedProgress)existingProgressDlg).RunTask(true, UpdateLocalization, loc, locale);
                    }
                    else if (existingProgressDlg != null)
                    {
                        using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(existingProgressDlg))
                            dlg.RunTask(true, UpdateLocalization, loc, locale);
                    }
                    else
                    {
                        using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(caller, m_scr.Cache.ThreadHelper))
                        {
                            dlg.AllowCancel = false;
                            dlg.RunTask(true, UpdateLocalization, loc, locale);
                        }
                    }
                    SetNewResourceVersion(resourceName, loc.Version);
                });
            }
        }
Beispiel #26
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        /// ------------------------------------------------------------------------------------
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (m_ctrl != null)
                {
                    m_ctrl.Dispose();
                }
            }

            m_ctrl           = null;
            m_progressDialog = null;
            m_importer       = null;

            m_fDisposed = true;
        }
Beispiel #27
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a new language project showing a dialog progress.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void CreateNewLangProjWithProgress()
        {
            ResourceManager resources = new ResourceManager(
                "SIL.FieldWorks.FwCoreDlgs.FwCoreDlgs", Assembly.GetExecutingAssembly());

            try
            {
                using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(this))
                {
                    progressDlg.Title = string.Format(FwCoreDlgs.kstidCreateLangProjCaption, ProjectName);


                    using (new WaitCursor())
                    {
                        m_newProjectInfo = (NewLangProjReturnData)progressDlg.RunTask(DisplayUi,
                                                                                      new BackgroundTaskInvoker(new FwNewLangProjectCreator().CreateNewLangProj),
                                                                                      resources, ProjectName, m_cbAnalWrtSys.SelectedItem, m_cbVernWrtSys.SelectedItem);
                    }
                }
            }
            catch (WorkerThreadException wex)
            {
                Exception e = wex.InnerException;
                if (e is PathTooLongException)
                {
                    this.Show();
                    m_fIgnoreClose = true;
                    MessageBox.Show(FwCoreDlgs.kstidErrPathToLong);
                }
                else if (e is ApplicationException)
                {
                    if (resources != null)
                    {
                        MessageBox.Show(string.Format(resources.GetString("kstidErrorNewDb"), e.Message));
                    }

                    m_fIgnoreClose    = true;
                    this.DialogResult = DialogResult.Cancel;
                }
                else
                {
                    m_fIgnoreClose    = true;
                    this.DialogResult = DialogResult.Cancel;
                    throw new Exception(FwCoreDlgs.kstidErrApp, e);
                }
            }
        }
        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();
                    }
                }
            }
        }
Beispiel #29
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        /// ------------------------------------------------------------------------------------
        protected virtual void Dispose(bool disposing)
        {
            System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
            if (disposing)
            {
                if (m_ctrl != null)
                {
                    m_ctrl.Dispose();
                }
            }

            m_ctrl           = null;
            m_progressDialog = null;
            m_importer       = null;

            m_fDisposed = true;
        }
Beispiel #30
0
        /// -------------------------------------------------------------------------------------
        /// <summary>
        /// Perform one-time initialization of a new Scripture project
        /// </summary>
        /// <returns>true if data loaded successfully; false, otherwise</returns>
        /// -------------------------------------------------------------------------------------
        protected bool Initialize(IFwSplashScreen splashScreen)
        {
            ILangProject lp = m_cache.LangProject;

            if (m_scr != null)
            {
                // Preload all book, section and paragraphs if we already have Scripture
                PreloadData(m_cache, splashScreen);

                if (m_scr.BookAnnotationsOS.Count != 0 &&
                    m_cache.ScriptureReferenceSystem.BooksOS.Count != 0 && m_scr.PublicationsOC.Count != 0 &&
                    lp.KeyTermsList.PossibilitiesOS.Count >= 1 &&
                    m_scr.NoteCategoriesOA != null && m_scr.NoteCategoriesOA.PossibilitiesOS.Count > 0)
                {
                    return(true);
                }
            }

            IAdvInd4 existingProgressDlg = null;

            if (splashScreen != null)
            {
                existingProgressDlg = splashScreen.ProgressBar as IAdvInd4;
            }

            using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(Form.ActiveForm))
            {
                try
                {
                    dlg.RunTask(existingProgressDlg, true, new BackgroundTaskInvoker(InitializeScriptureProject));
                }
                catch (WorkerThreadException e)
                {
                    UndoResult ures;
                    while (m_cache.Undo(out ures))
                    {
                        ;                                                // Enhance JohnT: make use of ures?
                    }
                    MessageBox.Show(Form.ActiveForm, e.InnerException.Message,
                                    TeResourceHelper.GetResourceString("kstidApplicationName"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }
            }
            return(true);
        }