private void btnSave_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(txtNoticeContext.Text)) { string id = ExtendApplicationContext.Current.LoginUser.USER_JOB_ID + " " + accountRepository.GetServerTime().Data.Ticks; MED_SCREEN_MSG msg = new MED_SCREEN_MSG(); msg.ID = id; msg.MSG = lbMsg.Text; msg.INSERT_TIME = accountRepository.GetServerTime().Data; msg.COUNTS = int.Parse(numUDNoticeTime.Value.ToString()); msg.STATUS = 1; msg.USER_ID = "紧急公告"; msg.TYPE = 2; msg.DEPT_CODE = ExtendApplicationContext.Current.OperRoom; commonRepository.SaveScreenMsg(msg); string msgStr = msg.ID + "@" + msg.MSG + "@" + msg.COUNTS; TransMessageModel tempTransMsgModel = new TransMessageModel(EnumAppType.Screen, EnumMessageType.Broadcase, EnumFunctionType.OperationScreen, msgStr ); TransMessageManager.Instance.SendMsg(tempTransMsgModel); } ShowMsgGrid(); }
/// <summary> /// 获取服务端主动推送消息,同时弹出消息对话框 /// </summary> public void DelegateSendMessage(string sendConnectionId, string sendName, string message) { try { LoginModel tar = JsonConvert.DeserializeObject <LoginModel>(sendName); if (null == tar || (tar.SessionID.Equals(this.curLoginModel.SessionID))) { return; } // 反序列化消息体 TransMessageModel curTransMsgModel = JsonConvert.DeserializeObject <TransMessageModel>(message); if (null != curTransMsgModel) { switch (curTransMsgModel.CurEnumFunctionType) { // 聊天记录 case EnumFunctionType.OperationScreen: this.SendClientMessage(curTransMsgModel.MessageContent); break; } } } catch (Exception ex) { Logger.Error("接收消息异常", ex); } }
/// <summary> /// 聊天记录处理 /// </summary> private void MessageCommunicatioin(TransMessageModel curTransMsgModel) { try { if (DateTime.MinValue == curTransMsgModel.ReceiveDateTime) { curTransMsgModel.ReceiveDateTime = accountRepository.GetServerTime().Data; } // 把消息记录分派到对应的客户 LoginModel source = JsonConvert.DeserializeObject <LoginModel>(curTransMsgModel.SourceClientName); LoginModel target = JsonConvert.DeserializeObject <LoginModel>(curTransMsgModel.TargetClientName); // 自身是发送方,则接收方为主 if (source.SessionID.Equals(this.CurLoginModel.SessionID)) { foreach (ClientModel client in this.allClientModelList) { if (client.CurCoordinationLoginModel.SessionID.Equals(target.SessionID)) { curTransMsgModel.CurFlowDirection = FlowDirection.RightToLeft;//聊天图形方向 curTransMsgModel.HasRead = true; client.CurMsgRecordList.Add(curTransMsgModel); break; } } } else { if (this.childHasLogin) { // 接收到其他客户端消息 foreach (ClientModel client in this.allClientModelList) { if (client.CurCoordinationLoginModel.SessionID.Equals(source.SessionID)) { curTransMsgModel.CurFlowDirection = FlowDirection.LeftToRight;//聊天图形方向 client.CurMsgRecordList.Add(curTransMsgModel); // 转发给子一体机 // curTransMsgModel.HasRead = true; this.ForwardMsg(curTransMsgModel, JsonConvert.SerializeObject(this.ChildLoginModel)); break; } } } Messenger.Default.Send <bool>(true, EnumMessageKey.NewUnreadMessage); } curTransMsgModel.HasRead = this.childHasLogin; this.allMsgList.Add(curTransMsgModel); } catch (Exception ex) { Logger.Error("聊天记录处理异常", ex); } }
/// <summary> /// 转发消息 /// </summary> /// <param name="transMsgModel">消息体</param> /// <param name="targetName">转发消息的接收者</param> public void ForwardMsg(TransMessageModel transMsgModel, string targetName) { if (null != this.connection && this.connection.ConnectionStatus && null != transMsgModel) { if (transMsgModel.ReceiveDateTime == DateTime.MinValue) { transMsgModel.ReceiveDateTime = DateTime.Now; } this.connection.SendMessage(targetName, JsonConvert.SerializeObject(transMsgModel)); } }
/// <summary> /// 保存大屏呼叫的信息到数据库 /// </summary> private bool SaveOperationScreenMsgInfo() { bool result = true; List <MED_SCREEN_MSG> list = new List <MED_SCREEN_MSG>(); foreach (OperationCanceledTypeModel item in this.AllOperScreenTypeList) { if (item.IsChecked) { MED_SCREEN_MSG newRow = new MED_SCREEN_MSG(); newRow.ID = ExtendAppContext.Current.LoginUser.USER_JOB_ID + "_" + Guid.NewGuid().ToString(); newRow.MSG = string.Format("{0}患者家属请注意:{1}", this.CurPatientModel.Name, item.ItemName); newRow.INSERT_TIME = DateTime.Now; newRow.COUNTS = 3; newRow.STATUS = 1; newRow.USER_ID = "紧急公告"; newRow.TYPE = 2; newRow.DEPT_CODE = ExtendAppContext.Current.OperDeptCode; newRow.ModelStatus = ModelStatus.Add; list.Add(newRow); } } // 如果其他事项包含信息,则也写入列表 if (!this.strOtherMesInfo.Trim().Equals("\r\n") && !string.IsNullOrEmpty(this.strOtherMesInfo.Trim())) { MED_SCREEN_MSG newRow = new MED_SCREEN_MSG(); new Guid().ToString(); newRow.ID = ExtendAppContext.Current.LoginUser.USER_JOB_ID + "_" + Guid.NewGuid().ToString(); newRow.MSG = string.Format("{0}患者家属请注意:{1}", this.CurPatientModel.Name, this.strOtherMesInfo.Trim()); newRow.INSERT_TIME = DateTime.Now; newRow.COUNTS = 3; newRow.STATUS = 1; newRow.USER_ID = "紧急公告"; newRow.TYPE = 2; newRow.DEPT_CODE = ExtendAppContext.Current.OperDeptCode; newRow.ModelStatus = ModelStatus.Add; list.Add(newRow); } result = CommonService.ClientInstance.SaveOperationScreen(list); foreach (MED_SCREEN_MSG msg in list) { string msgStr = msg.ID + "@" + msg.MSG + "@" + msg.COUNTS; TransMessageModel tempTransMsgModel = new TransMessageModel(EnumAppType.Screen, EnumMessageType.Broadcase, EnumFunctionType.OperationScreen, msgStr ); TransMessageManager.Instance.SendMsg(tempTransMsgModel); } return(true); }
/// <summary> /// 转发消息 /// </summary> /// <param name="transMsgModel">消息体</param> /// <param name="targetName">转发消息的接收者</param> public void ForwardMsg(TransMessageModel transMsgModel, string targetName) { if (null != this.connection && this.connection.ConnectionStatus && null != transMsgModel) { if (DateTime.MinValue == transMsgModel.ReceiveDateTime) { transMsgModel.ReceiveDateTime = accountRepository.GetServerTime().Data; } this.connection.SendMessage(targetName, JsonConvert.SerializeObject(transMsgModel)); } }
/// <summary> /// 转发消息 /// </summary> /// <param name="transMsgModel">消息体</param> /// <param name="targetName">转发消息的接收者</param> public void ForwardMsg(TransMessageModel transMsgModel, string targetName) { if (null != this.connection && this.connection.ConnectionStatus && null != transMsgModel) { if (DateTime.MinValue == transMsgModel.ReceiveDateTime) { transMsgModel.ReceiveDateTime = CommonService.ClientInstance.GetServerTime(); } this.connection.SendMessage(targetName, JsonConvert.SerializeObject(transMsgModel)); } }
/// <summary> /// 发送消息 /// </summary> public void SendMsg(TransMessageModel transMsgModel) { if (null != this.connection && this.connection.ConnectionStatus && null != transMsgModel) { transMsgModel.SendDateTime = DateTime.Now; transMsgModel.SourceClientName = JsonConvert.SerializeObject(this.CurLoginModel); if (transMsgModel.CurEnumMessageType == EnumMessageType.Single) { this.connection.SendMessage(transMsgModel.TargetClientName, JsonConvert.SerializeObject(transMsgModel)); } else { this.connection.SendALLMessage(JsonConvert.SerializeObject(transMsgModel)); } } }
/// <summary> /// 获取服务端主动推送消息,同时弹出消息对话框 /// </summary> public void DelegateSendMessage(string sendConnectionId, string sendName, string message) { try { LoginModel tar = JsonConvert.DeserializeObject <LoginModel>(sendName); if (null == tar || (tar.SessionID.Equals(this.CurLoginModel.SessionID))) { return; } // 反序列化消息体 TransMessageModel curTransMsgModel = JsonConvert.DeserializeObject <TransMessageModel>(message); if (null != curTransMsgModel) { switch (curTransMsgModel.CurEnumFunctionType) { // 聊天记录 case EnumFunctionType.MessageCommunication: this.MessageCommunicatioin(curTransMsgModel); break; // 请求视频通讯 case EnumFunctionType.VideoRequest: Messenger.Default.Send <object>(this, EnumMessageKey.ResponseVideoComm); break; case EnumFunctionType.HasNewVersion: if (!string.IsNullOrEmpty(curTransMsgModel.MessageContent) && curTransMsgModel.MessageContent.Equals("PACU")) { About about = new About(); about.ShowDialog(); } break; } } } catch (Exception ex) { Logger.Error("接收消息异常", ex); } }
/// <summary> /// 获取服务端主动推送消息,同时弹出消息对话框 /// </summary> public void DelegateSendMessage(string sendConnectionId, string sendName, string message) { try { LoginModel tar = JsonConvert.DeserializeObject <LoginModel>(sendName); if (null == tar || (tar.SessionID.Equals(this.curLoginModel.SessionID))) { return; } // 反序列化消息体 TransMessageModel curTransMsgModel = JsonConvert.DeserializeObject <TransMessageModel>(message); if (null != curTransMsgModel) { switch (curTransMsgModel.CurEnumFunctionType) { // 聊天记录 case EnumFunctionType.MessageCommunication: this.MessageCommunicatioin(curTransMsgModel); break; // 请求视频通讯 case EnumFunctionType.VideoRequest: // Messenger.Default.Send<object>(this, EnumMessageKey.ResponseVideoComm); break; case EnumFunctionType.HasNewVersion: System.Windows.Forms.MessageBox.Show("有新版信息:" + curTransMsgModel.MessageContent); break; } } } catch (Exception ex) { Logger.Error("接收消息异常", ex); } }
public ActionResult Create(MED_VER_INFO verInfo, HttpPostedFileBase postFileBase) { DapperContext dapper = new DapperContext("docareConnString"); string erroMsg = string.Empty; try { //检测应用程序最大版本号,是否为测试版,如果为测试版又未回退,就不能发布新版 if (!string.IsNullOrEmpty(verInfo.APP_ID)) { MED_VER_INFO maxNoVerInfo = dapper.Set <MED_VER_INFO>().Select(x => x.APP_ID.Equals(verInfo.APP_ID)).OrderByDescending(x => x.VER_NO).FirstOrDefault(); if (maxNoVerInfo == null || maxNoVerInfo.IS_TEST != 1 || (maxNoVerInfo.IS_TEST == 1 && maxNoVerInfo.ROLL_BACK == 1)) { if (Request.Files.Count > 0) { MED_APP_INFO appInfo = dapper.Set <MED_APP_INFO>().Single(x => x.APP_ID.Equals(verInfo.APP_ID)); postFileBase = Request.Files[0]; //文件上传,一次上传1M的数据,防止出现大文件无法上传 uploadStream = postFileBase.InputStream; int bufferLen = 1024; byte[] buffer = new byte[bufferLen]; int contentLen = 0; string fileName = Path.GetFileName(postFileBase.FileName); //判断扩展名 string[] extens = new string[] { ".zip" }; if (Array.Exists(extens, p => p.ToUpper() == System.IO.Path.GetExtension(fileName).ToUpper())) { string baseUrl = Server.MapPath("/"); string uploadPath = "UpdateFile" + @"\" + appInfo.APP_KEY + @"\"; //创建文件夹 string[] folderFile = uploadPath.Split(new String[] { @"\" }, StringSplitOptions.RemoveEmptyEntries); String l = folderFile.LastOrDefault(); string cPath = baseUrl; foreach (var item in folderFile) { if (!item.Contains(":")) { cPath += @"\" + item; if (!Directory.Exists(cPath)) { Directory.CreateDirectory(cPath); } } } //保存文件 string newFilename = verInfo.VER_NO + Path.GetExtension(fileName); string newFilePath = baseUrl + @"\" + uploadPath + newFilename; fs = new FileStream(newFilePath, FileMode.Create, FileAccess.ReadWrite); while ((contentLen = uploadStream.Read(buffer, 0, bufferLen)) != 0) { fs.Write(buffer, 0, bufferLen); fs.Flush(); } fs.Close(); verInfo.FILE_PATH = uploadPath + newFilename; //保存数据 verInfo.VER_ID = Guid.NewGuid().ToString(); verInfo.CREATE_TIME = DateTime.Now; verInfo.ModelStatus = ModelStatus.Add; bool rest = dapper.Set <MED_VER_INFO>().Save(verInfo); dapper.SaveChanges(); MedicalSystem.Services.Logger.Info("上传完成"); if (!rest) { //删除文件 System.IO.File.Delete(newFilePath); erroMsg = "数据保存失败"; } else { MedicalSystem.Services.Logger.Info("发消息给客户端"); // 发布消息给客户端 MED_USERS user = new MED_USERS { LOGIN_NAME = "admin", USER_NAME = "admin", USER_JOB_ID = "admin", USER_JOB = "医生", USER_ROLE = "主任,管理员", isMDSD = true }; if (System.Web.HttpContext.Current.Application["admin"] == null) { try { MedicalSystem.Services.Logger.Info("消息平台连接"); TransMessageManager tmm = new TransMessageManager(user); tmm.OpenConnection(); System.Web.HttpContext.Current.Application["admin"] = tmm; MedicalSystem.Services.Logger.Info("消息平台连接成功"); // 设置消息体 TransMessageModel tm = new TransMessageModel() { TargetClientEnumAppType = EnumAppType.AnesWorkStation, CurEnumMessageType = EnumMessageType.Broadcase, CurEnumFunctionType = EnumFunctionType.HasNewVersion, SourceClientEnumAppType = EnumAppType.Platform, MessageContent = appInfo.APP_KEY }; MedicalSystem.Services.Logger.Info("发送消息"); tmm.SendMsg(tm); MedicalSystem.Services.Logger.Info("发送消息完"); } catch (Exception ex) { MedicalSystem.Services.Logger.Info("消息平台错误:" + ex.Message); } } } } else { erroMsg = "扩展名必须为zip"; } } else { erroMsg = "未选择要上传文件!"; } } else { erroMsg = "版本号" + maxNoVerInfo.VER_NO + "是测试版并没有回退版本!"; } } else { erroMsg = "没有选择应用程序!"; } if (!string.IsNullOrEmpty(erroMsg)) { return(Json(erroMsg, "text/html")); } else { return(Json(true, "text/html")); } } catch (Exception ex) { erroMsg = ex.Message; return(Json(erroMsg, "text/html")); } finally { if (System.Web.HttpContext.Current.Application["admin"] != null) { TransMessageManager tmm = System.Web.HttpContext.Current.Application["admin"] as TransMessageManager; tmm.CloseConnection(); System.Web.HttpContext.Current.Application.Remove("admin"); } } }