Esempio n. 1
0
        /// <summary>
        /// 对外接口,解析 Cmd
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        public ExecRest Exec(Cmd cmd)
        {
            Logger.Debug("[CmdParseService] 执行命令:" + cmd.Action);
            var rest  = new ExecRest();
            var types = YUtil.GetTypes(cmd.Action, Assembly.GetExecutingAssembly());

            if (types.Count == 1)
            {
                var type = types[0];
                if (executors.TryGetValue(type, out var exec))
                {
                    var data = cmd.Args != null
                        ? JsonConvert.DeserializeObject(JsonConvert.SerializeObject(cmd.Args), type)
                        : null;

                    try {
                        rest = exec(data);
                    } catch (Exception e) {
                        rest.DebugMessage = e.Message;
                        rest.Code         = ExecCode.ExecFailed;
                        rest.Message      = "执行解析逻辑异常";
                    }
                }
                else
                {
                    rest.Code    = ExecCode.NotFoundAction;
                    rest.Message = "Action 对应的 Type 未注册";
                }
            }
            else if (types.Count > 1)
            {
                rest.Code    = ExecCode.MapManyTypes;
                rest.Message = "Action 对应了多个 Types";
            }
            else
            {
                rest.Code    = ExecCode.NotFoundType;
                rest.Message = "Action 未对应 Type";
            }
            return(rest);
        }