Example #1
0
        /**
         *  Sends a SIF_Event
         *  @param zone The zone to send the sifEvent to
         */
        public SIF_Ack SifEvent(IZone zone, Event sifEvent, String destinationId, String sifMsgId)
        {
            if (sifEvent.Data == null || sifEvent.Data.Available == false)
            {
                throw new AdkException("The sifEvent has no SIFDataObjects", zone);
            }

            SIF_ObjectData od = new SIF_ObjectData();

            //  Fill out the SIF_ObjectData
            IDataObjectInputStream inStr = sifEvent.Data;
            SifDataObject          data  = inStr.ReadDataObject();

            SifVersion msgVersion = data.EffectiveSIFVersion;

            SIF_EventObject eo = new SIF_EventObject();

            od.SIF_EventObject = eo;
            eo.Action          = sifEvent.ActionString;
            eo.ObjectName      = data.ElementDef.Tag(msgVersion);

            // Create the SIF_Event object
            SIF_Event msg = new SIF_Event(msgVersion);

            msg.SIF_ObjectData = od;

            SIF_Header msgHdr = msg.Header;

            //	Assign SIF_DestinationId if applicable
            if (destinationId != null)
            {
                msgHdr.SIF_DestinationId = destinationId;
            }

            while (data != null)
            {
                eo.Attach(data);
                data = inStr.ReadDataObject();
            }

            if (sifMsgId != null)
            {
                msgHdr.SIF_MsgId = sifMsgId;
            }

            SifContext[] contexts = sifEvent.Contexts;
            if (contexts == null)
            {
                contexts = new SifContext[] { SifContext.DEFAULT };
            }

            SIF_Contexts msgContexts = new SIF_Contexts();

            foreach (SifContext context in contexts)
            {
                msgContexts.AddSIF_Context(context.Name);
            }
            msgHdr.SIF_Contexts = msgContexts;
            return(((ZoneImpl)zone).Dispatcher.send(msg));
        }
Example #2
0
        private SIF_Event createSIF_Event(IElementDef objType)
        {
            SIF_Event evnt = new SIF_Event();

            evnt.Header.SIF_SourceId = "foo";
            SIF_ObjectData  sod = new SIF_ObjectData();
            SIF_EventObject obj = new SIF_EventObject();

            obj.ObjectName      = objType.Name;
            sod.SIF_EventObject = obj;
            evnt.SIF_ObjectData = sod;

            obj.Action = EventAction.Add.ToString();

            Object eventObject = null;

            try
            {
                eventObject = ClassFactory.CreateInstance(objType.FQClassName);
            }
            catch (Exception cfe)
            {
                throw new AdkException("Unable to create instance of " + objType.Name, fZone, cfe);
            }


            obj.AddChild(objType, (SifElement)eventObject);

            return(evnt);
        }
Example #3
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");
        }