Exemple #1
0
        public virtual void Write(SifMessagePayload o)
        {
            SetSifVersion(o.SifVersion);
            fWriter.WriteStartElement("SIF_Message", o.GetXmlns());
            writeRootAttributes(true);

            Write((SifElement)o);
            fWriter.WriteEndElement();
        }
Exemple #2
0
        /// <summary>  Called by the Adk to construct a SifMessageInfo</summary>
        /// <param name="msg">The SIF_Message
        /// </param>
        /// <param name="zone">The associated zone
        /// </param>
        public SifMessageInfo(SifMessagePayload msg,
                              IZone zone)
        {
            fZone    = zone;
            fPayload = Adk.Dtd.GetElementType(msg.ElementDef.Name);
            if (zone.Properties.KeepMessageContent)
            {
                try {
                    StringWriter sw     = new StringWriter();
                    SifWriter    writer = new SifWriter(sw);
                    writer.Write(msg);
                    writer.Flush();
                    writer.Close();
                    sw.Close();

                    fMessage = sw.ToString();
                }
                catch {
                    // Do nothing
                }
            }

            //  Set SIF_Header values
            fHeader = msg.Header;
            IList <SifContext> contexts = msg.SifContexts;

            fContexts = new SifContext[contexts.Count];
            contexts.CopyTo(fContexts, 0);

            //  Set information about the message payload
            fPayloadVersion = msg.SifVersion;
            switch (fPayload)
            {
            case SifMessageType.SIF_Request:
            {
                SIF_Request req = (SIF_Request)msg;
                fObjects["SIF_MaxBufferSize"]   = req.SIF_MaxBufferSize;
                fObjects["SIF_RequestVersions"] = req.parseRequestVersions(fZone.Log);
            }
            break;

            case SifMessageType.SIF_Response:
            {
                SIF_Response rsp = (SIF_Response)msg;
                this.SIFRequestMsgId         = rsp.SIF_RequestMsgId;
                fObjects["SIF_PacketNumber"] = rsp.SIF_PacketNumber;
                SetAttribute("SIF_MorePackets", rsp.SIF_MorePackets);
            }
            break;
            }
        }
 private void AssertRetryHandling(ErrorMessageHandler handler, SifMessagePayload payload, ZoneImpl zone)
 {
     try
      {
     assertNormalHandling(handler, payload, zone);
      }
      catch (SifException ex)
      {
     Assert.IsTrue(handler.wasCalled(), "Handler was not called");
     Assert.AreEqual(SifErrorCategoryCode.Transport, ex.ErrorCategory,
                     "SIF Error category should be 10: " + ex.Message);
      }
      Assert.IsTrue(handler.wasCalled(), "Handler was not called");
      AssertThreadIsOK();
 }
 private void assertNormalHandling(ErrorMessageHandler handler, SifMessagePayload payload, ZoneImpl zone)
 {
     MessageDispatcher testDispatcher = new MessageDispatcher(zone);
      int result = testDispatcher.dispatch(payload);
      Assert.IsTrue(handler.wasCalled(), "Handler was not called");
      Assert.AreEqual(1, result, "Result code should always be 1 because this version does not support SMB");
 }
        private void AssertExceptionHandling(ErrorMessageHandler handler, SifMessagePayload payload, ZoneImpl zone,
                                             Type expectedExceptionType)
        {
            Exception exc = null;
             try
             {
            assertNormalHandling(handler, payload, zone);
             }
             catch (Exception ex)
             {
            exc = ex;
            Assert.IsTrue(handler.wasCalled(), "Handler was not called");

            AdkMessagingException adkme = ex as AdkMessagingException;
            Assert.IsNotNull(adkme,
                             "Expected an ADKMessagingException, but was " + ex.GetType().Name + ":" + ex.ToString());

             Exception source = adkme;
             Exception innerEx = null;
             while( source.InnerException != null )
             {
                 innerEx = source.InnerException;
                 source = innerEx;
             }
            Assert.IsNotNull(innerEx, "AdkMessaginException was thrown but inner exception was not set");

            if (innerEx.GetType() != expectedExceptionType)
            {
               Assert.Fail("Exception thrown was not a " + expectedExceptionType.Name + ", but was " +
                           innerEx.GetType().Name + ":" + innerEx.ToString());
            }
             }

             Assert.IsNotNull(exc, "An exception was not thrown by the handler");
             AssertThreadIsOK();
        }
        /// <summary>  Called by the Adk to construct a SifMessageInfo</summary>
        /// <param name="msg">The SIF_Message
        /// </param>
        /// <param name="zone">The associated zone
        /// </param>
        public SifMessageInfo( SifMessagePayload msg,
                               IZone zone )
        {
            fZone = zone;
            fPayload = Adk.Dtd.GetElementType( msg.ElementDef.Name );
            if ( zone.Properties.KeepMessageContent ) {
                try {
                    StringWriter sw = new StringWriter();
                    SifWriter writer = new SifWriter( sw );
                    writer.Write( msg );
                    writer.Flush();
                    writer.Close();
                    sw.Close();

                    fMessage = sw.ToString();
                }
                catch {
                    // Do nothing
                }
            }

            //  Set SIF_Header values
            fHeader = msg.Header;
            IList<SifContext> contexts = msg.SifContexts;
            fContexts = new SifContext[ contexts.Count ];
            contexts.CopyTo( fContexts, 0 );

            //  Set information about the message payload
            fPayloadVersion = msg.SifVersion;
            switch ( fPayload ) {
                case SifMessageType.SIF_Request:
                    {
                        SIF_Request req = (SIF_Request) msg;
                        fObjects["SIF_MaxBufferSize"] = req.SIF_MaxBufferSize;
                        fObjects["SIF_RequestVersions"] = req.parseRequestVersions( fZone.Log );
                    }
                    break;

                case SifMessageType.SIF_Response:
                    {
                        SIF_Response rsp = (SIF_Response) msg;
                        this.SIFRequestMsgId = rsp.SIF_RequestMsgId;
                        fObjects["SIF_PacketNumber"] = rsp.SIF_PacketNumber;
                        SetAttribute( "SIF_MorePackets", rsp.SIF_MorePackets );
                    }
                    break;
            }
        }
