コード例 #1
0
 void parser_SetStepsCompleted(object sender, LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample> .ProgressEventArgs e)
 {
     if (m_progressDlg != null)
     {
         int nMin, nMax;
         m_progressDlg.GetRange(out nMin, out nMax);
         Debug.Assert(nMin < nMax);
         if (nMin >= nMax)
         {
             nMax = nMin + 1;
         }
         int n = e.Progress;
         if (n < nMin)
         {
             n = nMin;
         }
         if (n > nMax)
         {
             while (n > nMax)
             {
                 n = nMin + (n - nMax);
             }
         }
         m_progressDlg.Position = n;
     }
 }
コード例 #2
0
 void parser_SetTotalNumberSteps(object sender, LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample> .StepsArgs e)
 {
     if (m_progressDlg != null)
     {
         m_progressDlg.SetRange(0, e.Steps);
     }
 }
コード例 #3
0
 void parser_SetProgressMessage(object sender, LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample> .MessageArgs e)
 {
     if (m_progressDlg != null)
     {
         m_progressDlg.Message = e.Message;
     }
 }
コード例 #4
0
ファイル: FlexChorusDlg.cs プロジェクト: sillsdev/WorldPad
        void parser_SetStepsCompleted(object sender, LiftIO.Parsing.LiftParser <LiftObject, LiftEntry, LiftSense, LiftExample> .ProgressEventArgs e)
        {
            int nMin, nMax;

            m_progressDlg.GetRange(out nMin, out nMax);
            if (e.Progress > nMax)
            {
                m_progressDlg.Position = e.Progress % nMax;
            }
            else
            {
                m_progressDlg.Position = e.Progress;
            }
        }
コード例 #5
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;
		}
コード例 #6
0
        private object ImportLift(IAdvInd4 progressDlg, params object[] parameters)
        {
            Debug.Assert(parameters.Length == 1);
            m_progressDlg.Message = LexTextControls.ksLoadingVariousLists;
            m_progressDlg.Value   = 0;
            FlexLiftMerger flexImporter = new FlexLiftMerger(m_cache, FlexLiftMerger.MergeStyle.msKeepNew, 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       = (string)parameters[0];
            int cEntries = parser.ReadLiftFile((string)parameters[0]);

            m_progressDlg.Message = LexTextControls.ksFixingRelationLinks;
            flexImporter.ProcessPendingRelations();
            return(flexImporter.DisplayNewListItems((string)parameters[0], cEntries));
        }
コード例 #7
0
ファイル: LiftImportDlg.cs プロジェクト: sillsdev/WorldPad
		/// <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;
		}
コード例 #8
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);
        }
コード例 #9
0
		private object ImportLift(IAdvInd4 progressDlg, params object[] parameters)
		{
			Debug.Assert(parameters.Length == 1);
			m_progressDlg.Message = LexTextControls.ksLoadingVariousLists;
			m_progressDlg.Value = 0;
			FlexLiftMerger flexImporter = new FlexLiftMerger(m_cache, FlexLiftMerger.MergeStyle.msKeepNew, 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 = (string)parameters[0];
			int cEntries = parser.ReadLiftFile((string)parameters[0]);
			m_progressDlg.Message = LexTextControls.ksFixingRelationLinks;
			flexImporter.ProcessPendingRelations();
			return flexImporter.DisplayNewListItems((string)parameters[0], cEntries);
		}
コード例 #10
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);
        }