/// <summary> /// Prepare stylesheet to be included in dictionary configuration export. LT-17397. /// Returns paths to files to be included in a zipped export. /// </summary> internal static string PrepareStylesheetExport(FdoCache cache) { var projectStyles = new FlexStylesXmlAccessor(cache.LangProject.LexDbOA, true); var serializer = new XmlSerializer(typeof(FlexStylesXmlAccessor)); var tempFile = Path.Combine(Path.GetTempPath(), "DictExportStyles", "CustomStyles.xml"); Directory.CreateDirectory(Path.GetDirectoryName(tempFile)); using (var textWriter = new StreamWriter(tempFile)) { serializer.Serialize(textWriter, projectStyles); } return(tempFile); }
private void ImportStyles(string importStylesLocation) { var stylesToRemove = _cache.LangProject.StylesOC.Where(style => !UnsupportedStyles.Contains(style.Name)); // For LT-18267, record basedon and next properties of styles not // being exported, so they can be reconnected to the imported // styles of the same name. var preimportStyleLinks = _cache.LangProject.StylesOC.Where(style => UnsupportedStyles.Contains(style.Name)).ToDictionary( style => style.Name, style => new { BasedOn = style.BasedOnRA == null ? null : style.BasedOnRA.Name, Next = style.NextRA == null ? null : style.NextRA.Name }); NonUndoableUnitOfWorkHelper.DoSomehow(_cache.ActionHandlerAccessor, () => { // Before importing styles, remove all the current styles, except // for styles that we don't support and so we don't expect will // be imported. foreach (var style in stylesToRemove) { _cache.LangProject.StylesOC.Remove(style); } }); // Be sure that the Remove action is committed and saved to disk before we re-import styles with the same guid. // If we don't then the changes won't be noticed as the Styles will be marked as transient and won't be saved. _cache.ActionHandlerAccessor.Commit(); // Import styles NonUndoableUnitOfWorkHelper.DoSomehow(_cache.ActionHandlerAccessor, () => { // ReSharper disable once UnusedVariable -- The FlexStylesXmlAccessor constructor does the work of importing. var stylesAccessor = new FlexStylesXmlAccessor(_cache.LangProject.LexDbOA, true, importStylesLocation); var postimportStylesToReconnect = _cache.LangProject.StylesOC.Where(style => UnsupportedStyles.Contains(style.Name)); postimportStylesToReconnect.ForEach(postimportStyleToRewire => { var correspondingPreImportStyleInfo = preimportStyleLinks[postimportStyleToRewire.Name]; postimportStyleToRewire.BasedOnRA = _cache.LangProject.StylesOC.FirstOrDefault(style => style.Name == correspondingPreImportStyleInfo.BasedOn); postimportStyleToRewire.NextRA = _cache.LangProject.StylesOC.FirstOrDefault(style => style.Name == correspondingPreImportStyleInfo.Next); }); }); }
private void ImportStyles(string importStylesLocation) { NonUndoableUnitOfWorkHelper.DoSomehow(_cache.ActionHandlerAccessor, () => { var stylesToRemove = _cache.LangProject.StylesOC.Where(style => !UnsupportedStyles.Contains(style.Name)); // For LT-18267, record basedon and next properties of styles not // being exported, so they can be reconnected to the imported // styles of the same name. var preimportStyleLinks = _cache.LangProject.StylesOC.Where(style => UnsupportedStyles.Contains(style.Name)).ToDictionary( style => style.Name, style => new { BasedOn = style.BasedOnRA == null ? null : style.BasedOnRA.Name, Next = style.NextRA == null ? null : style.NextRA.Name }); // Before importing styles, remove all the current styles, except // for styles that we don't support and so we don't expect will // be imported. foreach (var style in stylesToRemove) { _cache.LangProject.StylesOC.Remove(style); } // Import styles var stylesAccessor = new FlexStylesXmlAccessor(_cache.LangProject.LexDbOA, true, importStylesLocation); var postimportStylesToReconnect = _cache.LangProject.StylesOC.Where(style => UnsupportedStyles.Contains(style.Name)); postimportStylesToReconnect.ForEach(postimportStyleToRewire => { var correspondingPreImportStyleInfo = preimportStyleLinks[postimportStyleToRewire.Name]; postimportStyleToRewire.BasedOnRA = _cache.LangProject.StylesOC.FirstOrDefault(style => style.Name == correspondingPreImportStyleInfo.BasedOn); postimportStyleToRewire.NextRA = _cache.LangProject.StylesOC.FirstOrDefault(style => style.Name == correspondingPreImportStyleInfo.Next); }); }); }