private void AddSharedNodesToAlphaConfigurations(DictionaryConfigurationModel model) { if (model.SharedItems.Any()) { m_logger.WriteLine("Not adding shared nodes because some already exist:"); m_logger.IncreaseIndent(); model.SharedItems.ForEach(si => m_logger.WriteLine(DCM.BuildPathStringFromNode(si))); m_logger.DecreaseIndent(); return; } DCM.PerformActionOnNodes(model.Parts, SetReferenceItem); if (model.IsReversal) { var reversalSubEntries = FindMainEntryDescendant(model, "SubentriesOS"); AddSubsubNodeIfNeeded(reversalSubEntries); DictionaryConfigurationController.ShareNodeAsReference(model.SharedItems, reversalSubEntries, "allreversalsubentries"); } else // is Configured Dictionary { var mainEntrySubSenseNode = FindMainEntryDescendant(model, "SensesOS", "SensesOS"); AddSubsubNodeIfNeeded(mainEntrySubSenseNode); DictionaryConfigurationController.ShareNodeAsReference(model.SharedItems, mainEntrySubSenseNode, "mainentrysubsenses"); var mainEntrySubEntries = FindMainEntryDescendant(model, "Subentries"); AddSubsubEntriesOptionsIfNeeded(mainEntrySubEntries); DictionaryConfigurationController.ShareNodeAsReference(model.SharedItems, mainEntrySubEntries, "mainentrysubentries"); } // Remove direct children from nodes with referenced children DCM.PerformActionOnNodes(model.PartsAndSharedItems, n => { if (!string.IsNullOrEmpty(n.ReferenceItem)) { n.Children = null; } }); }
public void MigrateIfNeeded(SimpleLogger logger, Mediator mediator, string appVersion) { m_logger = logger; Cache = (FdoCache)mediator.PropertyTable.GetValue("cache"); var foundOne = string.Format("{0}: Configuration was found in need of migration. - {1}", appVersion, DateTime.Now.ToString("yyyy MMM d h:mm:ss")); var configSettingsDir = FdoFileHelper.GetConfigSettingsDir(Cache.ProjectId.ProjectFolder); var dictionaryConfigLoc = Path.Combine(configSettingsDir, DictionaryConfigurationListener.DictionaryConfigurationDirectoryName); var stemPath = Path.Combine(dictionaryConfigLoc, "Stem" + DictionaryConfigurationModel.FileExtension); var lexemePath = Path.Combine(dictionaryConfigLoc, "Lexeme" + DictionaryConfigurationModel.FileExtension); if (File.Exists(stemPath) && !File.Exists(lexemePath)) { File.Move(stemPath, lexemePath); } foreach (var config in DCM.GetConfigsNeedingMigration(Cache, DCM.VersionCurrent)) { m_logger.WriteLine(foundOne); if (config.Label.StartsWith("Stem-")) { config.Label = config.Label.Replace("Stem-", "Lexeme-"); } m_logger.WriteLine(string.Format("Migrating {0} configuration '{1}' from version {2} to {3}.", config.Type, config.Label, config.Version, DCM.VersionCurrent)); m_logger.IncreaseIndent(); MigrateFrom83Alpha(logger, config, LoadBetaDefaultForAlphaConfig(config)); config.Save(); m_logger.DecreaseIndent(); } }
/// <summary> /// Renames the .fwdictconfig files in the ReversalIndex Folder /// For ex. english.fwdictconfig to en.fwdictconfig /// </summary> /// <param name="configSettingsDir"></param> private static void RenameReversalConfigFiles(string configSettingsDir) { var reversalIndexConfigLoc = Path.Combine(configSettingsDir, DictionaryConfigurationListener.ReversalIndexConfigurationDirectoryName); var dictConfigFiles = new List <string>(DCM.ConfigFilesInDir(reversalIndexConfigLoc)); string newFName = string.Empty; string wsValue = string.Empty; int version = 0; // Rename all the reversals based on the ws id (the user's name for copies is still stored inside the file) foreach (string fName in dictConfigFiles) { wsValue = GetWritingSystemNameAndVersion(fName, out version); if (!string.IsNullOrEmpty(wsValue) && version < DCM.VersionCurrent) { newFName = Path.Combine(Path.GetDirectoryName(fName), wsValue + DictionaryConfigurationModel.FileExtension); if (wsValue == Path.GetFileNameWithoutExtension(fName)) { continue; } newFName = FwUtils.GetUniqueFilename(Path.GetDirectoryName(fName), newFName); File.Move(fName, newFName); } } }
/// <summary>LT-18288: Change Headword to HeadwordRef for All "Referenced Sense Headword" to allow users to select WS</summary> private static void ChangeReferenceSenseHeadwordFieldName(ConfigurableDictionaryNode oldConfigPart) { DCM.PerformActionOnNodes(oldConfigPart.Children, node => { if (node.Label == "Referenced Sense Headword") { node.FieldDescription = "HeadWordRef"; } }); }
/// <summary>LT-18286: One Sharing Parent in Hybrid erroneously got direct children (from a migration step). Remove them.</summary> private static void RemoveHiddenChildren(ConfigurableDictionaryNode parent, ISimpleLogger logger) { DCM.PerformActionOnNodes(parent.Children, p => { if (p.ReferencedNode != null && p.Children != null && p.Children.Any()) { logger.WriteLine(DCM.BuildPathStringFromNode(p) + " contains both Referenced And Direct Children. Removing Direct Children."); p.Children = new List <ConfigurableDictionaryNode>(); } }); }
private static void RemoveReferencedHeadwordSubField(ConfigurableDictionaryNode part) { DCM.PerformActionOnNodes(part.Children, node => { // AllReversalSubentries under Referenced Headword field is ReversalName if (node.FieldDescription == "ReversalName" && node.SubField == "MLHeadWord") { node.SubField = null; } }); }
private static void RemoveMostOfGramInfoUnderRefdComplexForms(ConfigurableDictionaryNode part) { DCM.PerformActionOnNodes(part.Children, node => { // GramInfo under (Other) Ref'd Complex Forms is MorphoSystaxAnalyses // GramInfo under Senses is MorphoSyntaxAnalysisRA and should not lose any children if (node.FieldDescription == "MorphoSyntaxAnalyses") { node.Children.RemoveAll(child => child.FieldDescription != "MLPartOfSpeech"); } }); }
private static void RemoveNonLoadableData(IEnumerable <ConfigurableDictionaryNode> nodes) { DCM.PerformActionOnNodes(nodes, node => { node.ReferenceItem = null; var rsOptions = node.DictionaryNodeOptions as DictionaryNodeReferringSenseOptions; if (rsOptions != null) { node.DictionaryNodeOptions = rsOptions.WritingSystemOptions; } }); }
/// <summary>LT-18920: Change Referringsenses to Senses for all the reversal index configurations.</summary> private static void ChangeReferringsensesToSenses(ConfigurableDictionaryNode part) { if (part.FieldDescription == "ReversalIndexEntry" || part.FieldDescription == "SubentriesOS") { DCM.PerformActionOnNodes(part.Children, node => { if (node.FieldDescription == "ReferringSenses") { node.FieldDescription = "SensesRS"; } }); } }
internal void MigrateFrom83Alpha(DictionaryConfigurationModel alphaModel) { // original migration neglected to update the version number; -1 (Pre83) is the same as 1 (Alpha1) if (alphaModel.Version == PreHistoricMigrator.VersionPre83 || alphaModel.Version == PreHistoricMigrator.VersionAlpha1) { RemoveNonLoadableData(alphaModel.PartsAndSharedItems); } // now that it's safe to specify them, it would be helpful to have parents in certain steps: DictionaryConfigurationModel.SpecifyParentsAndReferences(alphaModel.Parts, alphaModel.SharedItems); switch (alphaModel.Version) { case -1: case 1: case 2: HandleNodewiseChanges(alphaModel.PartsAndSharedItems, m_logger, 2, alphaModel.IsReversal); goto case 3; case 3: HandleNodewiseChanges(alphaModel.PartsAndSharedItems, m_logger, 3, alphaModel.IsReversal); DCM.SetWritingSystemForReversalModel(alphaModel, Cache); AddSharedNodesToAlphaConfigurations(alphaModel); goto case 4; case 4: HandleNodewiseChanges(alphaModel.PartsAndSharedItems, m_logger, 4, alphaModel.IsReversal); goto case VersionAlpha2; case VersionAlpha2: HandleNodewiseChanges(alphaModel.PartsAndSharedItems, m_logger, VersionAlpha2, alphaModel.IsReversal); goto case 6; case 6: HandleNodewiseChanges(alphaModel.PartsAndSharedItems, m_logger, 6, alphaModel.IsReversal); goto case 7; case 7: var fileName = Path.GetFileNameWithoutExtension(alphaModel.FilePath); if (!alphaModel.IsRootBased) { alphaModel.IsRootBased = fileName == DCM.RootFileName; } break; default: m_logger.WriteLine(string.Format( "Unable to migrate {0}: no migration instructions for version {1}", alphaModel.Label, alphaModel.Version)); break; } alphaModel.Version = VersionAlpha3; }
/// <summary> /// Earlier versions of Hybrid mistakenly used VisibleComplexFormBackRefs instead of ComplexFormsNotSubentries. Correct this mistake. /// Referenced Complex Forms should be *Other* Referenced Complex Forms whenever they are siblings of Subentries /// </summary> private static void ChooseAppropriateComplexForms(DictionaryConfigurationModel migratingModel) { if (!migratingModel.IsHybrid) { return; } DCM.PerformActionOnNodes(migratingModel.Parts, parentNode => { if (parentNode.ReferencedOrDirectChildren != null && parentNode.ReferencedOrDirectChildren.Any(node => node.FieldDescription == "Subentries")) { parentNode.ReferencedOrDirectChildren.Where(sib => sib.FieldDescription == "VisibleComplexFormBackRefs").ForEach(sib => { sib.Label = "Other Referenced Complex Forms"; sib.FieldDescription = "ComplexFormsNotSubentries"; }); } }); }
public void MigrateIfNeeded(SimpleLogger logger, Mediator mediator, string appVersion) { m_logger = logger; Cache = (FdoCache)mediator.PropertyTable.GetValue("cache"); var foundOne = string.Format("{0}: Configuration was found in need of migration. - {1}", appVersion, DateTime.Now.ToString("yyyy MMM d h:mm:ss")); foreach (var config in DCM.GetConfigsNeedingMigration(Cache, VersionAlpha3)) { m_logger.WriteLine(foundOne); m_logger.WriteLine(string.Format("Migrating {0} configuration '{1}' from version {2} to {3}.", config.Type, config.Label, config.Version, VersionAlpha3)); m_logger.IncreaseIndent(); MigrateFrom83Alpha(config); config.Save(); m_logger.DecreaseIndent(); } }
private static void UseConfigReferencedEntriesAsPrimary(ConfigurableDictionaryNode part) { if (part.FieldDescription == "ReversalIndexEntry" || part.FieldDescription == "SubentriesOS") { DCM.PerformActionOnNodes(part.Children, node => { if (node.DisplayLabel == "Primary Entry References" && node.FieldDescription == "EntryRefsWithThisMainSense") { node.FieldDescription = "MainEntryRefs"; node.HideCustomFields = true; node.Before = " ("; node.After = ")"; } if (node.DisplayLabel == "Primary Entry(s)" && node.FieldDescription == "PrimarySensesOrEntries") { node.FieldDescription = "ConfigReferencedEntries"; node.CSSClassNameOverride = "referencedentries"; } }); } }
/// <summary> /// Case FirstAlphaMigrator.VersionAlpha3 above will pull in all the new nodes in the Etymology cluster by Label. /// Gloss is the only pre-existing node that doesn't have a new name, so it won't be replaced. /// It needs to be marked Enabled. The main Etymology node needs several modifications. /// Three old nodes will need deleting: Etymological Form, Comment and Source /// </summary> /// <param name="oldConfigPart"></param> /// <param name="oldConfig"></param> private static void UpgradeEtymologyCluster(ConfigurableDictionaryNode oldConfigPart, DictionaryConfigurationModel oldConfig) { if (oldConfigPart.Children == null || oldConfigPart.Children.Count == 0) { return; // safety net } var etymNodes = new List <ConfigurableDictionaryNode>(); DCM.PerformActionOnNodes(oldConfigPart.Children, node => { if (node.Label == "Etymology") { etymNodes.Add(node); // since we have to do some node deleting, just collect up the relevant nodes } }); foreach (var node in etymNodes) { if (node.IsCustomField) // Unfortunately there are some pathological users who have ancient custom fields named etymology { continue; // Leave them be } // modify main node var etymSequence = "EtymologyOS"; if (oldConfig.IsReversal) { node.SubField = etymSequence; node.FieldDescription = "Entry"; node.IsEnabled = true; } else { node.FieldDescription = etymSequence; node.IsEnabled = !oldConfig.IsHybrid; } node.CSSClassNameOverride = "etymologies"; node.Before = "("; node.Between = " "; node.After = ") "; if (node.Children == null) { continue; } // enable Gloss node var glossNode = node.Children.Find(n => n.Label == "Gloss"); if (glossNode != null) { glossNode.IsEnabled = true; } // enable Source Language Notes var notesList = node.Children.Find(n => n.FieldDescription == "LanguageNotes"); if (notesList != null) // ran into some cases where this node didn't exist in reversal config! { notesList.IsEnabled = true; } // remove old children var nodesToRemove = new[] { "Etymological Form", "Comment", "Source" }; node.Children.RemoveAll(n => nodesToRemove.Contains(n.Label)); } // Etymology changed too much to be matched in the PreHistoricMigration and was marked as custom DCM.PerformActionOnNodes(etymNodes, n => { n.IsCustomField = false; }); }
/// <remarks> /// Handles various kinds of configuration node changes that happened post-8.3Alpha1. /// It should no longer be necessary to add changes in two places /// [except: see caveat on PreHistoricMigrator.HandleChildNodeRenaming()] /// </remarks> private static void HandleNodewiseChanges(IEnumerable <ConfigurableDictionaryNode> nodes, ISimpleLogger logger, int version, bool isReversal) { var newHeadword = isReversal ? "ReversalName" : "HeadWordRef"; switch (version) { case 2: DCM.PerformActionOnNodes(nodes, n => { if (n.FieldDescription == "OwningEntry" && n.SubField == "MLHeadWord") { n.SubField = newHeadword; } }); break; case 3: DCM.PerformActionOnNodes(nodes, n => { if (n.Label == "Gloss (or Summary Definition)") { n.FieldDescription = "GlossOrSummary"; } if (n.Parent == null) { return; } if (n.Parent.FieldDescription == "ExamplesOS" && n.FieldDescription == "Example") { n.Label = "Example Sentence"; } else if (n.Parent.FieldDescription == "ReferringSenses") { if (n.FieldDescription == "Owner" && n.SubField == "Bibliography") { n.Label = "Bibliography (Entry)"; } else if (n.FieldDescription == "Bibliography") { n.Label = "Bibliography (Sense)"; } } }); break; case 4: DCM.PerformActionOnNodes(nodes, n => { switch (n.FieldDescription) { case "TranslationsOC": n.CSSClassNameOverride = "translationcontents"; break; case "ExamplesOS": n.CSSClassNameOverride = "examplescontents"; n.StyleType = ConfigurableDictionaryNode.StyleTypes.Character; n.DictionaryNodeOptions = new DictionaryNodeListAndParaOptions(); // allow to be shown in paragraph break; } }); break; case VersionAlpha2: DCM.PerformActionOnNodes(nodes, n => { if (n.FieldDescription == null) { logger.WriteLine(string.Format("Warning: '{0}' reached the Alpha2 migration with a null FieldDescription.", DCM.BuildPathStringFromNode(n))); return; } if (n.FieldDescription == "VisibleVariantEntryRefs" && n.Label == "Variant Of") { n.Label = "Variant of"; } else if (n.FieldDescription.Contains("EntryType")) { var parentFd = n.Parent.FieldDescription; if (n.FieldDescription == ConfiguredXHTMLGenerator.LookupComplexEntryType || isReversal && (n.FieldDescription == "VariantEntryTypesRS" || n.FieldDescription == "ComplexEntryTypesRS")) { if (parentFd == "ComplexFormEntryRefs") { // set type children to RevAbbr/RevName SetEntryTypeChildrenBackward(n); } else { // set type children to Abbr/Name SetEntryTypeChildrenForward(n); } } else if (parentFd.EndsWith("BackRefs") || parentFd == "ComplexFormsNotSubentries") { // set type children to Abbr/Name SetEntryTypeChildrenForward(n); } else { // set type children to RevAbbr/RevName SetEntryTypeChildrenBackward(n); } } else if ((n.Label == "Headword" && n.Parent.FieldDescription == "ReferringSenses") || (n.Label == "Form" && n.Parent.Label.StartsWith("Subentry Under"))) { n.Label = "Referenced Headword"; } else if (n.Label == "Subsenses" && n.Parent.FieldDescription == "SensesOS") { var senseNode = (DictionaryNodeSenseOptions)n.DictionaryNodeOptions; if (senseNode != null) { senseNode.ParentSenseNumberingStyle = "%."; senseNode.NumberingStyle = "%d"; n.DictionaryNodeOptions = senseNode; } } else if (n.Label == "Allomorphs" && n.FieldDescription == "Owner") { n.FieldDescription = "Entry"; } if (n.Label == "Referenced Headword") { n.FieldDescription = newHeadword; if (isReversal && n.DictionaryNodeOptions == null) { n.DictionaryNodeOptions = new DictionaryNodeWritingSystemOptions { WsType = DictionaryNodeWritingSystemOptions.WritingSystemType.Vernacular, Options = new List <DictionaryNodeListOptions.DictionaryNodeOption> { new DictionaryNodeListOptions.DictionaryNodeOption { Id = "vernacular", IsEnabled = true } } } } ; } }); break; case 6: DCM.PerformActionOnNodes(nodes, n => { if (isReversal && n.Label == "Pronunciation" && n.Parent.Label == "Pronunciations") { var parent = n.Parent; parent.Before = "["; parent.Between = " "; parent.After = "] "; n.Before = ""; n.Between = ""; n.After = " "; } UpdatePicturesChildren(n); }); break; } }