Ejemplo n.º 1
0
        public void TestParseReportData()
        {
            SIF_ReportObject reportObject = null;

            using (Stream aStream = GetResourceStream("ReportData.xml"))
            {
                TextReader aReader = new StreamReader(aStream);
                SifParser  parser  = SifParser.NewInstance();
                reportObject = (SIF_ReportObject)parser.Parse(aReader, null, SifParserFlags.None, SifVersion.SIF20r1);
                aReader.Close();
                aStream.Close();
            }

            Assert.IsNotNull(reportObject);
            Assert.AreEqual(1, reportObject.ChildCount);

            SifElement reportData = reportObject.GetChildList()[0];

            Assert.AreEqual(2060, reportData.ChildCount);
        }
Ejemplo n.º 2
0
        public void TestToXml030()
        {
            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>";

            SifParser parser   = SifParser.NewInstance();
            SIF_Query sifQuery = (SIF_Query)parser.Parse(queryStr);
            Query     q        = new Query(sifQuery);

            assertSectionInfoQueryXML(q);
        }
Ejemplo n.º 3
0
        public void testReturningCorrectSifVersionSIF1x()
        {
            String test =
                "<SIF_Request xmlns=\"http://www.sifinfo.org/infrastructure/1.x\">" +
                "	<SIF_Query >"+
                "      <SIF_QueryObject ObjectName=\"SchoolInfo\" />" +
                "	</SIF_Query>"+
                "</SIF_Request>";

            SifParser  parser  = SifParser.NewInstance();
            SifElement element = parser.Parse(test, null);

            // Since the version was not passed in, the latest supported
            // SIF 2.x Version should be returned
            Assertion.AssertEquals(SifVersion.GetLatest(1), element.SifVersion);

            element = parser.Parse(test, null, 0, SifVersion.SIF11);
            // Since the version was passed in, 1.1 should be returned
            Assertion.AssertEquals(SifVersion.SIF11, element.SifVersion);

            test =
                "<SIF_Message Version=\"1.1\" xmlns=\"http://www.sifinfo.org/infrastructure/1.x\">" +
                "<SIF_Request>" +
                "	<SIF_Query >"+
                "      <SIF_QueryObject ObjectName=\"SchoolInfo\" />" +
                "	</SIF_Query>"+
                "</SIF_Request>" +
                "</SIF_Message>";

            element = parser.Parse(test, null);
            // The version attribute is specified, use it.
            Assertion.AssertEquals(SifVersion.SIF11, element.SifVersion);

            element = parser.Parse(test, null, 0, SifVersion.SIF15r1);
            // The version attribute is specified and should override the
            // version passed in
            Assertion.AssertEquals(SifVersion.SIF11, element.SifVersion);
        }
Ejemplo n.º 4
0
        public void PerfTestParsing5000Times()
        {
            // Do one warmup parse . . .

            SifElement element = null;

            using (Stream aStream = this.GetType().Assembly.GetManifestResourceStream(AdkTest.RESOURCE_ROOT + "StudentPersonalResponse_AddForDelete.xml"))
            {
                SifParser parser = new SifParser();
                // Do one warmup parse . . .
                TextReader aReader = new StreamReader(aStream);
                element = parser.Parse(aReader, null, SifParserFlags.None, SifVersion.SIF11);

                for (int a = 0; a < 5000; a++)
                {
                    aStream.Seek(0, SeekOrigin.Begin);
                    element = parser.Parse(aStream, null, SifParserFlags.None);
                }
                aStream.Close();
            }

            Assert.IsNotNull(element, "SIFElement was not parsed");
        }
