/// <summary> /// Validate the essence alias between two facts referenced in a definition arc using /// the set of all facts in the fragment. /// </summary> /// <param name="EssenceAliasDefinitionArc"> /// The definition arc defining the essence alias. /// </param> /// <param name="FactList"> /// A collection of <see cref="Fact"/> objects defined in the fragment. /// </param> private void ValidateEssenceAliasedFacts(DefinitionArc EssenceAliasDefinitionArc, FactCollection FactList) { Locator CurrentFromLocator = EssenceAliasDefinitionArc.FromLocator; if (CurrentFromLocator == null) { throw new NullReferenceException("FromLocator is NULL in ValidateEssenceAliasedFacts()"); } Locator CurrentToLocator = EssenceAliasDefinitionArc.ToLocator; foreach (Fact CurrentFact in FactList) { if (CurrentFact is Item) { var CurrentItem = CurrentFact as Item; if (CurrentItem.Name.Equals(CurrentFromLocator.HrefResourceId) == true) { ValidateEssenceAliasedFacts(CurrentItem, FactList, CurrentToLocator.HrefResourceId); } } else if (CurrentFact is Tuple) { var CurrentTuple = CurrentFact as Tuple; ValidateEssenceAliasedFacts(EssenceAliasDefinitionArc, CurrentTuple.Facts); } } }
//------------------------------------------------------------------------------- // Validate the "requires element" connection between two facts referenced in a // definition arc. //------------------------------------------------------------------------------- private void ValidateRequiresElementFacts(DefinitionArc RequiresElementDefinitionArc) { Locator CurrentFromLocator = RequiresElementDefinitionArc.FromLocator; Locator CurrentToLocator = RequiresElementDefinitionArc.ToLocator; int FromFactCount = CountFactInstances(CurrentFromLocator.HrefResourceId); int ToFactCount = CountFactInstances(CurrentToLocator.HrefResourceId); if (FromFactCount > ToFactCount) { StringBuilder MessageBuilder = new StringBuilder(); string StringFormat = AssemblyResources.GetName("NotEnoughToFactsInRequiresElementRelationship"); MessageBuilder.AppendFormat(StringFormat, CurrentFromLocator.HrefResourceId, CurrentToLocator.HrefResourceId); validatingFragment.AddValidationError(new DefinitionArcValidationError(RequiresElementDefinitionArc, MessageBuilder.ToString())); } }
/// <summary> /// Validate the essence alias between two facts referenced in a definition arc using /// the set of all facts in the fragment. /// </summary> /// <param name="EssenceAliasDefinitionArc"> /// The definition arc defining the essence alias. /// </param> private void ValidateEssenceAliasedFacts(DefinitionArc EssenceAliasDefinitionArc) { ValidateEssenceAliasedFacts(EssenceAliasDefinitionArc, validatingFragment.Facts); }
private Linkbase CreateDefinitionLinkbase(Taxonomy taxonomy, DiscoverableTaxonomySet dts) { var linkbase = new Linkbase(GetLinkbaseFileName(taxonomy, "def")); var memberItems = ExtensionItems.OfType <ExtensionMember>().ToList(); var groupedByHypercube = memberItems.SelectMany(i => i.Locations.Select(l => new { l.HypercubeName, Location = l, Item = i })) .GroupBy(d => d.HypercubeName) .ToList(); foreach (var groupByHypercube in groupedByHypercube) { var hypercubeNode = dts.GetAllLinks() .Where(l => l.ElementName == LinkbaseXNames.Definition) .SelectMany(l => l.NodesMap.Values) .OfType <LocatorNode>() .SingleOrDefault(ln => ln.Item.Name == groupByHypercube.Key); if (hypercubeNode == null) { throw new InvalidOperationException($"Could not find a hypercube (aka table) {groupByHypercube.Key} in the DTS."); } var definitionLink = new DefinitionLink(LinkbaseXNames.Definition, hypercubeNode.Link.Role); linkbase.AddLink(definitionLink, dts); var locCount = 0; foreach (var locationAndItem in groupByHypercube) { var dimensionLocationNode = hypercubeNode.FromArcs .OfType <DefinitionArc>() .Select(da => da.ToLocator) .SingleOrDefault(ln => ln.Item.Name == locationAndItem.Location.DimensionName); if (dimensionLocationNode == null) { throw new InvalidOperationException($"Could not find a dimension (aka axis) {locationAndItem.Location.DimensionName} in the hypercube (aka table) {groupByHypercube.Key}."); } var parentNodeInBaseTaxonomy = FindParentNode(dimensionLocationNode, locationAndItem.Location.ParentName); if (parentNodeInBaseTaxonomy == null) { throw new InvalidOperationException($"There is no member {locationAndItem.Location.ParentName} in the dimension {groupByHypercube.Key}."); } var siblingArcs = parentNodeInBaseTaxonomy.GetOrderedOutgoingHierarchicalArcs <DefinitionArc>(); double newOrder; try { newOrder = DetermineOrder(locationAndItem.Location.PrecedingSiblingName, siblingArcs); } catch (InvalidOperationException ex) { throw new InvalidOperationException($"The sibling {locationAndItem.Location.PrecedingSiblingName} was not found as a child of {locationAndItem.Location.ParentName} in the dimension {groupByHypercube.Key}.", ex); } var parentLocLabel = $"loc_{locCount}"; locCount += 1; var parentNode = new LocatorNode(parentLocLabel, parentNodeInBaseTaxonomy.Item); definitionLink.AddNode(parentNode); var locLabel = $"loc_{locCount}"; locCount += 1; var locNode = CreateLocatorNode(locLabel, locationAndItem.Item, dts); definitionLink.AddNode(locNode); var arc = new DefinitionArc(parentNode, locNode, newOrder); definitionLink.AddArc(arc); } } return(linkbase); }