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); }
public string SyncSendCommand(int cmdID, string receiver, string content, uint waitTime = 0, byte[] contentAsBytes = null) { CommandContext cmdContext = new CommandContext(); cmdContext.iCommandId = cmdID; cmdContext.sReceiver = receiver; cmdContext.sStringObject = content; cmdContext.sSerializeObject = contentAsBytes; if (waitTime != 0) { cmdContext.iWaitTime = waitTime; } ISyncResult result = _communicationProxy.SyncSendCommand(cmdContext); if (result.GetCallResult() != NO_ERROR) { string msg = string.Format("{0} fails to send sync command with command id = {1}, errorCode = {2}, content = {3}", _communicationProxy.GetName(), cmdID, result.GetCallResult(), content); throw new CommunicationException(result.GetCallResult(), msg); } return(result.GetSerializedString()); }