Ejemplo n.º 5
0
        public void EmbeddedSIFMessage()
        {
            SifElement element = null;

            using (Stream aStream = GetResourceStream("GetNextMessageResponse.xml"))
            {
                TextReader aReader = new StreamReader(aStream);
                SifParser  parser  = SifParser.NewInstance();
                element = parser.Parse(aReader, null, SifParserFlags.ExpectInnerEnvelope, SifVersion.SIF11);
                aReader.Close();
                aStream.Close();
            }

            Assert.IsNotNull(element, "SIFElement was not parsed");
            SIF_Ack         ack            = (SIF_Ack)element;
            SifElement      messageElement = ack.SIF_Status.SIF_Data.GetChild("SIF_Message");
            SIF_Event       aEvent         = (SIF_Event)messageElement.GetChild("SIF_Event");
            SIF_EventObject eventObject    = aEvent.SIF_ObjectData.SIF_EventObject;

            Assert.AreEqual("SchoolCourseInfo", eventObject.ObjectName, "Wrong object name");
            Assert.AreEqual("Change", eventObject.Action, "Wrong Action");
            Assert.IsTrue(eventObject.GetChildList()[0] is SchoolCourseInfo, "Wrong object type");
        }
Ejemplo n.º 6
0
        public void ParseSectionInfo()
        {
            //  Parse the object from the file
            Console.WriteLine("Parsing from file...");
            SifParser   p           = SifParser.NewInstance();
            SectionInfo sectionInfo = null;

            using (Stream inStream = GetResourceStream("SectionInfo.xml"))
            {
                sectionInfo = (SectionInfo)p.Parse(inStream, null, SifParserFlags.None, SifVersion.SIF15r1);
                inStream.Close();
            }
            Assert.IsNotNull(sectionInfo);

            ScheduleInfoList schedules = sectionInfo.ScheduleInfoList;

            Assert.AreEqual(2, schedules.Count, "Should have two ScheduleInfo elements");

            ScheduleInfo[] scheds = schedules.ToArray();

            // Assert the first ScheduleInfo
            Assert.AreEqual(2, scheds[0].TeacherList.Count, "Should have two teachers");
            Assert.AreEqual(5, scheds[0].MeetingTimeList.Count, "Should have 5 meeeting times");

            // Assert the second ScheduleInfo
            Assert.AreEqual(1, scheds[1].TeacherList.Count, "Should have one teacher");
            Assert.AreEqual(5, scheds[1].MeetingTimeList.Count, "Should have 5 meeeting times");

            // Assert that the SchoolCourseInfoOverride parsed correctly
            SchoolCourseInfoOverride cio = sectionInfo.SchoolCourseInfoOverride;

            Assert.IsNotNull(cio.CourseCredits, "Should have a CourseCreditsOverrides");

            // NOTE: This will currently fail every time, due to a bug in
            // CompareGraphTo
            AdkObjectParseHelper.runParsingTest(sectionInfo, SifVersion.SIF15r1);
        }
        //public string Send(string msg)
        //{
        //   lock (this)
        //   {
        //      fMessages.AddLast(msg);
        //   }
        //   return makeAck();
        //}

        public IMessageInputStream Send( IMessageOutputStream msg )
        {
            lock ( this )
            {
                try
                {
                    MemoryStream stream = new MemoryStream();
                    msg.CopyTo( stream );
                    stream.Seek( 0, SeekOrigin.Begin );
                    SifParser parser = SifParser.NewInstance();
                    SifMessagePayload smp = (SifMessagePayload) parser.Parse( stream, fZone );

                    fMessages.Add( smp );
                    parser = null;

                    SIF_Ack ack = smp.ackStatus( 0 );
                    SIF_Header hdr = ack.Header;
                    hdr.SIF_Timestamp = DateTime.Now;
                    hdr.SIF_MsgId = Adk.MakeGuid();
                    hdr.SIF_SourceId = fZone.Agent.Id;

                    StringWriter str = new StringWriter();
                    SifWriter writer = new SifWriter( str );
                    writer.Write( ack );
                    writer.Flush();
                    writer.Close();
                    writer = null;
                    return new MessageStreamImpl( str.ToString() );
                }
                catch( Exception ex )
                {
                    // Possible error parsing. Write the message to console out
                    Console.Out.WriteLine(msg.Decode());
                    throw new AdkMessagingException(ex.Message, fZone, ex);
                }
            }
        }
