Example #1
0
        /// <summary>
        /// 回傳畫面物件的方法。在這邊做順序判斷
        /// </summary>
        /// <returns>畫面物件</returns>
        public FrameObject GetFrameObject(UserInfo userInfo)
        {
            //要這樣嗎
            UserInfo = userInfo;

            //若順序不合法則返回原畫面
            if (!(OrderingRule.IsOrderLegit(userInfo.LastFeature, this.GetType())))
            {
                return(userInfo.FrameObject);
            }

            //其他exception的情況
            try
            {
                var frameObject = CreateFrameObject();
                //若執行成功,則記錄下這一次執行的IFeature的type
                userInfo.LastFeature = this.GetType();

                return(frameObject);
            }
            catch (Exception exception)
            {
                //查詢例外字典
                if (ExceptionDic.ContainsKey(exception.GetType()))
                {
                    //這裡不太對
                    return(ExceptionDic[exception.GetType()].Invoke(userInfo.FrameObject, userInfo));
                }
                else
                {
                    //沒處理到的情況→直接死機
                    throw new Exception(exception.Message);
                }
            }
        }
Example #2
0
        /// <summary>
        /// 處理例外狀況後回傳畫面物件
        /// </summary>
        /// <param name="userInfo">用戶資訊</param>
        /// <returns>畫面物件</returns>
        public FrameObject GetAnswer(UserInfo userInfo)
        {
            if (!(OrderingRule.IsOrderLegit(userInfo.ComputeObject.LastFeature, this.GetType())))
            {
                return(userInfo.BoardObject.FrameObject);
            }

            try
            {
                //特殊狀況處理
                if (userInfo.ComputeObject.LastFeature == typeof(Equal) && this.GetType() == typeof(Number))
                {
                    userInfo.BoardObject.Init();
                }

                var frameObject = GetFrameObject(userInfo.BoardObject, Compute(userInfo.ComputeObject));

                userInfo.ComputeObject.LastFeature = this.GetType();
                return(frameObject);
            }
            catch (Exception exception)
            {
                //查詢例外字典
                if (ExceptionDic.ContainsKey(exception.GetType()))
                {
                    //這裡不太對
                    return(ExceptionDic[exception.GetType()].Invoke(userInfo.BoardObject.FrameObject, userInfo));
                }
                else
                {
                    //沒處理到的情況→直接死機
                    throw new Exception(exception.Message);
                }
            }
        }