/// <summary> Evaluates this rule against a SifDataObject and returns the text value /// of the element or attribute that satisfied the query. /// /// </summary> /// <param name="context">The SIFXPathContext to evaluate this rule against</param> /// <param name="version">The SIF version to use when evaluating this rule</param> /// <returns> The text value of the element or attribute that satisfied the /// query, or null if no match found /// </returns> public override SifSimpleType Evaluate(SifXPathContext context, SifVersion version) { // TODO: This could be done in the constructor, but the ADK outbound mapping // syntax sometimes cannot be compiled because it uses proprietary syntax // Therefore, compile the expression the first time it is used for a mapping if (fExpression == null) { Compile(); } Object value = fExpression.GetValue(context); if (value == null) { return(null); } else if (value is Element) { return(((Element)value).SifValue); } else { return(new SifString(value.ToString())); } }
/// <summary> /// Evaluates a condition group against a SifDataObject to determine if /// they are a match or not /// </summary> /// <param name="grp"></param> /// <param name="context"></param> /// <param name="culture"></param> /// <returns>True if the result of evaluating the condition groups is true</returns> /// <exception cref="OpenADK.Library.AdkSchemaException">If the condition contains references to invalid elements</exception> private bool EvaluateConditionGroup(SifXPathContext context, ConditionGroup grp, CultureInfo culture) { Condition[] conds = grp.Conditions; if (conds.Length > 0) { bool returnOnFirstMatch = grp.Operator == GroupOperator.Or ? true : false; foreach (Condition c in conds) { if ((EvaluateCondition(context, c, culture)) == returnOnFirstMatch) { // If this is an OR group, return true on the first match // If this is an AND Group, return false on the first failure return(returnOnFirstMatch); } } // None of the conditions matched the returnOnFirstMathValue. Therefore, // return the opposite value return(!returnOnFirstMatch); } else { return(EvaluateConditionGroups(context, grp.Operator, grp.Groups, culture)); } }
public SifSimpleType Evaluate(SifXPathContext xpathContext, SifVersion version, bool returnDefault) { SifSimpleType value = null; if (fRule != null) { value = fRule.Evaluate(xpathContext, version); } if (value == null && fDefValue != null && returnDefault) { // TODO: Support all data types try { return(SifTypeConverters.GetConverter(fDatatype).Parse(Adk.TextFormatter, fDefValue)); } catch (AdkParsingException adkpe) { throw new AdkSchemaException( "Error parsing default value: '" + fDefValue + "' for field " + fField + " : " + adkpe, null, adkpe); } } return(value); }
/// <summary> /// Evaluates the condition groups and returns True if the Operator is OR and at least /// one of the groups evaluates to TRUE. If the Operator is AND, all of the condition /// groups have to evaluate to TRUE /// </summary> /// <param name="op"></param> /// <param name="grps"></param> /// <param name="context"></param> /// <param name="culture"></param> /// <returns></returns> /// <exception cref="OpenADK.Library.AdkSchemaException">If the condition contains references to invalid elements</exception> private bool EvaluateConditionGroups(SifXPathContext context, GroupOperator op, ConditionGroup[] grps, CultureInfo culture) { bool isMatch = true; for (int c = 0; c < grps.Length; c++) { bool singleMatch = EvaluateConditionGroup(context, grps[c], culture); if (op == GroupOperator.Or) { if (singleMatch) { // In OR mode, return as soon as we evaluate to True return(true); } isMatch |= singleMatch; } else { isMatch &= singleMatch; } // As soon as the evaluation fails, return if (!isMatch) { return(false); } } return(isMatch); }
/// <summary>Sets an element or attribute value identified by an XPath-like query string.</summary> /// <remarks> /// NOTE: This method makes calls to SIFXPathContext. If multiple calls to /// <c>setElementOrAttribute</c> are being done, it is much more efficient to create /// a new <c>SIFXPathContext</c> by calling <c>SIFXPathContext.newInstance(sdo)</c> and then /// calling <c>.setElementorAttributeon</c> on that SifXPathContext instance /// </remarks> /// <param name="xpath">An XPath-like query string that identifies identifies /// the element or attribute to set. The string must reference elements /// and attributes by their <i>version-independent</i> names. /// </param> /// <param name="valu">The value of the element or attribute /// </param> public virtual void SetElementOrAttribute(string xpath, string valu) { SifVersion = Adk.SifVersion; SifXPathContext spc = SifXPathContext.NewSIFContext(this); spc.SetElementOrAttribute(xpath, valu); }
public override INodePointer CreateAttribute(SifXPathContext context, string name) { if (fChild.IsAttribute && fChildName.Equals(name)) { return(fChild); } return(base.CreateAttribute(context, name)); }
public INodePointer CreatePath(SifXPathContext context, SifVersion version) { if (fExpression == null) { Compile(); } return(fExpression.CreatePath(context)); }
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 testCustomFunction() { SIF_ZoneStatus zoneStatus = createZoneStatus(); SifXPathContext context = SifXPathContext.NewSIFContext(zoneStatus, SifVersion.SIF20); object value = context.GetValue( "adk:toLowerCase(SIF_Providers/SIF_Provider[SIF_ObjectList/SIF_Object[@ObjectName='SchoolInfo']]/@SourceId)"); Assert.AreEqual("acmeagent", value, "Value"); }
public void testGetValue() { SIF_ZoneStatus zoneStatus = createZoneStatus(); SifXPathContext context = SifXPathContext.NewSIFContext(zoneStatus, SifVersion.SIF20); object value = context.GetValue( "SIF_Providers/SIF_Provider[SIF_ObjectList/SIF_Object[@ObjectName='SchoolInfo']]/@SourceId"); Assert.AreEqual("AcmeAgent", value.ToString(), "Value"); }
private void assertStudentPersonal(StudentPersonal sp) { DateTime birthDate = new DateTime(1990, 1, 1); Assertion.AssertEquals("First Name", "Betty", sp.Name.FirstName); Assertion.AssertEquals("Middle Name", "George", sp.Name.MiddleName); Assertion.AssertEquals("Last Name", "Johnson", sp.Name.LastName); Assertion.AssertEquals("Student Number", "998", sp.OtherIdList.ItemAt(0).TextValue); Assertion.AssertEquals("Birthdate", birthDate, sp.Demographics.BirthDate.Value); Assertion.AssertEquals("Ethnicity", "H", sp.Demographics.RaceList.ItemAt(0).Code); PhoneNumberList pnl = sp.PhoneNumberList; Assertion.AssertNotNull("PhoneNumberList", pnl); PhoneNumber homePhone = pnl[PhoneNumberType.SIF1x_HOME_PHONE]; Assertion.AssertNotNull("Home Phone is null", homePhone); Assertion.AssertEquals("Home Phone", "202-358-6687", homePhone .Number); PhoneNumber cellPhone = pnl [PhoneNumberType.SIF1x_PERSONAL_CELL]; Assertion.AssertNotNull("cellPhone Phone is null", cellPhone); Assertion.AssertEquals("Cell Phone", "202-502-4856", cellPhone.Number); SifXPathContext xpathContext = SifXPathContext.NewSIFContext(sp, SifVersion.SIF20r1); assertByXPath(xpathContext, "AddressList/Address/Street/Line1", "321 Oak St"); assertByXPath(xpathContext, "AddressList/Address/Street/Line1", "321 Oak St"); assertByXPath(xpathContext, "AddressList/Address/Street/Line2", "APT 11"); assertByXPath(xpathContext, "AddressList/Address/City", "Metropolis"); assertByXPath(xpathContext, "AddressList/Address/StateProvince", "IL"); assertByXPath(xpathContext, "AddressList/Address/Country", "US"); assertByXPath(xpathContext, "AddressList/Address/PostalCode", "321546"); /* * These assertions are currently commented out because the Adk does not * currently support Repeatable elements that have wildcard attributes * * PhoneNumber number = sp.PhoneNumber( PhoneNumberType.PHONE ); * Assertion.AssertNotNull( "Alternate Phone Element is null", number ); * Assertion.AssertEquals( "Alternate Phone", "201-668-1245", * number.ToString() ); */ Assertion.AssertEquals("OriginalGradYear", 2005, sp.OnTimeGraduationYear.Value); Assertion.AssertEquals("Projected", 2007, sp.ProjectedGraduationYear.Value); Assertion.AssertNotNull("Actual Grad Year", sp.GraduationDate.Value); Assertion.AssertEquals("OriginalGradYear", 2007, sp.GraduationDate.Year); }
private void assertByXPath(SifXPathContext context, String xPath, String assertedValue) { Element e = (Element)context.GetValue(xPath); Assertion.AssertNotNull("Field is null for path " + xPath, e); SifSimpleType value = e.SifValue; Assertion.AssertNotNull("Value is null for path " + xPath, value); Assertion.AssertEquals(xPath, assertedValue, value.ToString()); }
/// <summary>Gets an element or attribute value identified by an XPath-like query string.</summary> /// NOTE: This method makes calls to SIFXPathContext. If multiple calls to /// <c>GetElementOrAttribute</c> are being done, it is much more efficient to create /// a new <c>SifXPathContext</c> by calling <c>SifXPathContext.NewInstance(sdo)</c> and then /// calling <c>.GetElementorAttributeon</c> on that SifXPathContext instance /// </remarks> /// <param name="xpath">An XPath-like query string that identifies the element or /// attribute to get. The string must reference elements and attributes /// by their <i>version-independent</i> names. /// </param> /// <returns> An Element instance encapsulating the element or attribute if /// found. If not found, <c>null</c> is returned. To retrieve the /// value of the Element, call its <c>getTextValue</c> method. /// </returns> public virtual Element GetElementOrAttribute(string xpath) { // XPath Navigation using this API causes the object to have to // remember the SIF Version being evaluated if (fVersion == null) { fVersion = Adk.SifVersion; } SifXPathContext spc = SifXPathContext.NewSIFContext(this); return(spc.GetElementOrAttribute(xpath)); }
/// <summary> /// Creates a child element, if supported by this node /// </summary> /// <param name="parentPointer"></param> /// <param name="formatter"></param> /// <param name="version"></param> /// <param name="context"></param> /// <returns></returns> public INodePointer CreateChild(INodePointer parentPointer, SifFormatter formatter, SifVersion version, SifXPathContext context) { // 1) Create an instance of the SimpleField with a null value (It's assigned later) // // STEP 2 // Find the actual field to set the value to // SifElement parent = (SifElement)((SifElementPointer)parentPointer).Element; SifElement targetElement = parent; if (!fElementDef.Field) { // This indicates a child SifElement that needs to be created targetElement = SifElement.Create(parent, fElementDef); formatter.AddChild(parent, targetElement, version); } IElementDef fieldDef = null; if (fValueXpath.Equals(".")) { fieldDef = fElementDef; } else { String fieldName = fValueXpath; if (fValueXpath.StartsWith("@")) { fieldName = fValueXpath.Substring(1); } fieldDef = Adk.Dtd.LookupElementDef(fElementDef, fieldName); } if (fieldDef == null) { throw new ArgumentException("Support for value path {" + fValueXpath + "} is not supported by XPathSurrogate."); } SifSimpleType ssf = fieldDef.TypeConverter.GetSifSimpleType(null); SimpleField sf = ssf.CreateField(targetElement, fieldDef); targetElement.SetField(sf); // 2) built out a fake set of node pointers representing the SIF 1.5r1 path and // return the root pointer from that stack return(BuildLegacyPointers(parentPointer, sf)); }
/// <summary>Sets an element or attribute value identified by an XPath-like query string.</summary> /// <remarks> /// NOTE: This method makes calls to SIFXPathContext. If multiple calls to /// <c>setElementOrAttribute</c> are being done, it is much more efficient to create /// a new <c>SifXPathContext</c> by calling <c>SifXPathContext.NewInstance(sdo)</c> and then /// calling <c>.SetElementorAttributeon</c> on that SifXPathContext instance /// </remarks> /// <param name="xpath">An XPath-like query string that identifies the element or /// attribute to set. The string must reference elements and attributes /// by their <i>version-independent</i> names. /// </param> /// <param name="valu">The value to assign to the element or attribute if the /// query string does not set a value; may be null /// </param> /// <param name="adaptor"> A data source may be used for variable /// substitutions within the query string /// </param> public virtual void SetElementOrAttribute(string xpath, string valu, IFieldAdaptor adaptor) { SifVersion = Adk.SifVersion; SifXPathContext spc = SifXPathContext.NewSIFContext(this); if (adaptor is IXPathVariableLibrary) { spc.AddVariables("", (IXPathVariableLibrary)adaptor); } spc.SetElementOrAttribute(xpath, valu); }
/** * Perform a mapping operation on the specified SIFElement. The mapping operation * will be either inbound or outbound, depending on whether this class was returned * from {@link Mappings#selectInbound(ElementDef, SIFVersion, String, String)} or * {@link Mappings#selectOutbound(ElementDef, SIFVersion, String, String)} * @param mappedElement The SIFElement to perform the mappings operation on * @param adaptor The FieldAdaptor to use for getting or setting data * @throws ADKMappingException */ public void Map(SifElement mappedElement, IFieldAdaptor adaptor) { SifXPathContext context = GetXPathContext(mappedElement, adaptor); if (fDirection == MappingDirection.Inbound) { fMappings.MapInbound(context, adaptor, mappedElement, fFieldMappings, fSIFVersion); } else if (fDirection == MappingDirection.Outbound) { fMappings.MapOutbound(context, adaptor, mappedElement, fFieldMappings, fValueBuilder, fSIFVersion); } }
public void testGetValueSubstring() { SIF_ZoneStatus zoneStatus = createZoneStatus(); Console.WriteLine(zoneStatus.ToXml()); SifXPathContext context = SifXPathContext.NewSIFContext(zoneStatus, SifVersion.SIF20); Object value = context.GetValue( "substring(SIF_Providers/SIF_Provider[SIF_ObjectList/SIF_Object[@ObjectName='SchoolInfo']]/@SourceId, 5)"); Assert.AreEqual("Agent", value, "Value"); }
/// <summary> /// Evaluate the given the SIFDataObject against the conditions provided in the /// Query. All conditions are evaluated using the provided comparer /// </summary> /// <param name="obj"> The SIFDataObject to evalaute against this query</param> /// <param name="culture">The culture info used to do string comparisons</param> /// <returns></returns> /// <exception cref="OpenADK.Library.AdkSchemaException">If the condition contains references to invalid elements</exception> public bool Evaluate(SifDataObject obj, CultureInfo culture) { if (!(obj.ElementDef == fObjType)) { return(false); } if (fRoot != null) { SifXPathContext context = SifXPathContext.NewSIFContext(obj, EffectiveVersion); return(EvaluateConditionGroup(context, fRoot, culture)); } return(true); }
public void testCourseCodeSIF15r1() { Adk.SifVersion = SifVersion.SIF15r1; SchoolCourseInfo sci = new SchoolCourseInfo(); sci.SetCourseCredits(CreditType.C0108_0585, 2); SifXPathContext spc = SifXPathContext.NewSIFContext(sci); Element value = (Element)spc.GetValue("CourseCredits[@Code='0585']"); SifSimpleType elementValue = value.SifValue; Assertion.AssertNotNull("Value by XPath", elementValue); Assertion.AssertEquals("Value By XPath", 2, elementValue.RawValue); }
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 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); }
private void Compile() { // If there is a value assignment in the rule, chop it off String sqp = fDef; int lastEqualsSign = fDef.LastIndexOf("="); if (lastEqualsSign > -1) { int lastBracket = fDef.LastIndexOf("]"); if (lastBracket < lastEqualsSign) { sqp = fDef.Substring(0, lastEqualsSign); fValueIndex = lastEqualsSign + 1; } } fExpression = SifXPathContext.Compile(sqp); }
/// <summary> /// If SIFElement restrictions are placed on this query, this method /// will take the SIFDataObject and call setChanged(false). It will then /// go through each of the SIFElement restrictions, resolve them, and /// call setChanged(true) on those elements only. This will cause the /// object to be rendered properly using SIFWriter. /// </summary> /// <param name="sdo"></param> public void SetRenderingRestrictionsTo(SifDataObject sdo) { if (sdo == null || fFieldRestrictions == null) { return; } sdo.SetChanged(false); // Go through and only set the filtered items to true SifXPathContext context = SifXPathContext.NewSIFContext(sdo); foreach (ElementRef elementRef in fFieldRestrictions) { String xPath = elementRef.XPath; Element e = context.GetElementOrAttribute(xPath); if (e != null) { e.SetChanged(); } } sdo.EnsureRootElementRendered(); }
private SifXPathContext GetXPathContext( SifElement mappedElement, IFieldAdaptor adaptor) { lock (this) { if (!mappedElement.ElementDef.Name.Equals(fElementDef.Name)) { throw new AdkMappingException( "Unable to use object for mapping. MappingsContext expected an object of type '" + fElementDef.Name + "' but was '" + mappedElement.ElementDef.Name + "'.", null); } if (fRootContext == null) { fRootContext = SifXPathContext.NewSIFContext(mappedElement, fSIFVersion); if (adaptor is IXPathVariableLibrary) { fRootContext.AddVariables("", (IXPathVariableLibrary)adaptor); } } return(SifXPathContext.NewSIFContext(fRootContext, mappedElement)); } }
/// <summary> /// Evaluates a single SIF_Condition against an object and returns whether it matches or not /// </summary> /// <param name="cond"></param> /// <param name="context"></param> /// <param name="culture"></param> /// <returns></returns> /// <exception cref="OpenADK.Library.AdkSchemaException">If the condition contains references to invalid elements</exception> private bool EvaluateCondition(SifXPathContext context, Condition cond, CultureInfo culture) { // TODO: Add support for comparison using the SIF Data Types Element def = context.GetElementOrAttribute(cond.GetXPath()); String conditionValue = cond.Value; String elementValue = null; if (def != null) { SifSimpleType value = def.SifValue; if (value != null) { // Format the value to string, based on the query version elementValue = value.ToString(EffectiveVersion); } else { // TODO: Not sure if this would ever return a value if the above does not elementValue = def.TextValue; } } if (elementValue == null || conditionValue == null) { // Don't use standard comparision because it will fail. If // one or the other value is null, it cannot be compared, except for // if the operator is EQ or NOT bool bothAreNull = (elementValue == null && conditionValue == null); switch (cond.Operators) { case ComparisonOperators.EQ: case ComparisonOperators.GE: case ComparisonOperators.LE: return(bothAreNull); case ComparisonOperators.NE: return(!bothAreNull); default: // For any other operator, the results are indeterminate with // null values. Return false in this case. return(false); } } int compareLevel = String.Compare(elementValue, conditionValue, false, culture); switch (cond.Operators) { case ComparisonOperators.EQ: return(compareLevel == 0); case ComparisonOperators.NE: return(compareLevel != 0); case ComparisonOperators.GT: return(compareLevel > 0); case ComparisonOperators.LT: return(compareLevel < 0); case ComparisonOperators.GE: return(compareLevel >= 0); case ComparisonOperators.LE: return(compareLevel <= 0); } return(false); }
public override INodePointer CreateChild(SifXPathContext context, string name, int i) { // Do nothing. The child has already been created return(fChild); }
/// <summary> /// Creates a child element, if supported by this node /// </summary> /// <param name="parentPointer"></param> /// <param name="formatter"></param> /// <param name="version"></param> /// <param name="context"></param> /// <returns></returns> public INodePointer CreateChild(INodePointer parentPointer, SifFormatter formatter, SifVersion version, SifXPathContext context) { return(null); }
/// <summary> /// Creates a child element, if supported by this node /// </summary> /// <param name="parentPointer"></param> /// <param name="formatter"></param> /// <param name="version"></param> /// <param name="context"></param> /// <returns></returns> public INodePointer CreateChild(INodePointer parentPointer, SifFormatter formatter, SifVersion version, SifXPathContext context) { // TODO Auto-generated method stub return(null); }
public void testSifResponseSender010() { string queryStr = @"<SIF_Query> <SIF_QueryObject ObjectName='SectionInfo'> <SIF_Element>@RefId</SIF_Element> <SIF_Element>@SchoolCourseInfoRefId</SIF_Element> <SIF_Element>@SchoolYear</SIF_Element> <SIF_Element>LocalId</SIF_Element> <SIF_Element>ScheduleInfoList/ScheduleInfo/@TermInfoRefId</SIF_Element> <SIF_Element>Description</SIF_Element> <SIF_Element>LanguageOfInstruction</SIF_Element> <SIF_Element>LanguageOfInstruction/Code</SIF_Element> </SIF_QueryObject> </SIF_Query>"; string sectionInfoStr = @"<SectionInfo RefId='D9C9889878144863B190C7D3428D7953' SchoolCourseInfoRefId='587F89D23EDD4761A59C04BA0D39E8D9' SchoolYear='2008'> <LocalId>1</LocalId> <Description>section 19</Description> <ScheduleInfoList> <ScheduleInfo TermInfoRefId='0D8165B1ADB34780BD1DFF9E38A7B935'> <TeacherList> <StaffPersonalRefId>F9D3916707634682B84C530BCF96B5CA</StaffPersonalRefId> </TeacherList> <SectionRoomList> <RoomInfoRefId>EED167D761CD493EA94A875F56ABB0CB</RoomInfoRefId> </SectionRoomList> <MeetingTimeList> <MeetingTime> <TimetableDay>R</TimetableDay> <TimetablePeriod>6</TimetablePeriod> </MeetingTime> <MeetingTime> <TimetableDay>F</TimetableDay> <TimetablePeriod>6</TimetablePeriod> </MeetingTime> <MeetingTime> <TimetableDay>W</TimetableDay> <TimetablePeriod>6</TimetablePeriod> </MeetingTime> <MeetingTime> <TimetableDay>M</TimetableDay> <TimetablePeriod>6</TimetablePeriod> </MeetingTime> <MeetingTime> <TimetableDay>T</TimetableDay> <TimetablePeriod>6</TimetablePeriod> </MeetingTime> </MeetingTimeList> </ScheduleInfo> </ScheduleInfoList> <MediumOfInstruction><Code>0605</Code></MediumOfInstruction> <LanguageOfInstruction><Code>eng</Code></LanguageOfInstruction> <SummerSchool>No</SummerSchool> </SectionInfo>"; SifParser parser = SifParser.NewInstance(); SIF_Query sifquery = (SIF_Query)parser.Parse(queryStr); SectionInfo section = (SectionInfo)parser.Parse(sectionInfoStr); Query query = new Query(sifquery); String SifRequestMsgId = Adk.MakeGuid(); String sourceId = "TEST_SOURCEID"; SifVersion testVersion = SifVersion.LATEST; int maxBufferSize = int.MaxValue; MessageDispatcher testDispatcher = new MessageDispatcher(Zone); Zone.SetDispatcher(testDispatcher); Zone.Connect(ProvisioningFlags.None); InMemoryProtocolHandler testProto = (InMemoryProtocolHandler)Zone.ProtocolHandler; testProto.clear(); SifResponseSender srs = new SifResponseSender(); srs.Open(Zone, SifRequestMsgId, sourceId, testVersion, maxBufferSize, query); srs.Write(section); srs.Close(); // Retrieve the SIF_Response message off the protocol handler and asssert the results SIF_Response response = (SIF_Response)testProto.readMsg(); Assert.AreEqual(SifRequestMsgId, response.SIF_RequestMsgId); Assert.AreEqual(1, response.SIF_PacketNumber.Value); Assert.AreEqual("No", response.SIF_MorePackets); SIF_Header header = response.SIF_Header; Assert.AreEqual(sourceId, header.SIF_DestinationId); SifDataObject responseObject = (SifDataObject)response.SIF_ObjectData.GetChildList()[0]; Assert.IsNotNull(responseObject); Console.Out.WriteLine(responseObject.ToXml()); SifXPathContext context = SifXPathContext.NewSIFContext(responseObject); foreach (ElementRef reference in query.FieldRestrictionRefs) { Element found = context.GetElementOrAttribute(reference.XPath); Assert.IsNotNull(found, reference.XPath); } Element sectionInfoList = responseObject.GetElementOrAttribute("ScheduleInfoList/ScheduleInfo/SectionInfoList"); Assert.IsNull(sectionInfoList); }
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(); }