Beispiel #1
0
        /// <summary>
        /// RunTask
        /// </summary>
        /// <param name="transfer"></param>
        private void RunTask(IEventMessage transfer)
        {
            String eventMessage = transfer.EventMessage;                                                           //事件消息

            KeyValuePair <string, string> taskEventPair = new KeyValuePair <string, string>(Status, eventMessage); //事件-传输子对

            //判断是否存在任务,如果不存在任务的话,保持现状
            if (_tTaskTable.ContainsKey(taskEventPair))
            {
                //根据事件-传输子对取得一个任务
                StateMachineTask stateMachineTask = _tTaskTable[taskEventPair];
                //判断任务是否存在
                if (stateMachineTask != null)
                {
                    //判断任务中是否有下一个状态
                    if (stateMachineTask.NextStatus != null)
                    {
                        //设定下一个状态
                        Status = stateMachineTask.NextStatus;
                    }
                    //判断动作是否存在
                    if (stateMachineTask.Action != null)
                    {
                        //载入传输子,执行动作
                        stateMachineTask.Action(transfer);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="state"></param>
        /// <param name="eventMessage"></param>
        /// <param name="action"></param>
        /// <param name="nextState"></param>
        public void AddTask(String state, String eventMessage, Action <IEventMessage> action, String nextState)
        {
            //定义状态-事件的键值对
            KeyValuePair <string, string> stateEventPair = new KeyValuePair <string, string>(state, eventMessage);
            //定义一个任务
            StateMachineTask task = new StateMachineTask(action, nextState);

            //压入任务表(状态转移表)
            _tTaskTable.Add(stateEventPair, task);
        }
        /// <summary>
        /// 添加任务
        /// </summary>
        /// <param name="state"></param>
        /// <param name="eventMessage"></param>
        /// <param name="action"></param>
        /// <param name="nextState"></param>
        public void AddTask(String state, String eventMessage, Action<IEventMessage> action, String nextState)
        {
            //定义状态-事件的键值对
            KeyValuePair<string, string> stateEventPair = new KeyValuePair<string, string>(state, eventMessage);
            //定义一个任务
            StateMachineTask task = new StateMachineTask(action, nextState);
            //压入任务表(状态转移表)
            _tTaskTable.Add(stateEventPair, task);

        }