public async Task SendMessage(string login, Message message, string roomName, string file) { await Groups.AddToGroupAsync(Context.ConnectionId, roomName); repos.Create(message); await Clients.Group(roomName).SendAsync("ReceiveMessage", login, message, file); }
public bool Create(Message _message) { _message.When = DateTime.Now; if (_msgDAO.Create(_message)) { return(true); } else { return(false); } }
public async Task <IActionResult> Create(CreateModel model) { Chat chat = repos1.GetOnGUID(model.Name); byte[] post = null; if (model.File != null) { using (var binaryReader = new BinaryReader(model.File.OpenReadStream())) { post = binaryReader.ReadBytes((int)model.File.Length); } } User user = repos.Get(Convert.ToInt32(model.Email)); Message message = new Message { Color = 0, ChatId = chat.Id, Text = model.Text, UserId = user.UserId }; if (this.User.FindFirstValue(ClaimTypes.Role) == "Admin") { message.Color = 1; } string login = user.UserName; if (model.File == null) { repos3.Create(message); } else { Document doc = new Document { GUID = Guid.NewGuid().ToString(), Name = model.File.FileName, Data = post }; repos3.CreateWithDoc(message, doc); } message.Doc = repos3.GetDoc(message.DocId); log.Info("Created new chat " + '\n' + "Chat name: " + chat.Name + '\n' + "Chat creator: " + model.Name); await hubContext.Clients.Group(chat.GUID).SendAsync("ReceiveMessage", login, message); return(RedirectToAction("Chat", "Chat", new { chat.GUID })); }
public PushResponse Process(PushRequest pRequest) { PushResponse response = new PushResponse(); response.ResultCode = 0; try { MessageChannelDAO channelDao = new MessageChannelDAO(new BasicUserInfo()); MessageDAO dao = new MessageDAO(new BasicUserInfo()); var entity = channelDao.GetByID(pRequest.ChannelID); if (entity == null) { throw new Exception(string.Format("未找到相应的ChannelID为:{0}的Channel信息", pRequest.ChannelID)); } MessageEntity mEntity = new MessageEntity(); mEntity.MessageID = Guid.NewGuid(); mEntity.ClientID = pRequest.ClientID; mEntity.ChannelID = pRequest.ChannelID; mEntity.AppCode = pRequest.AppCode; mEntity.UserID = pRequest.UserID; var request = pRequest.Request.DeserializeJSONTo <PushMsgRequest>(); var messagetype = request.InnerDictionary["message_type"].ToString(); //判断消息类型0-消息,1-通知 switch (messagetype) { case "0": mEntity.MessageContent = request.InnerDictionary["messages"].ToString(); break; case "1": mEntity.MessageContent = request.InnerDictionary["messages"].ToJSON().DeserializeJSONTo <BaiduPushNotification>().Description; break; } mEntity.MessageParameters = pRequest.GetJson(); switch (pRequest.Type) { case 1: //直接发送 var result = BaiduCloudPush.PushMessage(entity.GetBaiDuChannel(), pRequest.Request.DeserializeJSONTo <PushMsgRequest>()); if (result.IsSuccess) { mEntity.SendCount = 1; mEntity.Status = 2; dao.Create(mEntity); Loggers.Debug(new DebugLogInfo() { Message = "【发送成功】:" + mEntity.MessageParameters }); } else { mEntity.Status = 1; mEntity.SendCount = 1; mEntity.FaultReason = result.ErrorMessage; dao.Create(mEntity); Loggers.Debug(new DebugLogInfo() { Message = "【发送失败】:" + mEntity.MessageParameters + Environment.NewLine + result.ErrorMessage }); throw new Exception("【发送失败】:" + result.ErrorMessage + Environment.NewLine + mEntity.MessageParameters); } break; case 2: //存放到数据库 mEntity.SendCount = 0; mEntity.Status = 0; dao.Create(mEntity); Loggers.Debug(new DebugLogInfo() { Message = "【保存数据库成功】:" + mEntity.MessageParameters }); break; default: throw new Exception("未定义的请求类型:" + pRequest.Type); } } catch (Exception ex) { response.ResultCode = 100; response.Message = ex.Message; Loggers.Exception(new ExceptionLogInfo(ex)); } return(response); }
public PushResponse Process(PushRequest pRequest) { PushResponse response = new PushResponse(); response.ResultCode = 0; try { MessageChannelDAO channelDao = new MessageChannelDAO(new BasicUserInfo()); MessageDAO dao = new MessageDAO(new BasicUserInfo()); var entity = channelDao.GetByID(pRequest.ChannelID); if (entity == null) { throw new Exception(string.Format("未找到相应的ChannelID为:{0}的Channel信息", pRequest.ChannelID)); } MessageEntity mEntity = new MessageEntity(); mEntity.MessageID = Guid.NewGuid(); mEntity.ClientID = pRequest.ClientID; mEntity.ChannelID = pRequest.ChannelID; mEntity.AppCode = pRequest.AppCode; mEntity.UserID = pRequest.UserID; var notification = pRequest.Request.DeserializeJSONTo <JdSoft.Apple.Apns.Notifications.Notification>(); mEntity.MessageParameters = pRequest.GetJson(); switch (pRequest.Type) { case 1: //直接发送 var IOSChannel = entity.GetIOSChannel(); var result = IOSNotificationService.CreateInstance(IOSChannel.SandBox ?? true, IOSChannel.P12, IOSChannel.P12PWD).SendNotification(notification); if (result) { mEntity.SendCount = 1; mEntity.Status = 2; dao.Create(mEntity); Loggers.Debug(new DebugLogInfo() { Message = "【发送到推送服务器成功】:" + mEntity.MessageParameters }); } else { mEntity.Status = 1; mEntity.SendCount = 1; mEntity.FaultReason = "发送到推送服务器失败"; dao.Create(mEntity); Loggers.Debug(new DebugLogInfo() { Message = "【发送到推送服务器失败】:" + mEntity.MessageParameters }); throw new Exception("【发送到推送服务器失败】"); } break; case 2: //存放到数据库 mEntity.SendCount = 0; mEntity.Status = 0; dao.Create(mEntity); Loggers.Debug(new DebugLogInfo() { Message = "【保存数据库成功】:" + mEntity.MessageParameters }); break; default: throw new Exception("未定义的请求类型:" + pRequest.Type); } } catch (Exception ex) { response.ResultCode = 100; response.Message = ex.Message; Loggers.Exception(new ExceptionLogInfo(ex)); } return(response); }
void bw_DoWork1(object sender, DoWorkEventArgs e) { while (true) { try { Loggers.Debug(new DebugLogInfo() { Message = "审批订单-查询数据库" }); MessageDAO mdao = new MessageDAO(new BasicUserInfo()); OrdersCheckingDAO dao = new OrdersCheckingDAO(new BasicUserInfo()); ClientUserDAO userDao = new ClientUserDAO(new BasicUserInfo()); MessageChannelDAO channelDao = new MessageChannelDAO(new BasicUserInfo()); var entitys = dao.GetValidOrdersChecking(); Loggers.Debug(new DebugLogInfo() { Message = "审批订单-找到" + entitys.Count() + "条数据" }); foreach (var item in entitys) { Dictionary <ClientUserEntity, string> messages; var userEntitys = userDao.GetValidUserByStatus0(item, out messages); foreach (var it in userEntitys) { if (!string.IsNullOrEmpty(it.PushChannel)) { PushChannel info = it.PushChannel.DeserializeJSONTo <PushChannel>(); var pRequest = PushMsgRequestBuilder.CreateUnicastNotificationRequest(info.BaiduUserID, info.BaiduChannelID, "订单审批通知", messages[it]); MessageEntity mEntity = new MessageEntity(); mEntity.MessageID = Guid.NewGuid(); mEntity.ChannelID = 1; mEntity.ClientID = it.ClientID.Value.ToString(); mEntity.UserID = it.ClientUserID.Value.ToString(); var request = pRequest; var messagetype = request.InnerDictionary["message_type"].ToString(); //判断消息类型0-消息,1-通知 switch (messagetype) { case "0": mEntity.MessageContent = request.InnerDictionary["messages"].ToString(); break; case "1": mEntity.MessageContent = request.InnerDictionary["messages"].ToJSON().DeserializeJSONTo <BaiduPushNotification>().Description; break; } mEntity.MessageParameters = pRequest.InnerDictionary.ToJSON(); mEntity.SendCount = 0; mEntity.Status = 0; mdao.Create(mEntity); Loggers.Debug(new DebugLogInfo() { Message = "【保存数据库成功】:" + mEntity.MessageParameters }); item.SendStatus = 1; dao.Update(item); } else { Loggers.Debug(new DebugLogInfo() { Message = string.Format("用户{0}-{1}的PushChanel为空", it.ClientUserID, it.Username) }); } } } } catch (Exception ex) { Loggers.Exception(new ExceptionLogInfo(ex)); } Loggers.Debug(new DebugLogInfo() { Message = string.Format("审批订单-轮循结束,等待{0}秒", Interval) }); Thread.Sleep(TimeSpan.FromSeconds(Interval)); } }