Ejemplo n.º 8
0
        public void testSchoolInfo010()
        {
            String schoolInfoResp = "	<SIF_Message  xmlns=\"http://www.sifinfo.org/infrastructure/1.x\" Version=\"1.5r1\">"
                                    + "	  <SIF_Response>"
                                    + "		<SIF_Header>"
                                    + "		  <SIF_MsgId>B329CA6E5BC342339F135880CEE0578E</SIF_MsgId>"
                                    + "		  <SIF_Date>20070813</SIF_Date>"
                                    + "		  <SIF_Time Zone=\"UTC-06:00\">13:55:57</SIF_Time>"
                                    + "		  <SIF_Security>"
                                    + "			<SIF_SecureChannel>"
                                    + "			  <SIF_AuthenticationLevel>0</SIF_AuthenticationLevel>"
                                    + "			  <SIF_EncryptionLevel>0</SIF_EncryptionLevel>"
                                    + "			</SIF_SecureChannel>"
                                    + "		  </SIF_Security>"
                                    + "		  <SIF_SourceId>SASIxp</SIF_SourceId>"
                                    + "		  <SIF_DestinationId>Destiny</SIF_DestinationId>"
                                    + "		</SIF_Header>"
                                    + "		<SIF_RequestMsgId>88BE30BA0B8746809598854A1F58C8CC</SIF_RequestMsgId>"
                                    + "		<SIF_PacketNumber>1</SIF_PacketNumber>"
                                    + "		<SIF_MorePackets>No</SIF_MorePackets>"
                                    + "		<SIF_ObjectData>"
                                    + "		 <SchoolInfo RefId=\"B3E73AC5E8C7392044015E25A454AC6F\">"
                                    + "			<LocalId>997</LocalId>"
                                    + "			<SchoolName>Junior High Demo</SchoolName>"
                                    + "			<PrincipalInfo>"
                                    + "			  <ContactName>Mrs. Pleasant</ContactName>"
                                    + "			</PrincipalInfo>\r\n"
                                    +
                                    /* " <PhoneNumber Format=\"NA\" Type=\"TE\">(949) 888-7655</PhoneNumber>" + */
                                    "			<PhoneNumber Format=\"NA\" Type=\"FE\">888-9877</PhoneNumber>\r\n"
                                    + "			<Address Type=\"SS\">"
                                    + "			  <Street>"
                                    + "				<Line1>Grand Avenue</Line1>"
                                    + "			  </Street>"
                                    + "			  <City>Plesantville</City>"
                                    + "			  <StatePr Code=\"CA\" />"
                                    + "			  <Country Code=\"US\" />"
                                    + "			  <PostalCode>12345</PostalCode>"
                                    + "			</Address>"
                                    + "			<IdentificationInfo Code=\"76\">997</IdentificationInfo>"
                                    + "		  </SchoolInfo>"
                                    + "		</SIF_ObjectData>"
                                    + "	  </SIF_Response>" + "	</SIF_Message>";

            SifParser         parser = SifParser.NewInstance();
            SifMessagePayload smi    = (SifMessagePayload)parser.Parse(
                schoolInfoResp, null);

            // Verify that it is parsing the correct version
            Assertion.AssertEquals("Version", SifVersion.SIF15r1, smi.SifVersion);
            Assertion.AssertEquals("Version attribute", "1.5r1", smi.VersionAttribute);

            SifDataObject sdo = (SifDataObject)((SIF_Response)smi)
                                .SIF_ObjectData.GetChildList()[0];

            // Now attempt an inbound mapping
            IDictionary      fields = new ListDictionary();
            StringMapAdaptor sma    = new StringMapAdaptor(fields);
            Mappings         m      = fCfg.Mappings.GetMappings("Default").Select("asdf", "SASIxp", smi.SifVersion);

            m.MapInbound(sdo, sma, smi.SifVersion);
            Assertion.Assert("Elements Mapped", fields.Count > 0);
            Assertion.AssertEquals("Phone Number", "888-9877", fields["FAX"]);
        }
