private SifElement GetContainer(SifElement contentParent, IElementDef childDef, SifVersion version) { IElementDef elementParentDef = childDef.Parent; if (elementParentDef != null && elementParentDef != contentParent.ElementDef) { // The element does not appear to belong to this parent. Attempt to look // for a container element that might be missing in between the two // If the parent of this element were collapsed in a previous version // of SIF, check for or re-add the parent element and add this new // child instead. // // For example, a child could be an Email element from the // common package that's being added to StudentPersonal. In this // case, // we need to actually find or create an instance of the new // EmailList // container element and add the child to it, instead of to "this" String tag = elementParentDef.Tag(Adk.SifVersion); IElementDef missingLink = Adk.Dtd.LookupElementDef(contentParent.ElementDef, tag); if (missingLink != null && missingLink.IsCollapsed(version)) { SifElement container = contentParent.GetChild(missingLink); if (container == null) { container = SifElement.Create(contentParent, missingLink); } AddChild(contentParent, container, version); return(container); } } return(contentParent); }
/// <summary> /// Gets the content from the SIFElement for the specified version of SIF. Only /// elements that apply to the requested version of SIF will be returned. /// </summary> /// <param name="element">The element to retrieve content from</param> /// <param name="version"></param> /// <returns></returns> public override IList <Element> GetContent(SifElement element, SifVersion version) { List <Element> returnValue = new List <Element>(); ICollection <SimpleField> fields = element.GetFields(); foreach (SimpleField val in fields) { IElementDef def = val.ElementDef; if (def.IsSupported(version) && !def.IsAttribute(version) && def.Field) { returnValue.Add(val); } } IList <SifElement> children = element.GetChildList(); foreach (SifElement val in children) { IElementDef def = val.ElementDef; if (def.IsSupported(version)) { if (def.IsCollapsed(version)) { ICollection <Element> subElements = GetContent(val, version); // FIXUP the ElementDef for this version of SIF. // for example, StudentPersonal/EmailList/Email needs it's // ElementDef set to "StudentPersonal_Email" foreach (Element e in subElements) { IElementDef subElementDef = e.ElementDef; if (version.CompareTo(subElementDef.EarliestVersion) >= 0) { String tag = subElementDef.Tag(Adk.SifVersion); IElementDef restoredDef = Adk.Dtd.LookupElementDef(element.ElementDef, tag); if (restoredDef != null) { e.ElementDef = restoredDef; } returnValue.Add(e); } } } else { returnValue.Add(val); } } } MergeSort.Sort <Element>(returnValue, ElementSorter <Element> .GetInstance(version)); //returnValue.Sort(ElementSorter<Element>.GetInstance(version)); return(returnValue); }
public void OnQueryResults(IDataObjectInputStream data, SIF_Error error, IZone zone, IMessageInfo info) { SifMessageInfo smi = (SifMessageInfo)info; DateTime start = DateTime.Now; if (smi.Timestamp.HasValue) { start = smi.Timestamp.Value; } Console.WriteLine(); Console.WriteLine("********************************************* "); Console.WriteLine("Received SIF_Response packet from zone" + zone.ZoneId); Console.WriteLine("Details... "); Console.WriteLine("Request MsgId: " + smi.SIFRequestMsgId); Console.WriteLine("Packet Number: " + smi.PacketNumber); Console.WriteLine(); if (error != null) { Console.WriteLine("The publisher returned an error: "); Console.WriteLine("Category: " + error.SIF_Category + " Code: " + error.SIF_Code); Console.WriteLine("Description " + error.SIF_Desc); if (error.SIF_ExtendedDesc != null) { Console.WriteLine("Details: " + error.SIF_ExtendedDesc); } return; } try { int objectCount = 0; while (data.Available) { SifDataObject next = data.ReadDataObject(); objectCount++; Console.WriteLine(); Console.WriteLine("Text Values for " + next.ElementDef.Name + " " + objectCount + " {" + next.Key + "}"); SifXPathContext context = SifXPathContext.NewSIFContext(next); // Print out all attributes Console.WriteLine("Attributes:"); XPathNodeIterator textNodes = context.Select("//@*"); while (textNodes.MoveNext()) { XPathNavigator navigator = textNodes.Current; Element value = (Element)navigator.UnderlyingObject; IElementDef valueDef = value.ElementDef; Console.WriteLine(valueDef.Parent.Tag(SifVersion.LATEST) + "/@" + valueDef.Tag(SifVersion.LATEST) + "=" + value.TextValue + ", "); } Console.WriteLine(); // Print out all elements that have a text value Console.WriteLine("Element:"); textNodes = context.Select("//*"); while (textNodes.MoveNext()) { XPathNavigator navigator = textNodes.Current; Element value = (Element)navigator.UnderlyingObject; String textValue = value.TextValue; if (textValue != null) { IElementDef valueDef = value.ElementDef; Console.WriteLine(valueDef.Tag(SifVersion.LATEST) + "=" + textValue + ", "); } } } Console.WriteLine(); Console.WriteLine("Total Objects in Packet: " + objectCount); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } if (!smi.MorePackets) { // This is the final packet. Print stats Console.WriteLine("Final Packet has been received."); IRequestInfo ri = smi.SIFRequestInfo; if (ri != null) { Console.WriteLine("Source Query: "); Console.WriteLine(ri.UserData); TimeSpan difference = start.Subtract(ri.RequestTime); Console.WriteLine("Query execution time: " + difference.Milliseconds + " ms"); } } else { Console.WriteLine("This is not the final packet for this SIF_Response"); } Console.WriteLine("********************************************* "); Console.WriteLine( ); PrintPrompt(); }