/// <summary> /// Updates the links to the referenced objects /// </summary> /// <param name="sourceObject">The object to apply the link rule to</param> /// <returns>A list of objects that were modified</returns> private IList <MAObjectHologram> UpdateLinks(MAObjectHologram sourceObject) { List <MAObjectHologram> updatedObjects = new List <MAObjectHologram>(); List <MAObjectHologram> targetsToReference = new List <MAObjectHologram>(); List <MAObjectHologram> targetsToDereference = new List <MAObjectHologram>(); IEnumerable <MAObjectHologram> targetsProposed = sourceObject.GetReferencedObjects(this.ForwardLinkAttribute, System.Data.DataRowVersion.Proposed); IEnumerable <MAObjectHologram> targetsCurrent = sourceObject.GetReferencedObjects(this.ForwardLinkAttribute, System.Data.DataRowVersion.Current); targetsToReference.AddRange(targetsProposed.Except(targetsCurrent)); targetsToDereference.AddRange(targetsCurrent.Except(targetsProposed)); foreach (MAObjectHologram target in targetsToDereference) { Logger.WriteLine("Unlinking object {0} from {1} on object {2} referenced by {3}", LogLevel.Debug, sourceObject.DisplayText, this.BackLinkAttribute.Name, target.DisplayText, this.ForwardLinkAttribute.Name); target.SetObjectModificationType(ObjectModificationType.Update, false); this.RemoveReference(sourceObject, target); updatedObjects.Add(target); } foreach (MAObjectHologram target in targetsToReference) { Logger.WriteLine("Linking object {0} to {1} on object {2} referenced by {3}", LogLevel.Debug, sourceObject.DisplayText, this.BackLinkAttribute.Name, target.DisplayText, this.ForwardLinkAttribute.Name); target.SetObjectModificationType(ObjectModificationType.Update, false); this.AddReference(sourceObject, target); updatedObjects.Add(target); } return(updatedObjects); }
/// <summary> /// Gets the object containing the attribute value to use /// </summary> /// <param name="sourceObject">The object that is under construction</param> /// <returns>If the declaration contains a reference to another object, then that object is returned, otherwise the original object is returned</returns> private IEnumerable <MAObjectHologram> GetSourceObjects(MAObjectHologram sourceObject) { if (this.IsReferenced) { if (this.ReferencedObjectAttribute == null) { throw new InvalidOperationException("The value comparison rule does not have a reference attribute specified"); } IEnumerable <MAObjectHologram> sources = new List <MAObjectHologram>(); try { sources = sourceObject.GetReferencedObjects(this.ReferencedObjectAttribute); if (!sources.Any()) { this.RaiseRuleFailure(string.Format("The reference attribute {0} was null", this.ReferencedObjectAttribute.Name)); } } catch (ReferencedObjectNotPresentException) { this.RaiseRuleFailure(string.Format("The reference attribute {0} referred to an object which did not exist in the database", this.ReferencedObjectAttribute.Name)); } return(sources); } else { return(new List <MAObjectHologram>() { sourceObject }); } }