Exemplo n.º 1
0
		/// <summary>
		/// Export the contents of the lift lexicon.
		/// </summary>
		/// <param name="progressDialog"></param>
		/// <param name="parameters">parameters are not used in this method. This method is called by an invoker,
		/// which requires this signature.</param>
		/// <returns>the name of the exported LIFT file if successful, or null if an error occurs.</returns>
		/// <remarks>
		/// This method is called in a thread, during the export process.
		/// </remarks>
		private object ExportLiftLexicon(IProgress progressDialog, params object[] parameters)
		{
			try
			{
				var projectFolder = Cache.ProjectId.ProjectFolder;
				var liftProjectDir = GetLiftRepositoryFolderFromFwProjectFolder(projectFolder);
				if (!Directory.Exists(liftProjectDir))
				{
					Directory.CreateDirectory(liftProjectDir);
				}
				if (String.IsNullOrEmpty(_liftPathname))
				{
					_liftPathname = Path.Combine(liftProjectDir, Cache.ProjectId.Name + ".lift");
				}
				progressDialog.Message = String.Format(ResourceHelper.GetResourceString("kstidExportingEntries"),
					Cache.LangProject.LexDbOA.Entries.Count());
				progressDialog.Minimum = 0;
				progressDialog.Maximum = Cache.ServiceLocator.GetInstance<ILexEntryRepository>().Count;
				progressDialog.Position = 0;
				progressDialog.AllowCancel = false;

				var exporter = new LiftExporter(Cache);
				exporter.UpdateProgress += OnDumperUpdateProgress;
				exporter.SetProgressMessage += OnDumperSetProgressMessage;
				exporter.ExportPicturesAndMedia = true;
				using (TextWriter textWriter = new StreamWriter(_liftPathname))
				{
					exporter.ExportLift(textWriter, Path.GetDirectoryName(_liftPathname));
				}
				LiftSorter.SortLiftFile(_liftPathname);

				//Output the Ranges file
				var outPathRanges = Path.ChangeExtension(_liftPathname, @"lift-ranges");
				using (var stringWriter = new StringWriter(new StringBuilder()))
				{
					exporter.ExportLiftRanges(stringWriter);
					File.WriteAllText(outPathRanges, stringWriter.ToString());
				}
				LiftSorter.SortLiftRangesFiles(outPathRanges);

				if (File.Exists(FlexNotesPath))
				{

					using (var reader = new StreamReader(FlexNotesPath, Encoding.UTF8))
					using (var writer = new StreamWriter(LiftNotesPath, false, Encoding.UTF8))
					{
						ConvertFlexNotesToLift(reader, writer, Path.GetFileName(_liftPathname));
					}
				}

				return _liftPathname;
			}
			catch
			{
				_liftPathname = null;
				return _liftPathname;
			}
		}
Exemplo n.º 2
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Exports as a LIFT file (possibly with one or more range files.
 /// </summary>
 /// <param name="progress">The progress dialog.</param>
 /// <param name="args">The parameters: (only 1) the output file pathname.
 /// </param>
 /// <returns>Always null.</returns>
 /// ------------------------------------------------------------------------------------
 private object ExportLift(IThreadedProgress progress, object[] args)
 {
     var outPath = (string)args[0];
     var filtered = (bool)args[1];
     m_progressDlg = progress;
     var exporter = new LiftExporter(m_cache);
     exporter.UpdateProgress += OnDumperUpdateProgress;
     exporter.SetProgressMessage += OnDumperSetProgressMessage;
     exporter.ExportPicturesAndMedia = m_fExportPicturesAndMedia;
     #if DEBUG
     var dtStart = DateTime.Now;
     #endif
     using (TextWriter w = new StreamWriter(outPath))
     {
         if (filtered)
         {
             exporter.ExportLift(w, Path.GetDirectoryName(outPath), m_clerk.VirtualListPublisher, m_clerk.VirtualFlid);
         }
         else
         {
             exporter.ExportLift(w, Path.GetDirectoryName(outPath));
         }
     }
     var outPathRanges = Path.ChangeExtension(outPath, ".lift-ranges");
     using (var w =  new StringWriter())
     {
         exporter.ExportLiftRanges(w);
         using (var sw = new StreamWriter(outPathRanges))
         {
             //actually write out to file
             sw.Write(w.GetStringBuilder().ToString());
             sw.Close();
         }
     }
     #if DEBUG
     var dtExport = DateTime.Now;
     #endif
     progress.Message = String.Format(xWorksStrings.ksValidatingOutputFile,
             Path.GetFileName(outPath));
     Validator.CheckLiftWithPossibleThrow(outPath);
     #if DEBUG
     var dtValidate = DateTime.Now;
     var exportDelta = new TimeSpan(dtExport.Ticks - dtStart.Ticks);
     var validateDelta = new TimeSpan(dtValidate.Ticks - dtExport.Ticks);
     Debug.WriteLine(String.Format("Export time = {0}, Validation time = {1}",
         exportDelta, validateDelta));
     #endif
     return null;
 }