/// <summary>Return a response for the message</summary>
        /// <param name="msg">The message link to this response</param>
        /// <returns>The response to the message</returns>
        public ISpEventMessage Response(ISpEventMessage msg)
        {
            DemoMsgId   id    = SpConverter.IntToEnum <DemoMsgId>(msg.EventId);
            DemoMsgType _type = SpConverter.IntToEnum <DemoMsgType>(msg.TypeId);

            // Only one type of message for now.
            // Responses also in the same enum as messages so have to handle
            switch (_type)
            {
            case DemoMsgType.SimpleMsg:
                // TODO Hmm should this be a response instead of a message?
                return(new DemoMsgBase(_type, id, msg.Priority)
                {
                    ReturnCode = msg.ReturnCode,
                    StringPayload = msg.StringPayload,
                    ReturnStatus = msg.ReturnStatus,
                    // You can add any other info from derived message
                });

            case DemoMsgType.SimpleResponse:
                throw new Exception(string.Format("Response '{0}' is not a valid message", _type));

            default:
                throw new Exception(string.Format("Unhandled message '{0}'", _type));
            }
        }
Beispiel #2
0
        public ISpEventMessage Response(ISpEventMessage msg)
        {
            MyMsgId   eventType = SpConverter.IntToEnum <MyMsgId>(msg.EventId);
            MyMsgType msgType   = SpConverter.IntToEnum <MyMsgType>(msg.TypeId);

            // All my messages are Simple Types so I do not need any other info for types. Otherwise I would need a switch
            return(new MyBaseMsg(msgType, eventType, msg.Priority)
            {
                ReturnCode = msg.ReturnCode,
                StringPayload = msg.StringPayload,
                ReturnStatus = msg.ReturnStatus
            });
        }
        //protected override ISpEventMessage ExecOnTick(ISpEventMessage eventMsg) {
        //    Console.WriteLine("########## {0} has received OnTick event:{1}", this.FullName, eventMsg.EventId);
        //    return base.ExecOnEntry(eventMsg);
        //    // just push the same one back
        //    //return eventMsg;
        //}
        //protected override ISpEventMessage ExecOnTick(ISpEventMessage eventMsg) {
        //    Console.WriteLine("########## {0} has received OnTick event:{1}", this.FullName, eventMsg.EventId);
        //    return base.ExecOnEntry(eventMsg);
        //    // just push the same one back
        //    //return eventMsg;
        //}



        #region SpStateOverrides

        protected override ISpEventMessage OnRuntimeTransitionRequest(ISpEventMessage msg)
        {
            switch (SpConverter.IntToEnum <MyMsgId>(msg.EventId))
            {
            case MyMsgId.Abort:
                Log.Info("MySuperState", "OnRuntimeTransitionRequest", " *** Got abort and returning Stop");

                // get the GUID
                ISpEventMessage myMsg = new MyBaseMsg(MyMsgType.SimpleMsg, MyMsgId.Stop);
                myMsg.Uid = msg.Uid;
                return(myMsg);

            default:

                break;
            }


            //// Do not know which state this is except it is the current state
            if (msg.EventId == SpConverter.EnumToInt(MyMsgId.Abort))
            {
                //this.GetCurrentState().

                // get the GUID
                ISpEventMessage myMsg = new MyBaseMsg(MyMsgType.SimpleMsg, MyMsgId.Start);

                // Try recursion - no will not work
                //this.OnTick(myMsg);

                //this.GetCurrentState().

                //return this.GetOnResultTransition(myMsg);
            }


            return(base.OnRuntimeTransitionRequest(msg));
        }