コード例 #1
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="cache">The FDO cache</param>
 /// <param name="propChangedHandling">How to process PropChanged notifications</param>
 /// ------------------------------------------------------------------------------------
 public IgnorePropChanged(FdoCache cache, PropChangedHandling propChangedHandling)
 {
     m_cache       = cache;
     m_oldHandling = m_cache.PropChangedHandling;
     m_cache.PropChangedHandling |= propChangedHandling;
 }
コード例 #2
0
ファイル: FlexChorusDlg.cs プロジェクト: sillsdev/WorldPad
        /// <summary>
        /// Import the modified LIFT file given by the first (and only) parameter.
        /// </summary>
        /// <returns>the name of the log file for the import, or null if a major error occurs.</returns>
        protected object ImportLexicon(IAdvInd4 progressDialog, params object[] parameters)
        {
            if (m_progressDlg == null)
            {
                m_progressDlg = progressDialog;
            }
            progressDialog.SetRange(0, 100);
            progressDialog.Position = 0;
            string inPath   = parameters[0].ToString();
            string sLogFile = null;
            PropChangedHandling oldPropChg = m_cache.PropChangedHandling;

            try
            {
                m_cache.PropChangedHandling = PropChangedHandling.SuppressAll;
                string sFilename;
                bool   fMigrationNeeded = LiftIO.Migration.Migrator.IsMigrationNeeded(inPath);
                if (fMigrationNeeded)
                {
                    string sOldVersion = LiftIO.Validation.Validator.GetLiftVersion(inPath);
                    progressDialog.Message = String.Format("Migrating from LIFT version {0} to version {1}",
                                                           sOldVersion, LiftIO.Validation.Validator.LiftVersion);
                    sFilename = LiftIO.Migration.Migrator.MigrateToLatestVersion(inPath);
                }
                else
                {
                    sFilename = inPath;
                }
                // TODO: validate input file?
                progressDialog.Message = "Loading various lists for lookup during import";
                FlexLiftMerger flexImporter = new FlexLiftMerger(m_cache, FlexLiftMerger.MergeStyle.msKeepOnlyNew, true);
                LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample> parser =
                    new LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample>(flexImporter);
                parser.SetTotalNumberSteps += new EventHandler <LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample> .StepsArgs>(parser_SetTotalNumberSteps);
                parser.SetStepsCompleted   += new EventHandler <LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample> .ProgressEventArgs>(parser_SetStepsCompleted);
                parser.SetProgressMessage  += new EventHandler <LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample> .MessageArgs>(parser_SetProgressMessage);
                flexImporter.LiftFile       = inPath;

                int cEntries = parser.ReadLiftFile(sFilename);

                if (fMigrationNeeded)
                {
                    // Try to move the migrated file to the temp directory, even if a copy of it
                    // already exists there.
                    string sTempMigrated = Path.Combine(Path.GetTempPath(),
                                                        Path.ChangeExtension(Path.GetFileName(sFilename), "." + LiftIO.Validation.Validator.LiftVersion + ".lift"));
                    if (File.Exists(sTempMigrated))
                    {
                        File.Delete(sTempMigrated);
                    }
                    File.Move(sFilename, sTempMigrated);
                }
                progressDialog.Message = "Fixing relation links between imported entries";
                flexImporter.ProcessPendingRelations();
                sLogFile = flexImporter.DisplayNewListItems(inPath, cEntries);
            }
            catch (Exception error)
            {
                string sMsg = String.Format("Something went wrong trying to import {0} while merging...",
                                            inPath, error.Message);
                try
                {
                    StringBuilder bldr = new StringBuilder();
                    // leave in English for programmer's sake...
                    bldr.AppendFormat("Something went wrong while FieldWorks was attempting to import {0}.",
                                      inPath);
                    bldr.AppendLine();
                    bldr.AppendLine(error.Message);
                    bldr.AppendLine();
                    bldr.AppendLine(error.StackTrace);
                    if (System.Threading.Thread.CurrentThread.GetApartmentState() == System.Threading.ApartmentState.STA)
                    {
                        Clipboard.SetDataObject(bldr.ToString(), true);
                    }
                }
                catch
                {
                }
                MessageBox.Show(sMsg, "Problem Merging",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                m_cache.PropChangedHandling = oldPropChg;
            }
            return(sLogFile);
        }
コード例 #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="cache">The FDO cache</param>
		/// <param name="propChangedHandling">How to process PropChanged notifications</param>
		/// ------------------------------------------------------------------------------------
		public IgnorePropChanged(FdoCache cache, PropChangedHandling propChangedHandling)
		{
			m_cache = cache;
			m_oldHandling = m_cache.PropChangedHandling;
			m_cache.PropChangedHandling |= propChangedHandling;
		}
コード例 #4
0
        /// <summary>
        /// Import from a LIFT file.
        /// </summary>
        /// <param name="progressDlg">The progress dialog.</param>
        /// <param name="parameters">The parameters: 1) filename</param>
        /// <returns></returns>
        private object ImportLIFT(IAdvInd4 progressDlg, params object[] parameters)
        {
            m_progressDlg = progressDlg;
            Debug.Assert(parameters.Length == 1);
            string sOrigFile = (string)parameters[0];
            string sLogFile  = null;
            PropChangedHandling oldPropChg = m_cache.PropChangedHandling;

            try
            {
                m_cache.PropChangedHandling = PropChangedHandling.SuppressAll;
                string sFilename;
                bool   fMigrationNeeded = LiftIO.Migration.Migrator.IsMigrationNeeded(sOrigFile);
                if (fMigrationNeeded)
                {
                    string sOldVersion = LiftIO.Validation.Validator.GetLiftVersion(sOrigFile);
                    m_progressDlg.Message = String.Format(LexTextControls.ksMigratingLiftFile,
                                                          sOldVersion, LiftIO.Validation.Validator.LiftVersion);
                    sFilename = LiftIO.Migration.Migrator.MigrateToLatestVersion(sOrigFile);
                }
                else
                {
                    sFilename = sOrigFile;
                }
                if (!Validate(sFilename, sOrigFile))
                {
                    return(sLogFile);
                }
                m_progressDlg.Message = LexTextControls.ksLoadingVariousLists;
                FlexLiftMerger flexImporter = new FlexLiftMerger(m_cache, m_msImport, m_chkTrustModTimes.Checked);
                LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample> parser =
                    new LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample>(flexImporter);
                parser.SetTotalNumberSteps += new EventHandler <LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample> .StepsArgs>(parser_SetTotalNumberSteps);
                parser.SetStepsCompleted   += new EventHandler <LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample> .ProgressEventArgs>(parser_SetStepsCompleted);
                parser.SetProgressMessage  += new EventHandler <LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample> .MessageArgs>(parser_SetProgressMessage);
                flexImporter.LiftFile       = sOrigFile;

                int cEntries = parser.ReadLiftFile(sFilename);

                if (fMigrationNeeded)
                {
                    // Try to move the migrated file to the temp directory, even if a copy of it
                    // already exists there.
                    string sTempMigrated = Path.Combine(Path.GetTempPath(),
                                                        Path.ChangeExtension(Path.GetFileName(sFilename), "." + LiftIO.Validation.Validator.LiftVersion + ".lift"));
                    if (File.Exists(sTempMigrated))
                    {
                        File.Delete(sTempMigrated);
                    }
                    File.Move(sFilename, sTempMigrated);
                }
                m_progressDlg.Message = LexTextControls.ksFixingRelationLinks;
                flexImporter.ProcessPendingRelations();
                sLogFile = flexImporter.DisplayNewListItems(sOrigFile, cEntries);
            }
            catch (Exception error)
            {
                string sMsg = String.Format(LexTextControls.ksLIFTImportProblem,
                                            sOrigFile, error.Message);
                try
                {
                    StringBuilder bldr = new StringBuilder();
                    // leave in English for programmer's sake...
                    bldr.AppendFormat("Something went wrong while FieldWorks was attempting to import {0}.",
                                      sOrigFile);
                    bldr.AppendLine();
                    bldr.AppendLine(error.Message);
                    bldr.AppendLine();
                    bldr.AppendLine(error.StackTrace);

                    if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
                    {
                        Clipboard.SetDataObject(bldr.ToString(), true);
                    }
                    else
                    {
                        SIL.Utils.Logger.WriteEvent(bldr.ToString());
                    }
                }
                catch
                {
                }
                MessageBox.Show(sMsg, LexTextControls.ksProblemImporting,
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
                m_cache.PropChangedHandling = oldPropChg;
            }
            return(sLogFile);
        }