public override int HandleCommand(CommandContext context, ISyncResult result)
 {
     try
     {
         SessionRequestCommand sRequestCommand = SessionRequestCommand.ParseFrom(context.sSerializeObject);
         if (!sRequestCommand.HasCommandId)
         {
             CLRLogger.GetInstance().LogDevError("commandID error.");
             result.SetSerializedString("commandID error.");
             return(-1);
         }
         byte[] invokeResult = _dicFunc[sRequestCommand.CommandId].Invoke(sRequestCommand);
         if (null == invokeResult)
         {
             return(-1);
         }
         result.SetSerializedObject(invokeResult);
         return(0);
     }
     catch (Exception ex)
     {
         CLRLogger.GetInstance().LogDevError("HandleCommand error:" + ex.Message);
         return(-1);
     }
 }
Example #2
0
        override /// <summary>
        /// HandleCommand
        /// </summary>
        /// <param name="pContext">CommandContext</param>
        /// <param name="pSyncResult">ISyncResult</param>
        /// <returns>int</returns>
        public int HandleCommand(CommandContext pContext, ISyncResult pSyncResult)
        {
            var guid = Guid.NewGuid().ToString();

            string commandId = pContext != null?pContext.iCommandId.ToString() : string.Empty;

            GlobalDefinition.LoggerWrapper.LogDevInfo("####################Receive Command.#######################" +
                                                      guid + "########commandid:" + commandId);

            if (null == pContext || null == pSyncResult)
            {
                GlobalDefinition.LoggerWrapper.LogDevInfo(
                    "####################processed Command.#######################" + guid + "########commandid:" +
                    commandId);
                GlobalDefinition.LoggerWrapper.LogDevError("ICLRCommandHandler's param is null.");
                return(0);
            }

            if (null == CmdMap || null == CmdMapByte)
            {
                GlobalDefinition.LoggerWrapper.LogDevInfo(
                    "####################processed Command.#######################" + guid + "########commandid:" +
                    commandId);
                GlobalDefinition.LoggerWrapper.LogDevError("Not initialize the CmdMap");
                return(0);
            }

            if (CmdMap.ContainsKey(pContext.iCommandId))
            {
                string result = CmdMap[pContext.iCommandId](pContext);

                pSyncResult.SetSerializedString(result);
            }
            else if (CmdMapByte.ContainsKey(pContext.iCommandId))
            {
                byte[] result = CmdMapByte[pContext.iCommandId](pContext);

                pSyncResult.SetSerializedObject(result);
            }
            else
            {
                GlobalDefinition.LoggerWrapper.LogDevInfo(
                    "####################processed Command.#######################" + guid + "########commandid:" +
                    commandId);
                GlobalDefinition.LoggerWrapper.LogDevError("Not process this command id: " +
                                                           pContext.iCommandId.ToString());
                return(0);
            }

            GlobalDefinition.LoggerWrapper.LogDevInfo(pSyncResult.GetSerializedString());

            GlobalDefinition.LoggerWrapper.LogDevInfo("####################processed Command.#######################" +
                                                      guid + "########commandid:" + commandId);
            return(0);
        }