Ejemplo n.º 9
0
        /// <summary>  Constructs a MessageDispatcher for a zone</summary>
        public MessageDispatcher(ZoneImpl zone)
        {
            fRequestCache = RequestCache.GetInstance(zone.Agent);

            fZone = zone;
            fQueue = zone.fQueue;
            if (fQueue != null)
            {
                if (!fQueue.Ready)
                {
                    throw new AdkQueueException
                        (
                        "Agent Queue is not ready for agent \"" + zone.Agent.Id + "\" zone \"" +
                        zone.ZoneId + "\"",
                        fZone);
                }
                Thread thread = new Thread(new ThreadStart(this.Run));
                thread.Name = zone.Agent.Id + "@" + zone.ZoneId + ".MessageDispatcher";
                thread.Start();
            }

            fSourceId = zone.Agent.Id;
            fKeepMsg = zone.Agent.Properties.KeepMessageContent;
            fAckAckOnPull = zone.Agent.Properties.PullAckAck;

            try
            {
                fParser = SifParser.NewInstance();
            }
            catch (AdkException adke)
            {
                throw new ApplicationException(adke.ToString());
            }
        }
Ejemplo n.º 10
0
        private SifElement parseSIF15r1XML(String xml)
        {
            SifParser parser = SifParser.NewInstance();

            return(parser.Parse(xml, null, 0, SifVersion.SIF15r1));
        }
Ejemplo n.º 11
0
        public void TestToXml()
        {
            // From the javadoc example ...
            // Query for student where the Last Name is Jones and the First Name is
            // Bob, and the graduation year is 2004, 2005, or 2006
            ConditionGroup root = new ConditionGroup(GroupOperator.And);
            ConditionGroup grp1 = new ConditionGroup(GroupOperator.And);
            ConditionGroup grp2 = new ConditionGroup(GroupOperator.Or);

            // For nested elements, you cannot reference a SifDtd constant. Instead, use
            // the lookupElementDefBySQL function to lookup an IElementDef constant
            // given a SIF Query Pattern (SQP)
            IElementDef lname = Adk.Dtd.LookupElementDefBySQP(
                StudentDTD.STUDENTPERSONAL, "Name/LastName");
            IElementDef fname = Adk.Dtd.LookupElementDefBySQP(
                StudentDTD.STUDENTPERSONAL, "Name/FirstName");

            grp1.AddCondition(lname, ComparisonOperators.EQ, "Jones");
            grp1.AddCondition(fname, ComparisonOperators.EQ, "Bob");

            grp2.AddCondition(StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, ComparisonOperators.EQ, "2004");
            grp2.AddCondition(StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, ComparisonOperators.EQ, "2005");
            grp2.AddCondition(StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, ComparisonOperators.EQ, "2006");

            // Add condition groups to the root group
            root.AddGroup(grp1);
            root.AddGroup(grp2);

            //	Query for student with the conditions prepared above by passing the
            //	root ConditionGroup to the constructor
            Query query = new Query(StudentDTD.STUDENTPERSONAL, root);

            query.AddFieldRestriction(StudentDTD.STUDENTPERSONAL_NAME);

            // Now, call toXML() on the query object, reparse back into a Query object and assert all values

            String sifQueryXML = query.ToXml(SifVersion.LATEST);

            Console.WriteLine(sifQueryXML);

            SifParser   parser = SifParser.NewInstance();
            SIF_Request sifR   = (SIF_Request)parser.Parse("<SIF_Request>" + sifQueryXML + "</SIF_Request>", null);

            Query reparsedQuery = new Query(sifR.SIF_Query);

            Assert.AreEqual(StudentDTD.STUDENTPERSONAL, reparsedQuery.ObjectType,
                            "Object Type should be StudentPersonal");
            Assert.AreEqual(1, reparsedQuery.FieldRestrictions.Length, "Should have one field restriction");
            Assert.AreEqual(StudentDTD.STUDENTPERSONAL_NAME, reparsedQuery.FieldRestrictions[0],
                            "Should be for StudentPersonal/Name");


            ConditionGroup newRoot = reparsedQuery.RootConditionGroup;

            Assert.AreEqual(StudentDTD.STUDENTPERSONAL, reparsedQuery.ObjectType, "Should be StudentPersonal");
            Assert.AreEqual(GroupOperator.And, newRoot.Operator, "Root should be an AND conditon");


            ConditionGroup[] groups = reparsedQuery.RootConditionGroup.Groups;
            Assert.AreEqual(2, groups.Length, "Should have two groups");
            Assert.AreEqual(GroupOperator.And, groups[0].Operator, "First group should be AND");
            Assert.AreEqual(GroupOperator.Or, groups[1].Operator, "Second group should be OR");

            // Assert the first group conditions
            Condition[] newGrp1Conditions = groups[0].Conditions;
            Assert.AreEqual(2, newGrp1Conditions.Length, "First group should have two conditions");

            // Assert the first condition
            Assert.AreEqual(ComparisonOperators.EQ, newGrp1Conditions[1].Operators, "First Condition EQ");
            Assert.AreEqual(lname, newGrp1Conditions[0].Field, "First Condition Field");
            Assert.AreEqual("Jones", newGrp1Conditions[0].Value, "First Condition Value");

            // Assert the second condition
            Assert.AreEqual(ComparisonOperators.EQ, newGrp1Conditions[0].Operators, "Second Condition EQ");
            Assert.AreEqual(fname, newGrp1Conditions[1].Field, "First Condition Field");
            Assert.AreEqual("Bob", newGrp1Conditions[1].Value, "First Condition Value");

            // Assert the second group conditions
            Condition[] newGrp2Conditions = groups[1].Conditions;
            Assert.AreEqual(3, newGrp2Conditions.Length, "Second group should have three conditions");

            // Assert the first condition
            Assert.AreEqual(ComparisonOperators.EQ, newGrp2Conditions[0].Operators, "First Condition EQ");
            Assert.AreEqual(StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, newGrp2Conditions[0].Field,
                            "First Condition Field");
            Assert.AreEqual("2004", newGrp2Conditions[0].Value, "First Condition Value");

            // Assert the second condition
            Assert.AreEqual(ComparisonOperators.EQ, newGrp2Conditions[1].Operators, "Second Condition EQ");
            Assert.AreEqual(StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, newGrp2Conditions[1].Field,
                            "Second Condition Field");
            Assert.AreEqual("2005", newGrp2Conditions[1].Value, "Second Condition Value");

            // Assert the third condition
            Assert.AreEqual(ComparisonOperators.EQ, newGrp2Conditions[2].Operators, "Third Condition EQ");
            Assert.AreEqual(StudentDTD.STUDENTPERSONAL_ONTIMEGRADUATIONYEAR, newGrp2Conditions[2].Field,
                            "Third Condition Field");
            Assert.AreEqual("2006", newGrp2Conditions[2].Value, "Third Condition Value");
        }
