// TODO: Implement
        /*

        private SIF_Request createSIF_Request( ElementDef objectType, String refId, Zone zone )
        {
           SIF_Request request = new SIF_Request();
           request.getHeader().setSIF_MsgId( MSG_GUID );
           request.getHeader().setSIF_SourceId( "foo" );
           request.setSIF_MaxBufferSize("32768");
           request.setSIF_Version( ADK.getSIFVersion().toString() );
           Query query = new Query(objectType);
           query.addCondition(SifDtd.SIF_REPORTOBJECT_REFID, Condition.EQ, refId);

           SIF_Query q = SIFPrimitives.createSIF_Query(query, zone);
           SIF_QueryObject sqo = new SIF_QueryObject();
           sqo.setObjectName( objectType.name() );

           q.setSIF_QueryObject(sqo);
           request.setSIF_Query(q);

           return request;
        }

         */
        private SIF_Response createSIF_Response(IElementDef objType, bool storeInRequestCache, ISerializable stateObject)
        {
            SIF_Request req = createSIF_Request(objType);

             if (storeInRequestCache)
             {
            Query q = new Query(objType);
            q.UserData = stateObject;
            RequestCache.GetInstance(fAgent).StoreRequestInfo(req, q, fZone);
             }

             SIF_Response resp = new SIF_Response();
             resp.SIF_RequestMsgId = req.Header.SIF_MsgId;
             SIF_ObjectData sod = new SIF_ObjectData();
             resp.SIF_ObjectData = sod;

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

             sod.AddChild((SifElement)responseObject);
             return resp;
        }
        /// <summary>  Calculate the size of a SIF_Response minus the SIF_ObjectData content.</summary>
        protected virtual long CalcEnvelopeSize( ZoneImpl zone )
        {
            long size = 400;

            try {
                SIF_Response rsp = new SIF_Response();
                rsp.SIF_MorePackets = "Yes";
                rsp.SIF_RequestMsgId = fReqId;
                rsp.SIF_PacketNumber = 100000000;
                SIF_ObjectData data = new SIF_ObjectData();
                data.TextValue = " ";
                rsp.SIF_ObjectData = data;

                SIF_Header hdr = rsp.Header;

                hdr.SIF_Timestamp = DateTime.Now;
                hdr.SIF_MsgId = "012345678901234567890123456789012";
                hdr.SIF_SourceId = zone.Agent.Id;
                hdr.SIF_Security = zone.Dispatcher.secureChannel();
                hdr.SIF_DestinationId = fDestId;

                using ( MemoryStream buffer = new MemoryStream() ) {
                    SifWriter writer = new SifWriter( buffer );
                    writer.Write( rsp );
                    writer.Flush();
                    size = buffer.Length + 10;
                    writer.Close();
                    buffer.Close();
                }
            }
            catch( Exception ex ) {
                zone.Log.Warn( "Error calculating packet size: " + ex, ex );
            }

            return size;
        }
        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;
        }
Пример #4
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);
        }