/// <summary> /// Export the contents of the lift lexicon. /// </summary> /// <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); var liftPathname = _liftPathname; if (!Directory.Exists(liftProjectDir)) { Directory.CreateDirectory(liftProjectDir); } if (liftPathname == null) { liftPathname = Path.Combine(liftProjectDir, Cache.ProjectId.Name + ".lift"); } var outPath = liftPathname + ".tmp"; 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(outPath)) { exporter.ExportLift(textWriter, Path.GetDirectoryName(outPath)); } //Output the Ranges file var pathWithFilename = outPath.Substring(0, outPath.Length - @".lift.tmp".Length); var outPathRanges = Path.ChangeExtension(pathWithFilename, @"lift-ranges"); using (var stringWriter = new StringWriter(new StringBuilder())) { exporter.ExportLiftRanges(stringWriter); using (var xmlWriter = XmlWriter.Create(outPathRanges, CanonicalXmlSettings.CreateXmlWriterSettings())) { var doc = new XmlDocument(); doc.LoadXml(stringWriter.ToString()); doc.WriteContentTo(xmlWriter); } return(outPath); } } catch { return(null); } }
/// <summary> /// Prepare custom fields to be included in dictionary configuration export. LT-17397. /// Returns paths to files to be included in a zipped export. /// </summary> internal static IEnumerable <string> PrepareCustomFieldsExport(FdoCache cache) { var exporter = new LiftExporter(cache); var liftFile = Path.Combine(Path.GetTempPath(), "DictExportCustomLift", "CustomFields.lift"); var rangesFile = Path.Combine(Path.GetTempPath(), "DictExportCustomLift", "CustomFields.lift-ranges"); Directory.CreateDirectory(Path.GetDirectoryName(liftFile)); using (TextWriter textWriter = new StreamWriter(liftFile)) { exporter.ExportLift(textWriter, Path.GetDirectoryName(liftFile), new ILexEntry[0], 0); } using (var stringWriter = new StringWriter()) { exporter.ExportLiftRanges(stringWriter); stringWriter.Flush(); File.WriteAllText(rangesFile, stringWriter.ToString()); } return(new[] { liftFile, rangesFile }); }