Ejemplo n.º 12
0
 protected SifParser CreateParser()
 {
     return(SifParser.NewInstance());
 }
Ejemplo n.º 13
0
        public void TestxsiNill_SIFMessagePayload()
        {
            LearnerPersonal lp = new LearnerPersonal();

            // Add a null UPN
            SifString str = new SifString(null);

            lp.SetField(LearnerDTD.LEARNERPERSONAL_UPN, str);

            // Add a null AlertMsg
            AlertMsg msg = new AlertMsg(AlertMsgType.DISCIPLINE, null);

            lp.AlertMsgList = new AlertMsgList(msg);
            msg.SetField(CommonDTD.ALERTMSG, new SifString(null));



            SIF_Response sifMessage = new SIF_Response();

            sifMessage.AddChild(lp);


            //  Write the object to a file
            Console.WriteLine("Writing to file...");
            using (Stream fos = File.Open("SifWriterTest.Temp.xml", FileMode.Create, FileAccess.Write))
            {
                SifWriter writer = new SifWriter(fos);
                sifMessage.SetChanged(true);
                writer.Write(sifMessage);
                writer.Flush();
                fos.Close();
            }

            //  Parse the object from the file
            Console.WriteLine("Parsing from file...");
            SifParser p = SifParser.NewInstance();

            using (Stream fis = File.OpenRead("SifWriterTest.Temp.xml"))
            {
                sifMessage = (SIF_Response)p.Parse(fis, null);
            }



            lp = (LearnerPersonal)sifMessage.GetChildList()[0];


            SimpleField upn = lp.GetField(LearnerDTD.LEARNERPERSONAL_UPN);

            Assert.IsNotNull(upn);

            SifString rawValue = (SifString)upn.SifValue;

            Assert.IsNotNull(rawValue);
            Assert.IsNull(rawValue.Value);
            Assert.IsNull(upn.Value);

            AlertMsgList alertMsgs = lp.AlertMsgList;

            Assert.IsNotNull(alertMsgs);
            Assert.IsTrue(alertMsgs.Count == 1);
            msg = (AlertMsg)alertMsgs.GetChildList()[0];

            Assert.IsNull(msg.Value);
            SifSimpleType msgValue = msg.SifValue;

            Assert.IsNotNull(msgValue);
            Assert.IsNull(msgValue.RawValue);
        }
        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);
        }
