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); }
/// <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)); }
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>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); }
/// <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 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 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); }
/// <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)); } }
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(); }