public void testSelectNodes() { SIF_ZoneStatus zoneStatus = createZoneStatus(); SifXPathContext context = SifXPathContext.NewSIFContext(zoneStatus, SifVersion.SIF20); // Select all of the objects that are provided in this zone XPathNodeIterator iterator = context.Select("//SIF_Provider/*/SIF_Object"); Assert.AreEqual(5, iterator.Count, "Should be 5 objects selected"); }
public void testSelectSingleNode() { SIF_ZoneStatus zoneStatus = createZoneStatus(); SifXPathContext context = SifXPathContext.NewSIFContext(zoneStatus, SifVersion.SIF20); // Select a single object provider XPathNodeIterator iterator = context.Select("SIF_Providers/SIF_Provider[SIF_ObjectList/SIF_Object[@ObjectName='StudentPersonal']]"); Assert.AreEqual(1, iterator.Count); Assert.IsTrue(iterator.MoveNext()); Element node = (Element)iterator.Current.UnderlyingObject; Assert.IsNotNull(node); }
public void testIterate() { SIF_ZoneStatus zoneStatus = createZoneStatus(); SifXPathContext context = SifXPathContext.NewSIFContext(zoneStatus, SifVersion.SIF20); // Select all of the objects that are provided in this zone XPathNodeIterator iterator = context.Select("//SIF_Provider/*/SIF_Object"); int a = 0; foreach (XPathNavigator o in iterator) { Console.WriteLine(o.UnderlyingObject); a++; } Assert.AreEqual(5, a, "Should have iterated 5 objects"); }
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(); }