Ejemplo n.º 15
0
        public static SifElement WriteParseAndReturn( 
            SifElement o,
            SifVersion version,
            SchemaValidator validator, 
            Boolean echoOut )
        {
            SifElement returnVal;

            if ( o is SifMessagePayload )
            {
                o.SifVersion = version;
            }

            SifWriter echo = null;

            if ( echoOut )
            {
                //   Write the object to System.out
                Console.WriteLine( "Writing object : " + o.ElementDef.Name
                                   + " using SIFVersion: " + version.ToString() );

                echo = new SifWriter( Console.Out );
                echo.Write( o, version );
                echo.Flush();
                Console.Out.Flush();
                
            }

            //  Write the object to a file
            Console.WriteLine( "Writing to file... test.xml" );
            using (Stream fos = new FileStream("test.xml", FileMode.Create))
            {
                SifWriter writer = new SifWriter( new StreamWriter( fos, Encoding.UTF8 ) );
                o.SetChanged( true );
                writer.Write( o, version );
                writer.Flush();
                writer.Close();
                fos.Close();
            }

            if ( validator != null )
            {
                Validate( "test.xml", validator );
            }

            //  Parse the object from the file
            Console.WriteLine( "Parsing from file..." );
            SifParser p = SifParser.NewInstance();

            FileStream fr = new FileStream( "test.xml", FileMode.Open );

            StreamReader inStream = new StreamReader( fr, Encoding.UTF8 );


            returnVal = p.Parse( inStream, null, 0, version );

            inStream.Close();
            fr.Close();
            //  Write the parsed object to System.out
            returnVal.SetChanged( true );
            Console.WriteLine( "Read object : " + returnVal.ElementDef.Name );
            if ( echoOut )
            {
                echo.Write( returnVal, version );
                echo.Flush();
            }


            return returnVal;
        }
