private IList <string> CreateListOfProperlyOrderedNames(XmlElement element, IList <MessagePart> messagePartAndChoiceExtensionParts , MessageVisitor visitor) { IList <string> properlyOrderedProvidedRelationshipNames = new List <string>(); foreach (MessagePart messagePart in messagePartAndChoiceExtensionParts) { ElementBridge helper = new ElementBridge(element, messagePart, GetInteraction(element.OwnerDocument)); foreach (RelationshipBridge relationshipBridge in helper.GetRelationships()) { if (!relationshipBridge.IsStructuralAttribute()) { ICollection <string> names = relationshipBridge.GetNames(); if (!names.IsEmpty()) { IEnumerator <string> iterator = names.GetEnumerator(); if (iterator.MoveNext()) { //For .NET translation properlyOrderedProvidedRelationshipNames.Add(iterator.Current); } if (names.Count > 1) { // not expecting this to ever happen, but need to know if it does so we can adjust the code visitor.AddError("Internal error: found more than one name " + ListNames(names), element); } } } } } return(properlyOrderedProvidedRelationshipNames); }
public void BroadcastWithAckTest(uint size, uint startnode) { //First, create a hyperweb with 6 nodes in it. Node root = new Node(null); List<Node> AllNodes = new List<Node>(new Node[] { root }); for (int i = 0; i < size; i++) { Node n = new Node(null); root.InsertNode(n); AllNodes.Add(n); } //Now create a message visitor and broadcast it. MessageVisitor v = new MessageVisitor("First"); uint Retval = AllNodes[(int)startnode].BroadcastWithAck(v, 0); uint Expected = (uint)AllNodes.Count; //Now make sure that all nodes have exactly one copy of that message. foreach (Node n in AllNodes) { List<string> Messages = (List<string>)n.Payload["Messages"]; Assert.AreEqual(1, Messages.Count); Assert.AreEqual("First", Messages[0]); Assert.AreEqual(Expected, Retval); } }
private void Walk(Interaction interaction, MessageVisitor visitor) { XmlElement documentElement = this.message.DocumentElement; visitor.VisitRoot(documentElement, interaction); MessagePart messagePart = GetMessagePart(interaction.SuperTypeName); ProcessAllRelationships(documentElement, interaction, Arrays.AsList(messagePart), visitor); }
public virtual void Accept(MessageVisitor visitor) { Interaction interaction = GetInteraction(this.message); if (interaction != null) { Walk(interaction, visitor); } else { visitor.VisitRoot(this.message.DocumentElement, null); } }
private void ProcessAllRelationships(XmlElement element, Interaction interaction, IList <MessagePart> messagePartAndChoiceExtensionParts , MessageVisitor visitor) { ICollection <string> knownItems = new HashSet <string>(); ValidateElementOrder(messagePartAndChoiceExtensionParts, element, visitor); foreach (MessagePart messagePart in messagePartAndChoiceExtensionParts) { ElementBridge helper = new ElementBridge(element, messagePart, GetInteraction(element.OwnerDocument)); foreach (RelationshipBridge relationship in helper.GetRelationships()) { knownItems.AddAll(relationship.GetNames()); ProcessRelationship(interaction, messagePart, relationship, visitor); } } ProcessUnknownStructuralAttributes(new HashSet <string>(knownItems), element, visitor); ProcessUnknownChildElements(new HashSet <string>(knownItems), element, visitor); }
/// <summary> /// Accept a visit by the given visitor. /// </summary> public override TReturn Accept <TReturn, TData>(MessageVisitor <TReturn, TData> visitor, TData data) { return(visitor.Visit(this, data)); }
/// <summary> ///A test for Broadcast ///</summary> public void VisitTest(uint size, uint startnode) { //First, create a hyperweb with 6 nodes in it. Node root = new Node(null); List<Node> AllNodes = new List<Node>(new Node[] { root }); for (int i = 0; i < size; i++) { Node n = new Node(null); root.InsertNode(n); AllNodes.Add(n); } //Now create a message visitor and broadcast it. MessageVisitor v = new MessageVisitor("First"); uint rand = (uint)(new Random(12123)).Next(0, (int)size - 1); AllNodes[(int)startnode].Send(v, rand); //Now make sure that all nodes have exactly one copy of that message. foreach (Node n in AllNodes) { if (n.Id == rand) { List<string> Messages = (List<string>)n.Payload["Messages"]; Assert.AreEqual(1, Messages.Count); Assert.AreEqual("First", Messages[0]); } } }
public override T Accept <T>(MessageVisitor <T> visitor) { return(visitor.VisitMessageRaw(this)); }
private void ProcessUnknownChildElements(ICollection <string> knownItems, XmlElement element, MessageVisitor visitor) { IList <XmlElement> children = NodeUtil.ToElementList(element); foreach (XmlElement child in children) { if (!NamespaceUtil.IsHl7Node(child)) { } else { // ignore it string localOrTagName = NodeUtil.GetLocalOrTagName(child); if (!knownItems.Contains(localOrTagName)) { knownItems.Add(localOrTagName); // this call will intentionally fail fast with an error (since relationship is null) visitor.VisitNonStructuralAttribute(element, Arrays.AsList(child), null); } } } }
private void ValidateElementOrder(IList <MessagePart> messagePartAndChoiceExtensionParts, XmlElement element, MessageVisitor visitor) { // create list of properly ordered names (skipping those not provided, and skipping those without a relationship match) IList <string> properlyOrderedProvidedRelationshipNames = CreateListOfProperlyOrderedNames(element, messagePartAndChoiceExtensionParts , visitor); // create list of xml names in the order provided (collapsing duplicates) // remove/ignore any not in properly ordered names IList <string> xmlElementNamesInOrderProvided = CreateListOfXmlNamesInOrderProvided(element, properlyOrderedProvidedRelationshipNames ); // iterate proper list, look for exact match int expectedSize = properlyOrderedProvidedRelationshipNames.Count; int actualSize = xmlElementNamesInOrderProvided.Count; bool errorDetected = false; for (int i = 0; i < expectedSize; i++) { string expectedName = properlyOrderedProvidedRelationshipNames[i]; string actualName = actualSize > i ? xmlElementNamesInOrderProvided[i] : null; if (!StringUtils.Equals(expectedName, actualName)) { // if not found, break out and log error "beginning with...", then show expected element order errorDetected = true; string errorMessage = CreateElementOutOfOrderErrorMessage(properlyOrderedProvidedRelationshipNames, actualName); visitor.AddError(errorMessage, element); break; } } // the two sets of names should be the same length, but just in case... if (!errorDetected && actualSize > expectedSize) { string errorMessage = CreateElementOutOfOrderErrorMessage(properlyOrderedProvidedRelationshipNames, xmlElementNamesInOrderProvided [expectedSize]); visitor.AddError(errorMessage, element); } }
private void ProcessEachRelationshipValue(Interaction interaction, RelationshipBridge relationshipBridge, MessageVisitor visitor) { foreach (XmlElement child in relationshipBridge.GetElements()) { Relationship relationship = relationshipBridge.GetRelationship(); IList <MessagePart> messageParts = GetMessageParts(relationship, interaction, NodeUtil.GetLocalOrTagName(child)); if (!messageParts.IsEmpty() && !IsNull(child)) { ProcessAllRelationships(child, interaction, messageParts, visitor); } } }
private void ProcessRelationship(Interaction interaction, MessagePart messagePart, RelationshipBridge relationship, MessageVisitor visitor) { if (relationship.IsStructuralAttribute()) { XmlAttribute attr = relationship.GetAttribute(); visitor.VisitStructuralAttribute(relationship.GetBase(), attr, relationship.GetRelationship()); } else { if (relationship.IsAssociation()) { visitor.VisitAssociation(relationship.GetBase(), relationship.GetXmlName(), relationship.GetElements(), relationship.GetRelationship ()); ProcessEachRelationshipValue(interaction, relationship, visitor); } else { visitor.VisitNonStructuralAttribute(relationship.GetBase(), relationship.GetElements(), relationship.GetRelationship()); } } }
private void ProcessUnknownStructuralAttributes(ICollection <string> knownItems, XmlElement element, MessageVisitor visitor ) { XmlAttributeCollection attrs = element.Attributes; if (attrs != null) { foreach (XmlNode node in new XmlNamedNodeMapIterable(attrs)) { XmlAttribute item = (XmlAttribute)node; if (IsIgnorable(item)) { } else { // skip it if (!NamespaceUtil.IsHl7Node(item)) { } else { // skip it if (!knownItems.Contains(item.Name)) { knownItems.Add(item.Name); // this call will intentionally fail fast with an error (since relationship is null) visitor.VisitStructuralAttribute(element, item, null); } } } } } }