Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// AddItemToByteCommandMap
        /// </summary>
        /// <param name="key">int</param>
        /// <param name="command">CmdHandlerByte</param>
        public static void AddItemToByteCommandMap(int key, CmdHandlerByte command)
        {
            GlobalDefinition.LoggerWrapper.LogTraceInfo("public static void AddItemToByteCommandMap() start");
            if (null == CmdMapByte)
            {
                GlobalDefinition.LoggerWrapper.LogTraceInfo("CmdmapByte is  null");
                return;
            }

            if (!CmdMapByte.ContainsKey(key))
            {
                CmdMapByte.Add(key, command);
            }
            GlobalDefinition.LoggerWrapper.LogTraceInfo("public static void AddItemToByteCommandMap() end");
        }