Ejemplo n.º 16
0
        public void testLeaInfoParseFrom15r1()
        {
            Adk.SifVersion = SifVersion.SIF15r1;
            String leaInfoXML = "	<LEAInfo RefId='1234' xmlns='http://www.sifinfo.org/infrastructure/1.x'>"
                                + "    <LocalId>1234</LocalId>"
                                + "    <StatePrId>4567</StatePrId>"
                                + "    <LEAName>Tom District</LEAName>"
                                + "    <PhoneNumber Format='NA' Type='TE'>814.455.4658</PhoneNumber>"
                                + "    <Address Type='07'>"
                                + "      <Street>"
                                + "        <Line1>1232 Bateman Point Drive</Line1>"
                                + "        <Line2></Line2>"
                                + "        <Line3></Line3>"
                                + "      </Street>"
                                + "      <City>West Jordan</City>"
                                + "      <StatePr Code='Utah' />"
                                + "      <PostalCode>84084</PostalCode>"
                                + "    </Address>"
                                + "    <LEAContact>"
                                + "      <ContactInfo>"
                                + "        <Name Type='04'>"
                                + "          <LastName>Ngo</LastName>"
                                + "          <FirstName>Tom</FirstName>"
                                + "          <MiddleName>C.</MiddleName>"
                                + "        </Name>"
                                + "        <PositionTitle>Principal</PositionTitle>"
                                + "        <PhoneNumber Format='NA' Type='TE'></PhoneNumber>"
                                + "        <Email Type='Primary'>[email protected]</Email>"
                                + "      </ContactInfo>" + "    </LEAContact>" + "  </LEAInfo>";

            String agentCFG = "<agent id='Repro' sifVersion='2.0'>"
                              + "   <mappings id='Default'>"
                              + "     <object object='LEAInfo'>"
                              + "     <field name='LOCALID'>LocalId</field>"
                              + "     <field name='STATEPRID' sifVersion='+2.0'>StateProvinceId</field>"
                              + "     <field name='STATEPRID' sifVersion='-1.5r1'>StatePrId</field>"
                              + "     <field name='NAME'>LEAName</field>"
                              + "     <field name='DISTRICT_PHONE' sifVersion='+2.0'>PhonenumberList/PhoneNumber[@Type='0096']/Number</field>"
                              + "     <field name='DISTRICT_PHONE' sifVersion='-1.5r1'>PhoneNumber[@Format='NA',@Type='TE']</field>"
                              + "     <field name='DISTRICT_ADDR1' sifVersion='+2.0'>AddressList/Address[@Type='2382']/Street/Line1</field>"
                              + "     <field name='DISTRICT_ADDR1' sifVersion='-1.5r1'>Address[@Type='07']/Street/Line1</field>"
                              + "     <field name='DISTRICT_ADDR2' sifVersion='+2.0'>AddressList/Address[@Type='2382']/Street/Line2</field>"
                              + "     <field name='DISTRICT_ADDR2' sifVersion='-1.5r1'>Address[@Type='07']/Street/Line2</field>"
                              + "     <field name='DISTRICT_ADDR3' sifVersion='+2.0'>AddressList/Address[@Type='2382']/Street/Line3</field>"
                              + "     <field name='DISTRICT_ADDR3' sifVersion='-1.5r1'>Address[@Type='07']/Street/Line3</field>"
                              + "     <field name='DISTRICT_CITY' sifVersion='+2.0'>AddressList/Address[@Type='0123']/City</field>"
                              + "     <field name='DISTRICT_CITY' sifVersion='-1.5r1'>Address[@Type='07']/City</field>"
                              + "     <field name='DISTRICT_STATE' sifVersion='+2.0'>AddressList/Address[@Type='0123']/StateProvince</field>"
                              + "     <field name='DISTRICT_STATE' sifVersion='-1.5r1'>Address[@Type='07']/StatePr/@Code</field>"
                              + "     <field name='DISTRICT_COUNTRY' sifVersion='+2.0'>AddressList/Address[@Type='0123']/Country=US</field>"
                              + "     <field name='DISTRICT_COUNTRY' sifVersion='-1.5r1'>Address[@Type='07']/Country[@Code='US']</field>"
                              + "     <field name='DISTRICT_ZIPCODE' sifVersion='+2.0'>AddressList/Address[@Type='0123']/PostalCode</field>"
                              + "     <field name='DISTRICT_ZIPCODE' sifVersion='-1.5r1'>Address[@Type='07']/PostalCode</field>"
                              + "     <field name='CONTACT_POSITION' sifVersion='+2.0'>LEAContactList/LEAContact/ContactInfo/PositionTitle</field>"
                              + "     <field name='CONTACT_POSITION' sifVersion='-1.5r1'>LEAContact/ContactInfo/PositionTitle</field>"
                              + "     <field name='CONTACT_PHONE' sifVersion='+2.0'>LEAContactList/LEAContact/ContactInfo/PhonenumberList/PhoneNumber[@Type='0096']/Number</field>"
                              + "     <field name='CONTACT_PHONE' sifVersion='-1.5r1'>LEAContact/ContactInfo/PhoneNumber[@Format='NA',@Type='TE']</field>"
                              + "     <field name='CONTACT_EMAIL' sifVersion='+2.0'>LEAContactList/LEAContact/ContactInfo/EmailList/Email[@Type='Primary']</field>"
                              + "     <field name='CONTACT_EMAIL' sifVersion='-1.5r1'>LEAContact/ContactInfo/Email[@Type='Primary']</field>"
                              + "     <field name='CONTACT_FIRSTNAME' sifVersion='+2.0'>LEAContactList/LEAContact/ContactInfo/Name[@Type='04']/FirstName</field>"
                              + "     <field name='CONTACT_FIRSTNAME' sifVersion='-1.5r1'>LEAContact/ContactInfo/Name[@Type='04']/FirstName</field>"
                              + "     <field name='CONTACT_MIDDLENAME' sifVersion='+2.0'>LEAContactList/LEAContact/ContactInfo/Name[@Type='04']/MiddleName</field>"
                              + "     <field name='CONTACT_MIDDLENAME' sifVersion='-1.5r1'>LEAContact/ContactInfo/Name[@Type='04']/MiddleName</field>"
                              + "     <field name='CONTACT_LASTNAME' sifVersion='+2.0'>LEAContactList/LEAContact/ContactInfo/Name[@Type='04']/LastName</field>"
                              + "     <field name='CONTACT_LASTNAME' sifVersion='-1.5r1'>LEAContact/ContactInfo/Name[@Type='04']/LastName</field>"
                              + "</object></mappings></agent>";


            SifParser p         = SifParser.NewInstance();
            LEAInfo   leaObject = (LEAInfo)p.Parse(leaInfoXML, null, 0, SifVersion.SIF15r1);

            PhoneNumber phone = leaObject.PhoneNumberList.ItemAt(0);

            Assertion.AssertEquals("Format", "NA", phone.Format);
            Assertion.AssertEquals("Type", "TE", phone.Type);
            Assertion.AssertEquals("District Phone", "814.455.4658", phone.Number);

            phone = leaObject.LEAContactList.ItemAt(0).ContactInfo.PhoneNumberList.ItemAt(0);
            Assertion.AssertEquals("Format", "NA", phone.Format);
            Assertion.AssertEquals("Type", "TE", phone.Type);
            Assertion.AssertEquals("Contact Phone", "", phone.Number);

            AgentConfig cfg    = createConfig(agentCFG);
            Mappings    m      = cfg.Mappings.GetMappings("Default").Select(null, null, null);
            IDictionary target = new Hashtable();

            m.MapInbound(leaObject, new StringMapAdaptor(target));

            Console.WriteLine(leaObject.SifVersion);

            Assertion.AssertEquals("District Phone", "814.455.4658", target["DISTRICT_PHONE"]);
            Assertion.AssertEquals("District Phone", "", target["CONTACT_PHONE"]);
        }
