internal string GetLocatorLabel(Node childNode, ref int priority) { if (childLocatorsByHRef != null) { ChildPresentationLocator cpl = childLocatorsByHRef[childNode.Id] as ChildPresentationLocator; if (cpl != null) { for (int i = cpl.LocatorRelationshipInfos.Count - 1; i >= 0; i--) { LocatorRelationshipInfo lri = cpl.LocatorRelationshipInfos[i] as LocatorRelationshipInfo; if (lri.Order == (float)childNode.order && lri.PrefLabel == childNode.PreferredLabel && lri.CalculationWeight == childNode.Weight) { priority = lri.Priority; return(lri.Label); } } LocatorRelationshipInfo netRel = cpl.NetRelationShipInfo; priority = netRel.Priority; return(netRel.Label); } } return(null); }
/// <summary> /// Determines whether a supplied <see cref="Object"/> is equal to this <see cref="LocatorRelationshipInfo"/>. /// </summary> /// <param name="obj">The <see cref="Object"/> to be compared to this <see cref="LocatorRelationshipInfo"/>. /// Assumed to be a <see cref="LocatorRelationshipInfo"/>.</param> /// <returns>True if <paramref name="obj"/> is equal to this <see cref="LocatorRelationshipInfo"/>.</returns> /// <remarks>To be equal, <see cref="BaseEquals"/> must be true and the "IsProhibited" and /// "Priority" properties in the two <see cref="LocatorRelationshipInfo"/> must be equal.</remarks> public override bool Equals(object obj) { LocatorRelationshipInfo lri = obj as LocatorRelationshipInfo; if (lri == null) { return(false); } if (!BaseEquals(lri)) { return(false); } if (lri.IsProhibited != IsProhibited) { return(false); } if (lri.Priority != Priority) { return(false); } return(true); }
public void AddChild(PresentationLocator childPl, string label, string priority, float orderArg, string prefLabel, string weight, bool isProhibited) { childPl.AddParent(this); if (this.childLocatorsByHRef == null) { this.childLocatorsByHRef = new HybridDictionary(); this.childDisplayOrder = new HybridDictionary(); } LocatorRelationshipInfo newRelation = LocatorRelationshipInfo.CreateObj(label, priority, orderArg, orderArg, prefLabel, weight, isProhibited); ChildPresentationLocator cpl = childLocatorsByHRef[childPl.HRef] as ChildPresentationLocator; if (cpl == null) { // doesn't exist in either the href table or the order table cpl = new ChildPresentationLocator(childPl.HRef, newRelation); childLocatorsByHRef.Add(childPl.HRef, cpl); // keep these separate so they don't impact each other ChildPresentationLocator cplOrder = new ChildPresentationLocator(cpl); } else { // the cpl already exists, append the existing relation info cpl.AddRelationship(newRelation); } }
/// <summary> /// Adds a parameter-supplied <see cref="LocatorRelationshipInfo"/> to /// this <see cref="ChildPresentationLocator"/>'s collection of /// <see cref="LocatorRelationshipInfo"/>. /// </summary> /// <param name="newRelation">The <see cref="LocatorRelationshipInfo"/> that method /// is to add.</param> public void AddRelationship(LocatorRelationshipInfo newRelation) { if (CanAddRelationship(newRelation)) { this.locatorRelationshipInfos.Add(newRelation); locatorRelationshipInfos.Sort(); } }
/// <summary> /// Overloaded. Creates a new instance of <see cref="LocatorRelationshipInfo"/> /// and copies properties from a parameter-supplied <see cref="LocatorRelationshipInfo"/> /// to the newly created <see cref="LocatorRelationshipInfo"/>. /// </summary> /// <param name="lri">The <see cref="LocatorRelationshipInfo"/> from which properties are /// to be copied to the newly created <see cref="LocatorRelationshipInfo"/>.</param> public LocatorRelationshipInfo(LocatorRelationshipInfo lri) { this.isProhibited = lri.isProhibited; this.label = lri.label; this.order = lri.order; this.priority = lri.priority; this.weight = lri.weight; this.origOrder = lri.origOrder; this.prefLabel = lri.prefLabel; }
/// <summary> /// Overloaded. Creates a new instance of <see cref="LocatorRelationshipInfo"/> /// and copies properties from a parameter-supplied <see cref="LocatorRelationshipInfo"/> /// to the newly created <see cref="LocatorRelationshipInfo"/>. /// </summary> /// <param name="lri">The <see cref="LocatorRelationshipInfo"/> from which properties are /// to be copied to the newly created <see cref="LocatorRelationshipInfo"/>.</param> public LocatorRelationshipInfo(LocatorRelationshipInfo lri) { this.isProhibited = lri.isProhibited; this.label = lri.label; this.order = lri.order; this.priority = lri.priority; this.weight = lri.weight; this.origOrder = lri.origOrder; this.prefLabel = lri.prefLabel; }
// public ChildPresentationLocator( string hRef, string label, // string priority, // float orderArg, string prefLabel, string weight, bool isProhibited ) : base( href, LocatorRelationshipInfo.CreateObj(label, priority, // orderArg, prefLabel, weight, isProhibited ) ) // { // } #endregion #region Public methods /// <summary> /// Determines if a parameter-supplied <see cref="LocatorRelationshipInfo"/> can /// be added to this <see cref="ChildPresentationLocator"/>'s collection of /// <see cref="LocatorRelationshipInfo"/>. A <see cref="LocatorRelationshipInfo"/> /// can be added it is not already present in the collection. /// </summary> /// <param name="newRelation">The <see cref="LocatorRelationshipInfo"/> for which /// method is to search.</param> /// <returns>True if <paramref name="newRelation"/> can be added (if it is not found /// in the collection. False otherwise.</returns> public bool CanAddRelationship(LocatorRelationshipInfo newRelation) { foreach (LocatorRelationshipInfo lri in this.locatorRelationshipInfos) { if (lri.Equals(newRelation)) { return(false); } } return(true); }
/// <summary> /// Add a new relationship between two locators... /// </summary> /// <param name="elementId"></param> /// <param name="parentElementId"></param> /// <param name="newLocatorRelationshipInfo"></param> /// <param name="taxonomy"></param> /// <returns></returns> public bool UpdateArc(string elementId, string parentElementId, LocatorRelationshipInfo newLocatorRelationshipInfo, Taxonomy taxonomy) { PresentationLocator parentLocator = locators[parentElementId] as PresentationLocator; if (parentLocator == null && !string.IsNullOrEmpty(parentElementId)) { parentLocator = new PresentationLocator(); parentLocator.href = parentElementId; parentLocator.MyElement = taxonomy.allElements[parentElementId] as Element; locators[parentElementId] = parentLocator; } PresentationLocator childLocator = locators[elementId] as PresentationLocator; if (childLocator == null) { childLocator = new PresentationLocator(); childLocator.href = elementId; childLocator.MyElement = taxonomy.allElements[elementId] as Element; if (parentLocator != null) { childLocator.AddParent(parentLocator); } locators[elementId] = childLocator; } if (parentLocator != null) { if (parentLocator.childLocatorsByHRef == null) { parentLocator.childLocatorsByHRef = new HybridDictionary(); } ChildPresentationLocator cpl = parentLocator.childLocatorsByHRef[elementId] as ChildPresentationLocator; if (cpl != null) { cpl.AddRelationship(newLocatorRelationshipInfo); } else { cpl = new ChildPresentationLocator(elementId, newLocatorRelationshipInfo); parentLocator.childLocatorsByHRef[elementId] = cpl; } } return(true); }
/// <summary> /// Determines whether a supplied <see cref="LocatorRelationshipInfo"/> is equal to this <see cref="LocatorRelationshipInfo"/>. /// </summary> /// <param name="lri">The <see cref="LocatorRelationshipInfo"/> to be compared to this <see cref="LocatorRelationshipInfo"/>.</param> /// <returns>True if <paramref name="lri"/> is equal to this <see cref="LocatorRelationshipInfo"/>.</returns> /// <remarks>To be equal, the label, preferred label, order, original order, and /// calculation weight properties in the two <see cref="LocatorRelationshipInfo"/> must be equal.</remarks> public bool BaseEquals(LocatorRelationshipInfo lri) { if (this.label != null) { if (this.label.CompareTo(lri.Label) != 0) { return(false); } } else if (lri.Label != null) { return(false); } if (prefLabel != null) { if (prefLabel.CompareTo(lri.PrefLabel) != 0) { return(false); } } else if (lri.prefLabel != null) { return(false); } if (lri.Order != Order) { return(false); } if (lri.origOrder != origOrder) { return(false); } if (lri.CalculationWeight.CompareTo(CalculationWeight) != 0) { return(false); } return(true); }
internal bool IsChildProhibited(string id, double order) { ChildPresentationLocator cpl = childLocatorsByHRef[id] as ChildPresentationLocator; if (cpl != null) { for (int i = cpl.LocatorRelationshipInfos.Count - 1; i >= 0; i--) { LocatorRelationshipInfo lri = cpl.LocatorRelationshipInfos[i] as LocatorRelationshipInfo; if (lri.Order == order) { return(lri.IsProhibited); } } return(cpl.NetRelationShipInfo.IsProhibited); } return(false); }
virtual internal bool IsNonXlinkEquivalentRelationship(LocatorRelationshipInfo other) { if (!this.origOrder.Equals(other.origOrder)) { return(false); } if (!this.weight.Equals(other.weight)) { return(false); } string thisLabel = string.IsNullOrEmpty(this.prefLabel) ? string.Empty : this.prefLabel; string otherLabel = string.IsNullOrEmpty(other.prefLabel) ? string.Empty : other.prefLabel; if (!thisLabel.Equals(otherLabel)) { return(false); } return(true); }
public static LocatorRelationshipInfo CreateObj(string label, string priority, float origOrder, float orderArg, string prefLabel, string weight, bool isProhibited) { LocatorRelationshipInfo obj = new LocatorRelationshipInfo(); obj.label = label; obj.isProhibited = isProhibited; obj.prefLabel = prefLabel; obj.order = orderArg; obj.origOrder = origOrder; obj.priority = Convert.ToInt32(priority); obj.weight = weight; if (prefLabel != null) { int lastSlash = prefLabel.LastIndexOf("/") + 1; obj.prefLabel = prefLabel.Substring(lastSlash, prefLabel.Length - lastSlash); } return(obj); }
/// <summary> /// Compares this instance of <see cref="LocatorRelationshipInfo"/> to a supplied <see cref="Object"/>. /// </summary> /// <param name="obj">An <see cref="object"/> to which this instance of <see cref="LocatorRelationshipInfo"/> /// is to be compared. Assumed to be a <see cref="LocatorRelationshipInfo"/>.</param> /// <returns>An <see cref="int"/> indicating if <paramref name="obj"/> is less than (<0), /// greater than (>0), or equal to (0) this instance of <see cref="LocatorRelationshipInfo"/>.</returns> /// <remarks>The following <see cref="LocatorRelationshipInfo"/> properties are compared in order: /// <bl> /// <li>Original order.</li> /// <li>Priority.</li> /// <li>Prohibited.</li> /// </bl> /// </remarks> public int CompareTo(object obj) { LocatorRelationshipInfo other = (LocatorRelationshipInfo)obj; string thisLabel = string.IsNullOrEmpty(this.prefLabel) ? string.Empty : this.prefLabel; string otherLabel = string.IsNullOrEmpty(other.prefLabel) ? string.Empty : other.prefLabel; int ret = thisLabel.CompareTo(otherLabel); if (ret != 0) { return(ret); } ret = this.weight.CompareTo(other.weight); if (ret != 0) { return(ret); } ret = this.origOrder.CompareTo(other.origOrder); if (ret != 0) { return(ret); } ret = this.Priority.CompareTo(other.priority); if (ret != 0) { return(ret); } //false before true... return(this.isProhibited.CompareTo(other.isProhibited)); }
public Node CreateNode(string lang, string role, int level, string currentId, Node parentNode, LocatorRelationshipInfo relation, PresentationLink pLink, bool recursive, Dimension dimensionInfo) { Node current = null; if (e == null && pLink != null) { /* Something went wrong during mergePresentation because we should have an element at * this point. Go to the presentationLink and try to get the element. */ PresentationLocator loc = null; pLink.TryGetLocator(this.HRef, out loc); if (loc != null && loc.MyElement != null) { //update the element and the child locators e = loc.MyElement; this.childLocatorsByHRef = loc.childLocatorsByHRef; } } if (e == null) { //it is a locator to an invalid element //just return null at this point... return(null); } //make sure we have the right element if there's a parent (there could be clones) Element elementToUse = e; if (dimensionInfo != null && elementToUse != null) { if (elementToUse.IsDimensionItem()) { //get the parent node if (parentNode != null) { //DimensionNode hierNode; //if (dimensionInfo.TryGetHypercubeNode(lang, // role, pLink.Role, parentNode.Id, out hierNode)) //{ // foreach (DimensionNode dn in hierNode.Children) // { // if (dn.Id == elementToUse.Id) // { // if (parentNode != null) // { // and add it // parentNode.AddChild(dn); // } // return dn; // } // } //} DimensionNode hierNode; if (dimensionInfo.TryGetHypercubeNode(lang, role, pLink.Role, parentNode.Id, true, out hierNode)) { if (hierNode.Children != null) { foreach (DimensionNode dn in hierNode.Children) { if (dn.Id == elementToUse.Id) { if (parentNode != null) { // and add it parentNode.AddChild(dn); } return(dn); } } } return(null); //strange ..could not find the correct hierarchy.. } else { return(null); } } } } current = elementToUse == null ? new Node(href) : elementToUse.CreateNode(lang, role, false); if (relation != null) { current.SetOrder(relation.Order); current.CalculationWeight = relation.CalculationWeight; if (preferredLabelRole.Equals(role)) { if (relation.PrefLabel != null) { current.UpdatePreferredLabel(lang, relation.PrefLabel); } } // now check to see if it's prohibited current.IsProhibited = relation.IsProhibited; } if (parentNode != null) { // and add it parentNode.AddChild(current); } if (childLocatorsByHRef != null && recursive) { foreach (ChildPresentationLocator cpl in childLocatorsByHRef.Values) { PresentationLocator childLocator; if (!pLink.TryGetLocator(cpl.HRef, out childLocator)) { continue; } bool innerRecursive = true; if (parentNode != null && parentNode.GetParent(cpl.HRef) != null) { //this might be ok if one of the links is a prohibitted link... innerRecursive = false; //looks like we have a recursion... } //organize locators by base order //we should have only one valid LocatorRelationshipInfo for each non xlink information... LocatorRelationshipInfo currentRelationShip = null; for (int i = cpl.LocatorRelationshipInfos.Count - 1; i >= 0; i--) { LocatorRelationshipInfo lri = cpl.LocatorRelationshipInfos[i] as LocatorRelationshipInfo; if (currentRelationShip != null && lri.IsNonXlinkEquivalentRelationship(currentRelationShip)) { continue; } currentRelationShip = lri; // always create the child childLocator.CreateNode(lang, role, level + 1, cpl.HRef, current, lri, pLink, innerRecursive, dimensionInfo); } } //need to sort the nodes if (current.Children != null) { current.Children.Sort(new NodeOrderSorter()); } } return(current); }
/// <summary> /// Creates a new instance of <see cref="ChildDefinitionLocator"/>. /// </summary> public ChildDefinitionLocator( string hRef, LocatorRelationshipInfo info ) { this.hRef = hRef; locatorRelationshipInfos.Add( info ); }
/// <summary> /// Determines whether a supplied <see cref="LocatorRelationshipInfo"/> is equal to this <see cref="LocatorRelationshipInfo"/>. /// </summary> /// <param name="lri">The <see cref="LocatorRelationshipInfo"/> to be compared to this <see cref="LocatorRelationshipInfo"/>.</param> /// <returns>True if <paramref name="lri"/> is equal to this <see cref="LocatorRelationshipInfo"/>.</returns> /// <remarks>To be equal, the label, preferred label, order, original order, and /// calculation weight properties in the two <see cref="LocatorRelationshipInfo"/> must be equal.</remarks> public bool BaseEquals(LocatorRelationshipInfo lri) { if ( this.label != null ) { if ( this.label.CompareTo( lri.Label ) != 0 ) return false; } else if ( lri.Label != null ) { return false; } if ( prefLabel != null ) { if ( prefLabel.CompareTo( lri.PrefLabel ) != 0 ) return false; } else if ( lri.prefLabel != null ) { return false; } if ( lri.Order != Order ) return false; if ( lri.origOrder != origOrder ) return false; if ( lri.CalculationWeight.CompareTo( CalculationWeight ) != 0 ) return false; return true; }
public static LocatorRelationshipInfo CreateObj( string label, string priority, float origOrder, float orderArg, string prefLabel, string weight, bool isProhibited) { LocatorRelationshipInfo obj = new LocatorRelationshipInfo(); obj.label = label; obj.isProhibited = isProhibited; obj.prefLabel = prefLabel; obj.order = orderArg; obj.origOrder = origOrder; obj.priority = Convert.ToInt32( priority ); obj.weight = weight; if ( prefLabel != null ) { int lastSlash = prefLabel.LastIndexOf( "/" )+1; obj.prefLabel = prefLabel.Substring( lastSlash, prefLabel.Length - lastSlash ); } return obj; }
internal virtual bool IsNonXlinkEquivalentRelationship(LocatorRelationshipInfo other) { if (!this.origOrder.Equals(other.origOrder)) return false; if (!this.weight.Equals(other.weight)) return false; string thisLabel = string.IsNullOrEmpty(this.prefLabel) ? string.Empty : this.prefLabel; string otherLabel = string.IsNullOrEmpty(other.prefLabel) ? string.Empty : other.prefLabel; if (!thisLabel.Equals(otherLabel)) return false; return true; }
/// <summary> /// Add a new relationship between two locators... /// </summary> /// <param name="elementId"></param> /// <param name="parentElementId"></param> /// <param name="newLocatorRelationshipInfo"></param> /// <param name="taxonomy"></param> /// <returns></returns> public bool UpdateArc(string elementId, string parentElementId , LocatorRelationshipInfo newLocatorRelationshipInfo, Taxonomy taxonomy ) { PresentationLocator parentLocator = locators[parentElementId] as PresentationLocator; if (parentLocator == null && !string.IsNullOrEmpty(parentElementId)) { parentLocator = new PresentationLocator(); parentLocator.href = parentElementId; parentLocator.MyElement = taxonomy.allElements[parentElementId] as Element; locators[parentElementId] = parentLocator; } PresentationLocator childLocator = locators[elementId] as PresentationLocator; if (childLocator == null ) { childLocator = new PresentationLocator(); childLocator.href = elementId; childLocator.MyElement = taxonomy.allElements[elementId] as Element; if (parentLocator != null) { childLocator.AddParent(parentLocator); } locators[elementId] = childLocator; } if (parentLocator != null) { if (parentLocator.childLocatorsByHRef == null) { parentLocator.childLocatorsByHRef = new HybridDictionary(); } ChildPresentationLocator cpl = parentLocator.childLocatorsByHRef[elementId] as ChildPresentationLocator; if (cpl != null) { cpl.AddRelationship(newLocatorRelationshipInfo); } else { cpl = new ChildPresentationLocator(elementId, newLocatorRelationshipInfo); parentLocator.childLocatorsByHRef[elementId] = cpl; } } return true; }
/// <summary> /// Creates a new instance of <see cref="ChildDefinitionLocator"/>. /// </summary> public ChildDefinitionLocator(string hRef, LocatorRelationshipInfo info) { this.hRef = hRef; locatorRelationshipInfos.Add(info); }
/// <exclude/> public TestChildPresentationLocator(string href, LocatorRelationshipInfo lri) : base(href, lri) { }
public Node CreateNode( string lang, string role, int level, string currentId, Node parentNode, LocatorRelationshipInfo relation, PresentationLink pLink, bool recursive, Dimension dimensionInfo ) { Node current = null; if (e == null && pLink != null) { /* Something went wrong during mergePresentation because we should have an element at * this point. Go to the presentationLink and try to get the element. */ PresentationLocator loc = null; pLink.TryGetLocator(this.HRef, out loc); if (loc != null && loc.MyElement != null) { //update the element and the child locators e = loc.MyElement; this.childLocatorsByHRef = loc.childLocatorsByHRef; } } if (e == null) { //it is a locator to an invalid element //just return null at this point... return null; } //make sure we have the right element if there's a parent (there could be clones) Element elementToUse = e; if (dimensionInfo != null && elementToUse != null) { if (elementToUse.IsDimensionItem()) { //get the parent node if (parentNode != null) { //DimensionNode hierNode; //if (dimensionInfo.TryGetHypercubeNode(lang, // role, pLink.Role, parentNode.Id, out hierNode)) //{ // foreach (DimensionNode dn in hierNode.Children) // { // if (dn.Id == elementToUse.Id) // { // if (parentNode != null) // { // and add it // parentNode.AddChild(dn); // } // return dn; // } // } //} DimensionNode hierNode; if (dimensionInfo.TryGetHypercubeNode(lang, role, pLink.Role, parentNode.Id,true, out hierNode)) { if (hierNode.Children != null) { foreach (DimensionNode dn in hierNode.Children) { if (dn.Id == elementToUse.Id) { if (parentNode != null) { // and add it parentNode.AddChild(dn); } return dn; } } } return null; //strange ..could not find the correct hierarchy.. } else { return null; } } } } current = elementToUse==null ? new Node( href ) : elementToUse.CreateNode( lang, role, false ); if (relation != null) { current.SetOrder(relation.Order); current.CalculationWeight = relation.CalculationWeight; if (preferredLabelRole.Equals(role)) { if (relation.PrefLabel != null) { current.UpdatePreferredLabel(lang, relation.PrefLabel); } } // now check to see if it's prohibited current.IsProhibited = relation.IsProhibited; } if (parentNode != null) { // and add it parentNode.AddChild(current); } if ( childLocatorsByHRef != null && recursive ) { foreach( ChildPresentationLocator cpl in childLocatorsByHRef.Values ) { PresentationLocator childLocator; if ( !pLink.TryGetLocator( cpl.HRef, out childLocator )) { continue; } bool innerRecursive = true; if (parentNode != null && parentNode.GetParent(cpl.HRef) != null) { //this might be ok if one of the links is a prohibitted link... innerRecursive = false; //looks like we have a recursion... } //organize locators by base order //we should have only one valid LocatorRelationshipInfo for each non xlink information... LocatorRelationshipInfo currentRelationShip=null; for (int i = cpl.LocatorRelationshipInfos.Count - 1; i >= 0; i--) { LocatorRelationshipInfo lri = cpl.LocatorRelationshipInfos[i] as LocatorRelationshipInfo; if (currentRelationShip != null && lri.IsNonXlinkEquivalentRelationship(currentRelationShip)) continue; currentRelationShip = lri; // always create the child childLocator.CreateNode(lang, role, level + 1, cpl.HRef, current, lri, pLink, innerRecursive, dimensionInfo); } } //need to sort the nodes if (current.Children != null) { current.Children.Sort(new NodeOrderSorter()); } } return current; }