public void HandleMessage(RemoteEnterCode message) { if (this.IsDisposed || this.Disposing) { return; } Invoke(new MethodInvoker(() => { if (message.Guid != this.Guid) { return; } Mediator.ShowMsg(string.Format("远程机器{0}加入了远程听诊", message.SrcMac)); if (this.isSender && message.SrcMac != Setting.authorizationInfo.MachineCode) { foreach (var mac in this.DgvTable.Select().Select(r => r["MAC"] + "").ToArray().Distinct()) { var code = new RemoteEnterCode() { Guid = message.Guid, SrcMac = Setting.authorizationInfo.MachineCode, DestMac = mac }; var _bytes = ProtocalData.Utilities.SerializaHelper.Serialize(code); Mediator.SuperSocket.Send(_bytes); } } else { string sql = @"select b.StetName,b.MAC,b.PCName,b.StetChineseName,b.Owner from RemoteAuscultateList a left join StethoscopeManager b on a.Acceptor=b.StetName and a.MAC=b.MAC where a.SrcGUID={0} and a.isAccept=1 and isExit=0"; using (OperationContextScope scope = new OperationContextScope(Mediator.remoteService.InnerChannel)) { MessageHeader header = MessageHeader.CreateHeader("SN", "http://tempuri.org", Setting.authorizationInfo.AuthorizationNum); OperationContext.Current.OutgoingMessageHeaders.Add(header); header = MessageHeader.CreateHeader("MAC", "http://tempuri.org", Setting.authorizationInfo.MachineCode); OperationContext.Current.OutgoingMessageHeaders.Add(header); var ds = Mediator.remoteService.ExecuteDataset(sql, new string[] { this.Guid }); dgvRemote.Rows.Clear(); foreach (DataRow row in ds.Tables[0].Rows) { dgvRemote.Rows.Add(row["StetChineseName"], row["StetName"], row["PCName"], row["MAC"], row["Owner"], true); } } } })); }
/// <summary> /// 接收到请求远程邀请 /// </summary> /// <param name="message"></param> public void HandleMessage(RequestRemoteAuscultateCode message) { Invoke(new MethodInvoker(() => { Mediator.WriteLog(this.Name, string.Format("处理来自{0}的听诊器{1}处理远程邀请请求...", message.SrcMac, message.SrcStetName)); //非本机,接收到远程请求,但本机有其他设备在使用中,自动拒绝 if (message.SrcMac != Setting.authorizationInfo.MachineCode && Mediator.isBusy) { var msg = string.Format("设备忙,自动拒绝了{0}的{1}远程听诊请求...", message.SrcMac, message.SrcStetName); var _resRemoteAuscultateCode = new ResRemoteAuscultateCode() { Guid = message.Guid, SrcPCName = CommonUtil.GetMachineName(), SrcMac = Setting.authorizationInfo.MachineCode, DestMac = message.SrcMac, isAccept = false, Comment = msg }; var _bytes = ProtocalData.Utilities.SerializaHelper.Serialize(_resRemoteAuscultateCode); Mediator.SuperSocket.Send(_bytes); Mediator.ShowMsg(msg); using (OperationContextScope scope = new OperationContextScope(Mediator.remoteService.InnerChannel)) { MessageHeader header = MessageHeader.CreateHeader("SN", "http://tempuri.org", Setting.authorizationInfo.AuthorizationNum); OperationContext.Current.OutgoingMessageHeaders.Add(header); header = MessageHeader.CreateHeader("MAC", "http://tempuri.org", Setting.authorizationInfo.MachineCode); OperationContext.Current.OutgoingMessageHeaders.Add(header); foreach (var stetName in message.DestStetNames) { string sql = "update RemoteAuscultateList set Comment={0} where SrcGUID={1} and Acceptor={2}"; var count = Mediator.remoteService.ExecuteNonQuery(sql, new string[] { msg, message.Guid, stetName }); if (count < 0) { } } } return; } //本机 if (message.SrcMac == Setting.authorizationInfo.MachineCode) { var resRemoteAuscultateCode = new ResRemoteAuscultateCode() { Guid = message.Guid, SrcPCName = CommonUtil.GetMachineName(), SrcMac = Setting.authorizationInfo.MachineCode, DestMac = message.SrcMac, isAccept = true, Comment = "本机远程邀请自动接受..." }; var bytes = ProtocalData.Utilities.SerializaHelper.Serialize(resRemoteAuscultateCode); Mediator.SuperSocket.Send(bytes); using (OperationContextScope scope = new OperationContextScope(Mediator.remoteService.InnerChannel)) { MessageHeader header = MessageHeader.CreateHeader("SN", "http://tempuri.org", Setting.authorizationInfo.AuthorizationNum); OperationContext.Current.OutgoingMessageHeaders.Add(header); header = MessageHeader.CreateHeader("MAC", "http://tempuri.org", Setting.authorizationInfo.MachineCode); OperationContext.Current.OutgoingMessageHeaders.Add(header); foreach (var stetName in message.DestStetNames) { string sql = "update RemoteAuscultateList set isAccept=1,Comment={0} where SrcGUID={1} and Acceptor={2}"; var count = Mediator.remoteService.ExecuteNonQuery(sql, new string[] { "本机远程邀请自动接受...", message.Guid, stetName }); if (count < 0) { } } } return; } this.tabControlYDTZ.SelectedTab = tabYCTZ; var stetNames = string.Join(",", message.DestStetNames); if (!StethoscopeManager.StethoscopeList.Where(s => message.DestStetNames.Contains(s.Name) && s.IsConnected).Any()) { Mediator.ShowMsg(string.Format("来自{3}的听诊器{0} {1}邀请您远程听诊,邀请的听诊器{2},都处于未连接状态,自动拒绝!", message.SrcStetName, string.IsNullOrEmpty(message.SrcStetOwner) ? "" : ",(" + message.SrcStetOwner + ")", stetNames, message.SrcPCName)); var resRemoteAuscultateCode = new ResRemoteAuscultateCode() { Guid = message.Guid, SrcPCName = CommonUtil.GetMachineName(), SrcMac = Setting.authorizationInfo.MachineCode, DestMac = message.SrcMac, isAccept = false, Comment = "邀请的听诊器都处于未连接状态,自动拒绝..." }; var bytes = ProtocalData.Utilities.SerializaHelper.Serialize(resRemoteAuscultateCode); Mediator.SuperSocket.Send(bytes); using (OperationContextScope scope = new OperationContextScope(Mediator.remoteService.InnerChannel)) { MessageHeader header = MessageHeader.CreateHeader("SN", "http://tempuri.org", Setting.authorizationInfo.AuthorizationNum); OperationContext.Current.OutgoingMessageHeaders.Add(header); header = MessageHeader.CreateHeader("MAC", "http://tempuri.org", Setting.authorizationInfo.MachineCode); OperationContext.Current.OutgoingMessageHeaders.Add(header); foreach (var stetName in message.DestStetNames) { string sql = "update RemoteAuscultateList set isAccept=1,Comment={0} where SrcGUID={1} and Acceptor={2}"; var count = Mediator.remoteService.ExecuteNonQuery(sql, new string[] { "邀请的听诊器都处于未连接状态,自动拒绝...", message.Guid, stetName }); if (count < 0) { } } } return; } Mediator.ShowMsg(string.Format("来自{3}的听诊器{0} {1}邀请您远程听诊,邀请的听诊器有{2},是否接受?", message.SrcStetName, string.IsNullOrEmpty(message.SrcStetOwner) ? "" : ",(" + message.SrcStetOwner + ")", stetNames, message.SrcPCName)); //非本机,同意请求请求,但得知道当前远程回话是否还在 if (DialogResult.OK == MessageBox.Show(string.Format("来自{3}的听诊器{0} {1}邀请您远程听诊,邀请的听诊器有{2},是否接受?", message.SrcStetName, string.IsNullOrEmpty(message.SrcStetOwner) ? "" : ",(" + message.SrcStetOwner + ")", stetNames, message.SrcPCName) , "远程听诊提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)) { //1.同意远程请求,但得知道当前远程回话是否还在 using (OperationContextScope scope = new OperationContextScope(Mediator.remoteService.InnerChannel)) { MessageHeader header = MessageHeader.CreateHeader("SN", "http://tempuri.org", Setting.authorizationInfo.AuthorizationNum); OperationContext.Current.OutgoingMessageHeaders.Add(header); header = MessageHeader.CreateHeader("MAC", "http://tempuri.org", Setting.authorizationInfo.MachineCode); OperationContext.Current.OutgoingMessageHeaders.Add(header); string sql = "select Status from RemoteAuscultate where GUID={0}"; // Status默认为0 -就绪 1-进行中 2-结束 var status = int.Parse("" + Mediator.remoteService.ExecuteScalar(sql, new string[] { message.Guid })); if (status == 2) { var _msg = string.Format("此次远程听诊已经结束...远程听诊编号{0}", message.Guid); Mediator.ShowMsg(_msg); return; } else if (status == 1) { var _msg = string.Format("此次远程听诊正在进行中您来晚了...远程听诊编号{0}", message.Guid); Mediator.ShowMsg(_msg); return; // 已经开始 } } var msg = string.Format("{2}接受了{0}的{1}远程听诊请求...", message.SrcMac, message.SrcStetName, CommonUtil.GetMachineName()); var resRemoteAuscultateCode = new ResRemoteAuscultateCode() { Guid = message.Guid, SrcPCName = CommonUtil.GetMachineName(), SrcMac = Setting.authorizationInfo.MachineCode, DestMac = message.SrcMac, isAccept = true, Comment = msg //Mediator.isBusy ? string.Format("设备忙,拒绝了{0},{1}远程听诊请求...", message.SrcMac, message.SrcStetName): }; var bytes = ProtocalData.Utilities.SerializaHelper.Serialize(resRemoteAuscultateCode); Mediator.SuperSocket.Send(bytes); using (OperationContextScope scope = new OperationContextScope(Mediator.remoteService.InnerChannel)) { MessageHeader header = MessageHeader.CreateHeader("SN", "http://tempuri.org", Setting.authorizationInfo.AuthorizationNum); OperationContext.Current.OutgoingMessageHeaders.Add(header); header = MessageHeader.CreateHeader("MAC", "http://tempuri.org", Setting.authorizationInfo.MachineCode); OperationContext.Current.OutgoingMessageHeaders.Add(header); foreach (var stetName in message.DestStetNames) { var isAccept = StethoscopeManager.StethoscopeList.Where(s => s.Name == stetName && s.IsConnected).Any() ? "1" : "0"; string sql = "update RemoteAuscultateList set AcceptTime=getdate(), isAccept={3},Comment={0} where SrcGUID={1} and Acceptor={2}"; var count = Mediator.remoteService.ExecuteNonQuery(sql, new string[] { msg, message.Guid, stetName, isAccept }); if (count < 0) { } } } //2.实时更新听诊器连接状态 Mediator.StethcopeConnectChangedEvent += (name, b) => { if (message.DestStetNames.Contains(name)) { var code = new RefleshStatusCode() { SrcMac = Setting.authorizationInfo.MachineCode, SrcStetName = name, DestMac = message.SrcMac, isConnect = b }; var _bytes = ProtocalData.Utilities.SerializaHelper.Serialize(code); Mediator.SuperSocket.Send(_bytes); } }; Mediator.ShowMsg(string.Format("接受了{0}的{1}远程听诊请求...", message.SrcMac, message.SrcStetName)); //3.进入会议室 Thread thread = new Thread(() => { this.Invoke(new MethodInvoker(() => { var formAuscultation = new FrmAuscultation() { Sender = message.SrcStetName, Guid = message.Guid, isSender = false }; Mediator.isBusy = true; //发进入消息 { var code = new RemoteEnterCode() { Guid = message.Guid, SrcMac = Setting.authorizationInfo.MachineCode, DestMac = message.SrcMac }; var _bytes = ProtocalData.Utilities.SerializaHelper.Serialize(code); Mediator.SuperSocket.Send(_bytes); } formAuscultation.ShowDialog(); //写离开状态 using (OperationContextScope scope = new OperationContextScope(Mediator.remoteService.InnerChannel)) { MessageHeader header = MessageHeader.CreateHeader("SN", "http://tempuri.org", Setting.authorizationInfo.AuthorizationNum); OperationContext.Current.OutgoingMessageHeaders.Add(header); header = MessageHeader.CreateHeader("MAC", "http://tempuri.org", Setting.authorizationInfo.MachineCode); OperationContext.Current.OutgoingMessageHeaders.Add(header); foreach (var stetName in message.DestStetNames) { string sql = "update RemoteAuscultateList set ExitTime=getdate(), isExit=1,Comment={0} where SrcGUID={1} and Acceptor={2}"; var count = Mediator.remoteService.ExecuteNonQuery(sql, new string[] { msg, message.Guid, stetName }); if (count < 0) { } } } Mediator.ShowMsg(string.Format("远程听诊结束,编号{0}", message.Guid)); //发退出消息 Mediator.isBusy = false; foreach (var stetName in message.DestStetNames) { var code = new RemoteExitCode() { Guid = message.Guid, SrcMac = Setting.authorizationInfo.MachineCode, DestMac = message.SrcMac, ExitMac = Setting.authorizationInfo.MachineCode }; var _bytes = ProtocalData.Utilities.SerializaHelper.Serialize(code); Mediator.SuperSocket.Send(_bytes); } })); }); thread.Start(); } else { var msg = string.Format("主动拒绝了{0}的{1}远程听诊请求...", message.SrcMac, message.SrcStetName); var resRemoteAuscultateCode = new ResRemoteAuscultateCode() { Guid = message.Guid, SrcPCName = CommonUtil.GetMachineName(), SrcMac = Setting.authorizationInfo.MachineCode, DestMac = message.SrcMac, isAccept = false , Comment = msg //Mediator.isBusy ? string.Format("设备忙,拒绝了{0},{1}远程听诊请求...", message.SrcMac, message.SrcStetName): }; var bytes = ProtocalData.Utilities.SerializaHelper.Serialize(resRemoteAuscultateCode); Mediator.SuperSocket.Send(bytes); using (OperationContextScope scope = new OperationContextScope(Mediator.remoteService.InnerChannel)) { MessageHeader header = MessageHeader.CreateHeader("SN", "http://tempuri.org", Setting.authorizationInfo.AuthorizationNum); OperationContext.Current.OutgoingMessageHeaders.Add(header); header = MessageHeader.CreateHeader("MAC", "http://tempuri.org", Setting.authorizationInfo.MachineCode); OperationContext.Current.OutgoingMessageHeaders.Add(header); foreach (var stetName in message.DestStetNames) { string sql = "update RemoteAuscultateList set Comment={0} where SrcGUID={1} and Acceptor={2}"; var count = Mediator.remoteService.ExecuteNonQuery(sql, new string[] { msg, message.Guid, stetName }); if (count < 0) { } } } } })); }