Ejemplo n.º 17
0
        public void TestXsiNill_AllChildrenNilMultiple()
        {
            SIF_Data data = new SIF_Data();

            for (int a = 0; a < 3; a++)
            {
                SchoolInfo            si   = new SchoolInfo();
                AddressableObjectName paon = new AddressableObjectName();
                paon.Description = "The little white school house";
                paon.StartNumber = "321";
                Address      addr = new Address(AddressType.CURRENT, paon);
                GridLocation gl   = new GridLocation();
                gl.SetField(CommonDTD.GRIDLOCATION_PROPERTYEASTING, new SifDecimal(null));
                gl.SetField(CommonDTD.GRIDLOCATION_PROPERTYNORTHING, new SifDecimal(null));
                addr.GridLocation = gl;
                si.AddressList    = new AddressList(addr);

                data.AddChild(si);
            }



            //  Write the object to a file
            Console.WriteLine("Writing to file...");
            using (Stream fos = File.Open("SifWriterTest.Temp.xml", FileMode.Create, FileAccess.Write))
            {
                SifWriter writer = new SifWriter(fos);
                data.SetChanged(true);
                writer.Write(data);
                writer.Flush();
                fos.Close();
            }

            //  Parse the object from the file
            Console.WriteLine("Parsing from file...");
            SifParser p = SifParser.NewInstance();

            using (Stream fis = File.OpenRead("SifWriterTest.Temp.xml"))
            {
                data = (SIF_Data)p.Parse(fis, null);
            }

            foreach (SchoolInfo si in data.GetChildList())
            {
                AddressList al = si.AddressList;
                Assert.IsNotNull(al);

                Address addr = al.ItemAt(0);
                Assert.IsNotNull(addr);

                GridLocation gl = addr.GridLocation;
                Assert.IsNotNull(gl);

                Assert.IsNull(gl.PropertyEasting);
                Assert.IsNull(gl.PropertyNorthing);

                SimpleField sf = gl.GetField(CommonDTD.GRIDLOCATION_PROPERTYEASTING);
                Assert.IsNotNull(sf);
                Assert.IsNull(sf.Value);

                sf = gl.GetField(CommonDTD.GRIDLOCATION_PROPERTYNORTHING);
                Assert.IsNotNull(sf);
                Assert.IsNull(sf.Value);
            }
        }