public void run()
    {
        /**
         * This class periodically publishes change events to the zone. This
         * method starts up the thread that publishes the change events.
         *
         * A normal SIF Agent would, instead look for changes in the application's database
         * and publish those as changes.
         */

        Console.WriteLine
            ("Event publishing enabled with an interval of " + EVENT_INTERVAL / 1000 +
            " seconds.");

        Random random = new Random();

        bool isProcessing = true;

        // Go into a loop and send events
        while (isProcessing)
        {
            try
            {
                Thread.Sleep(EVENT_INTERVAL);

                SifDataObject changedObject = fData[random.Next(fData.Count)];
                SifDataObject eventObject   = Adk.Dtd.CreateSIFDataObject(getElementDef());
                eventObject.SetElementOrAttribute
                    ("@PersonRefId",
                    changedObject.GetElementOrAttribute("@PersonRefId").
                    TextValue);

                // Create a change event with a random Learner ID;
                string newNum = "A" + random.Next(999999);
                eventObject.SetElementOrAttribute("LocalId", newNum);

                fZone.ReportEvent(eventObject, EventAction.Change);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error during event processing: " + ex);
                isProcessing = false;
            }
        }
    }
        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);
        }