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; } }); }
/// <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>(); } }); }
/// <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; } }