//SynSendRequest private void button7_Click(object sender, EventArgs e) { ParamPackage packageSended = PackMessage(); ClientDevice targetClient = null; foreach (ClientDevice item in clientDeviceList) { if (item.Detail == comboBox12.SelectedItem.ToString()) { targetClient = item; } } string commuicateName = this.comboBox9.SelectedItem.ToString(); RequestCommunicatePackage requestCommunicatePackage = localDevice.CreateRequestCommunicatePackage(commuicateName, (CommunicatType)comboBox11.SelectedItem, packageSended, targetClient, checkBox1.Checked, asynReponseHandler); try { localDevice.SynSendRequest(requestCommunicatePackage, int.Parse(this.textBox4.Text)); } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); } ReplyPackage replyPkg = requestCommunicatePackage.ResponsePackage; if (null != replyPkg) { //List<string> list = replyPkg.Values<string>("value"); string replyString = replyPkg.ReplyState.ToString(); Console.WriteLine(replyString.ToString()); } }
protected void CoSynSendRequest(RequestCommunicatePackage communicator, int timeMillionsecond) { if (communicator.WaitResponse) { RequestPackage reqtPkg = new RequestPackage(_selfDevice, communicator.CommunicationName, communicator.WaitResponse, communicator.ParamPackage.ParamDefalutValues); C2CRequestPackage c2cReqtPkg = new C2CRequestPackage(_selfDevice, "outside message sent", communicator.WaitResponse, null); c2cReqtPkg.OutSideMessage = reqtPkg; RequestMTPackage mtReqtPkg = new RequestMTPackage(c2cReqtPkg, _selfDevice, communicator.TargetDevice, c2cReqtPkg.WaittingResponse); MiddlewareTransferPackage mtReplyBasePkg = null; //set param-time to wait this c2c response. mtReplyBasePkg = _middlewareCommunicateProcessor.SynSendMessage(mtReqtPkg, timeMillionsecond); if (null != (mtReplyBasePkg as ReplyMTPackage)) { ReplyMTPackage mtReplyPkg = mtReplyBasePkg as ReplyMTPackage; C2CReplyPackage c2cReplyPkg = mtReplyPkg.C2CReplyPackage; if ((null != c2cReplyPkg) && (null != c2cReplyPkg.OutSideMessage)) { ReplyPackage outsideReplyPkg = c2cReplyPkg.OutSideMessage; communicator.ResponsePackage = outsideReplyPkg; } else { throw new ArgumentNullException("应答报文C2CReplyPackage/C2CReplyPackage.OutSideMessage字段空"); } } else { throw new NotImplementedException("暂不支持打回RequestMTPackage类型"); } } else { throw new MiddlewareCommunicatErrorExcetion("同步调用而不请求应答是一个错误"); } }
protected RequestCommunicatePackage CoCreateRequestCommunicatePackage(string communicationName, CommunicatType communicateType, ParamPackage reqtParamPkg, ClientDevice targetDevice, bool waitResponse, AsynReponseHandler callback) { RequestCommunicatePackage reqtPkg = new RequestCommunicatePackage(); reqtPkg.CommunicationName = communicationName; reqtPkg.CommunicateType = communicateType; reqtPkg.ParamPackage = reqtParamPkg; reqtPkg.TargetDevice = targetDevice; reqtPkg.WaitResponse = waitResponse; reqtPkg.AsynchronousReponseCame = callback; return(reqtPkg); }
//AsynSendRequest private void button6_Click(object sender, EventArgs e) { ParamPackage packageSended = PackMessage(); ClientDevice targetClient = null; foreach (ClientDevice item in clientDeviceList) { if (item.Detail == comboBox12.SelectedItem.ToString()) { targetClient = item; } } string radioOp = this.comboBox8.SelectedItem.ToString(); string commuicateName = this.comboBox9.SelectedItem.ToString(); RequestCommunicatePackage requestCommunicatePackage = localDevice.CreateRequestCommunicatePackage(commuicateName, (CommunicatType)comboBox11.SelectedItem, packageSended, targetClient, checkBox1.Checked, asynReponseHandler); localDevice.AsynSendRequest(requestCommunicatePackage); }
private void __CoAsynSendRequestRunning(RequestCommunicatePackage communicator) { RequestPackage reqtPkg = new RequestPackage(_selfDevice, communicator.CommunicationName, communicator.WaitResponse, communicator.ParamPackage.ParamDefalutValues); C2CRequestPackage c2cReqtPkg = new C2CRequestPackage(_selfDevice, "outside message sent", communicator.WaitResponse, null); c2cReqtPkg.OutSideMessage = reqtPkg; RequestMTPackage mtReqtPkg = new RequestMTPackage(c2cReqtPkg, _selfDevice, communicator.TargetDevice, c2cReqtPkg.WaittingResponse); if (communicator.WaitResponse) { MiddlewareTransferPackage mtReplyBasePkg = null; try { //100s limited time to wait this c2c response. mtReplyBasePkg = _middlewareCommunicateProcessor.SynSendMessage(mtReqtPkg, 10000); } catch (System.Exception ex) { //throw new MiddlewareCommunicatErrorExcetion(ex.ToString()); this.CoMiddleware2MiddlewareAsynReqtCommunicatErrorRecived_OutsideNotify(communicator, new MiddlewareCommunicatErrorExcetion(ex.ToString())); } if (null != (mtReplyBasePkg as ReplyMTPackage)) { ReplyMTPackage mtReplyPkg = mtReplyBasePkg as ReplyMTPackage; C2CReplyPackage c2cReplyPkg = mtReplyPkg.C2CReplyPackage; if ((null != c2cReplyPkg) && (null != c2cReplyPkg.OutSideMessage)) { ReplyPackage outsideReplyPkg = c2cReplyPkg.OutSideMessage; communicator.ResponsePackage = outsideReplyPkg; //asyn outside notify if (null != communicator.AsynchronousReponseCame) { communicator.AsynchronousReponseCame(communicator, new AsynReplyCommunicatePackage(outsideReplyPkg)); } } else { ArgumentNullException ex = new ArgumentNullException("应答报文C2CReplyPackage/C2CReplyPackage.OutSideMessage字段空"); this.CoMiddleware2MiddlewareAsynReqtCommunicatErrorRecived_OutsideNotify(communicator, new MiddlewareCommunicatErrorExcetion(ex.ToString())); } } else { NotImplementedException ex = new NotImplementedException("暂不支持打回RequestMTPackage类型"); this.CoMiddleware2MiddlewareAsynReqtCommunicatErrorRecived_OutsideNotify(communicator, new MiddlewareCommunicatErrorExcetion(ex.ToString())); } } else { try { _middlewareCommunicateProcessor.AsynSendMessage(mtReqtPkg); } catch (System.Exception ex) { //throw new MiddlewareCommunicatErrorExcetion(ex.ToString()); this.CoMiddleware2MiddlewareAsynReqtCommunicatErrorRecived_OutsideNotify(communicator, new MiddlewareCommunicatErrorExcetion(ex.ToString())); } } }
protected void CoAsynSendRequest(RequestCommunicatePackage communicator) { _asynSendRequestRunner.EnqueueMessage(communicator); }
/// <summary> /// 阻塞式发起一次远程请求 /// </summary> /// <param name="communicator">请求通讯包</param> /// <param name="timeMillionsecond">等待的上限时长</param> public void SynSendRequest(RequestCommunicatePackage communicator, int timeMillionsecond) { base.CoSynSendRequest(communicator, timeMillionsecond); }
/// <summary> /// 非阻塞式发起一次远程请求 /// </summary> /// <param name="communicator">请求通讯包</param> public void AsynSendRequest(RequestCommunicatePackage communicator) { base.CoAsynSendRequest(communicator); }