Exemple #7
0
        public virtual void Write( SifMessagePayload o )
        {
            SetSifVersion( o.SifVersion );
            fWriter.WriteStartElement( "SIF_Message", o.GetXmlns() );
            writeRootAttributes( true );

            Write( (SifElement) o );
            fWriter.WriteEndElement();
        }
        private SIF_Ack ProcessPush( SifMessagePayload parsed )
        {
            try {
                //  Dispatch. When the result is an Integer it is an ack code to
                //  return; otherwise it is ack data to return and the code is assumed
                //  to be 1 for an immediate acknowledgement.
                int ackStatus = this.Zone.Dispatcher.dispatch( parsed );

                //  Ask the original message to generate a SIF_Ack for itself
                return parsed.ackStatus( ackStatus );
            }
            catch ( SifException se ) {
                return
                    parsed.AckError( se );
            }
            catch ( AdkException adke ) {
                return
                    parsed.AckError
                        ( SifErrorCategoryCode.Generic, SifErrorCodes.GENERIC_GENERIC_ERROR_1,
                          adke.Message );
            }
            catch ( Exception thr ) {
                if ( (Adk.Debug & AdkDebugFlags.Messaging) != 0 ) {
                    this.Zone.Log.Debug( "Uncaught exception dispatching push message: " + thr );
                }

                return
                    parsed.AckError
                        ( SifErrorCategoryCode.Generic, SifErrorCodes.GENERIC_GENERIC_ERROR_1,
                          "An unexpected error has occurred", thr.ToString() );
            }
        }