/// <summary>  Create a SIF_Ack for this message.</summary>
        /// <param name="code">The SIF_Status/SIF_Code value
        /// </param>
        /// <returns> A new SIF_Ack instance where the SIF_Status/SIF_Code value is
        /// set to the specified value and SIF_Ack header values are derived
        /// from this message's header values
        /// </returns>
        public virtual SIF_Ack ackStatus(int code)
        {
            SIF_Ack    ack    = new SIF_Ack();
            SIF_Status status = new SIF_Status(code);

            ack.SIF_Status           = status;
            ack.SIF_OriginalMsgId    = MsgId;
            ack.SIF_OriginalSourceId = SourceId;


            SifVersion msgVersion = this.SifVersion;

            if (code == 8 /* Receiver is sleeping */)
            {
                if (msgVersion.Major == 1)
                {
                    // SIF 1.x used SIF_Data for text
                    SIF_Data d = new SIF_Data();
                    d.TextValue     = "Receiver is sleeping";
                    status.SIF_Data = d;
                }
                else
                {
                    status.SIF_Desc = "Receiver is sleeping";
                }
            }

            ack.message = this;

            //  Ack using the same version of SIF as this message
            ack.SifVersion = msgVersion;

            return(ack);
        }
Beispiel #2
0
//		/// <summary>  Throws an AdkMessagingException, optionally logging its message first</summary>
//		public static void  _throw(AdkMessagingException thr, Category log)
//		{
//			if ((Adk.Debug & AdkDebugFlags.Exceptions) != 0)
//				thr.log(log);
//			throw thr;
//		}
//
//		/// <summary>  Throws an AdkTransportException, optionally logging its message first</summary>
//		public static void  _throw(AdkTransportException thr, Category log)
//		{
//			if ((Adk.Debug & AdkDebugFlags.Exceptions) != 0)
//				thr.log(log);
//			throw thr;
//		}

        /// <summary>  Throws a SifException, optionally logging its message first</summary>
        public static void _throw(SifException thr,
                                  ILog log)
        {
            SifException exc = thr;

            //  If exception has a non-success status code and no errors, substitute a
            //  more descriptive exception
            if (thr.Ack != null && (!thr.Ack.HasStatusCode(0) && !thr.Ack.HasError()))
            {
                StringBuilder b = new StringBuilder();
                b.Append("Received non-success status code (");

                SIF_Status s = thr.Ack.SIF_Status;
                if (s == null)
                {
                    b.Append("and no SIF_Status element exists");
                }
                else
                {
                    b.Append(s.SIF_Code);
                }

                b.Append(") but no error information");

                exc = new SifException(b.ToString(), thr.Ack, thr.Zone);
            }

            if ((Adk.Debug & AdkDebugFlags.Exceptions) != 0)
            {
                exc.Log(log);
            }

            throw exc;
        }