private bool SaveMsg(MessageModel m) { //这是表的Model,跟MessageModel不一样,MessageModel是自定义的消息结构 //if (MessagesBLL.Exist(m.id)) return true; MessagesModel tableMessages = new MessagesModel { id = m.id, uid = m.FromUid, to_uid = m.ToUid ?? "0", msg = m.Msg }; try { return(MessagesBLL.Add(tableMessages) > 0); } catch (MySqlException e) { if (e.Message.Contains("Duplicate entry")) { return(true); } } return(false); }
public string CheckNewMsg(string toUid) { if (!string.IsNullOrEmpty(toUid)) { return(MessagesBLL.CheckNewMsg(toUid)); } return("0"); }
public string ConfirmMsg(string msgids) { if (!string.IsNullOrEmpty(msgids)) { return(MessagesBLL.UpdateReadStateBatchByMsgIds(1, msgids).ToString()); } return("false"); }
private void GetMyMsg(string fromuid, string touid, UdpPacketArrivedEventArgs e) { var dtMsg = MessagesBLL.GetMessages(fromuid, touid); if (dtMsg != null && dtMsg.Rows.Count > 0) { var jsonMsg = JsonConvert.SerializeObject(dtMsg); mUdpServer.Post(Encoding.UTF8.GetBytes(jsonMsg), e.RemoteEndPoint); } }
public string GetNewMsg(string toUid) { if (!string.IsNullOrEmpty(toUid)) { var dt = MessagesBLL.GetNewMsg(toUid); if (dt != null && dt.Rows.Count > 0) { return(Newtonsoft.Json.JsonConvert.SerializeObject(dt)); } } return(""); }
public Resolver() { GetLogger = new ComLogger(); daoUsers = new UsersDAL(GetLogger); daoFriends = new FriendsDAL(GetLogger); daoMessages = new MessagesDAL(GetLogger); daoSecurityData = new SecurityDataDAL(GetLogger); GetBloUsers = new UsersBLL(GetLogger, daoUsers); GetBloFriends = new FriendsBLL(GetLogger, daoFriends); GetBloMessages = new MessagesBLL(GetLogger, daoMessages); GetBloSecurityData = new SecurityDataBLL(GetLogger, daoSecurityData); }
public PersonalSender() { var sendThread = new Thread(() => { var i = 0; while (true) { i++; //每循环一千次暂停2秒,避免CPU使用过高 if (GetMessageCount() <= 0 || i % 1000 == 0) { Thread.Sleep(2000); i = 1; } if (GetMessageCount() <= 0) { continue; } var msg = MessageQueue.msgQueuePersonal.Dequeue(); try { var model = JsonConvert.DeserializeObject <MessageModel>(msg); var toUser = CacheManage.UserCache.GetUser(model.ToUid); if (toUser != null) { if (!SendMessage(msg, toUser)) { MessagesBLL.UpdateReadState(0, model.id); } } else { MessagesBLL.UpdateReadState(0, model.id); Console.WriteLine("to user is null"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }); sendThread.Start(); }
private void SendMsg(MessageModel m) { if (m.ToUid != null && m.ToUid != "") { UserInfoModel userInfoModel = UserInfoBLL.GetModel(int.Parse(m.ToUid)); if (userInfoModel != null && !string.IsNullOrEmpty(userInfoModel.udpip) && !string.IsNullOrEmpty(userInfoModel.udp_port)) { //如果客户端的通信端口信息已经超过30分钟不更新了则不再发送消息,因为超过30分钟理论上已经关闭了 var timeDiff = (DateTime.Now - userInfoModel.create_date.Value).TotalMinutes; if (timeDiff <= 30) { var dtMsg = MessagesBLL.GetMessages(m.ToUid, m.FromUid); if (dtMsg != null && dtMsg.Rows.Count > 0) { var jsonMsg = JsonConvert.SerializeObject(dtMsg); var ipEndPoint = new IPEndPoint(IPAddress.Parse(userInfoModel.udpip), int.Parse(userInfoModel.udp_port)); mUdpServer.Post(Encoding.UTF8.GetBytes(jsonMsg), ipEndPoint); } } } } }