// 调度过来的命令 public void ReceiveCommand(RequestCommand command) { // TraceManagerForOPC.AppendInfo("PUMP-OPC子服务当前任务条目数:"+ this.queue.Count.ToString()); //写值操作 if (command.sonServerType == CommandServerType.Pump_OPC && command.operType == CommandOperType.Write) { TakeOutCollectCommand(); this.Append(PumpCommand.CreateWriteCommand(this.opcClientManager, command)); //命令记录 TraceManagerForCommand.AppendDebug(string.Format("命令ID:{0}开始执行JZID:{1},业务地址{2},设定值{3}操作", command.ID, command.jzID, command.fDBAddress, command.value)); return; } // OPC_Pump--重载请求 if (command.sonServerType == CommandServerType.Pump_OPC && command.operType == CommandOperType.ReLoadData) { TakeOutCollectCommand(); this.Append(PumpCommand.CreateReloadCommand(this.opcClientManager, command)); //命令记录 TraceManagerForCommand.AppendDebug(string.Format("命令ID:{0}开始执行PUMP-OPC重载机组数据操作:", command.ID)); return; } // 错误请求 CommandManager.MakeFail("错误的请求类型", ref command); CommandManager.CompleteCommand(command); TraceManagerForCommand.AppendErrMsg(command.message); return; }
/// <summary> /// 命令消费 /// </summary> /// <param name="reciveData"></param> private void Excute(ReciveData reciveData) { //将接受到数据反序列化成命令对象 RequestCommand request; try { request = ByteUtil.ToDeserializeObject<RequestCommand>(reciveData.data.body); } catch (Exception e) { ResponseCommand response = new ResponseCommand() { errMsg = "序列化请求对象失败," + e.Message + "堆栈:" + e.StackTrace, statusCode = "440", info = "" }; string data = ByteUtil.ToSerializeObject(response); reciveData.FinshCallBack(reciveData.sessionID, data,true); TraceManagerForCommand.AppendErrMsg(response.errMsg); return; } // 序列化检查 if (request == null) { ResponseCommand response = new ResponseCommand() { errMsg = "序列化请求对象失败,", statusCode = "440", info = "" }; string data = ByteUtil.ToSerializeObject(response); reciveData.FinshCallBack(reciveData.sessionID, data, true); TraceManagerForCommand.AppendErrMsg(response.errMsg); return; } // 将委托和会话ID传递给命令对象 request.FinshCallBack = reciveData.FinshCallBack; request.sessionID = reciveData.sessionID; //命令记录 TraceManagerForCommand.AppendDebug("已获取命令ID:"+ request.ID); // 让调度开始分发给对应的子服务 this.DoRequestCommand(request); }