using LitJson; using Microsoft.AspNet.SignalR; using Platform.Infrastructure.SignalRLayer.Entity; using Platform.Infrastructure.SignalRLayer.Service; using Platform.Infrastructure.SignalRLayer.SignalR; using System; using System.Linq.Expressions; namespace Platform.Infrastructure { public class SendMessageBySignalR { ISignalRMessage message; TBL_SYS_NOTICE msg = new TBL_SYS_NOTICE(); public SendMessageBySignalR() { message = new SignalRMessage(); } /// /// 发送站内短信 /// /// 接收人员ID /// 接收人员姓名 /// 标题 /// 内容 /// 类别0用户消息 1系统消息 /// 连接地址,点击消息的操作 /// 连接ID,用着特殊操作的标识 /// 消息ID,用于提前需要预知ID的情况 /*public static Guid Send(string userID, string userName, string title, string contents, int msgType = 0, string linkUrl = "", string linkID = "", string msgID = "") { if (String.IsNullOrWhiteSpace(userID) || String.IsNullOrWhiteSpace(title) || string.IsNullOrWhiteSpace(contents)) { return Guid.Empty; } if (String.IsNullOrWhiteSpace(userName)) { userName = new Users().GetName(userID); } Data.Model.ShortMessage sm = new Data.Model.ShortMessage(); sm.Contents = contents; sm.ID = msgID.IsGuid() ? msgID.ToGuid() : Guid.NewGuid(); sm.LinkID = linkID; sm.LinkUrl = linkUrl; sm.ReceiveUserID = userID; sm.ReceiveUserName = userName; sm.SendTime = RoadFlow.Utility.DateTimeNew.Now; sm.SendUserID = Users.CurrentUserID; sm.SendUserName = Users.CurrentUserName; sm.Status = 0; sm.Title = title; sm.Type = msgType; new ShortMessage().Add(sm); string msgContents = string.Empty; if (!linkUrl.IsNullOrEmpty()) { msgContents = "" + sm.Contents + ""; } else { msgContents = sm.Contents; } SiganalR(userID, sm.ID.ToString(), title, msgContents); return sm.ID; } */ /// /// 调用signalr向客户端发消息 /// /// /// /// /// /// public static void SiganalR(string userID, string id, string title, string contents) { userID = "18609986119"; id = "ae033ad0-1343-4085-8bfc-839059088731"; title = "测试发送消息"; contents = "测试发送消息啊,这是正文啊"; Expression> expression= PredicateExtensions.True(); expression=(x=>x.Id==userID); var contextHost = GlobalHost.ConnectionManager.GetConnectionContext(); JsonData jd = new JsonData(); jd["id"] = id; jd["title"] = title; jd["contents"] = contents; //jd["count"] = new SignalRMessage().GetAllByCondition(expression).Count; jd["count"] = 1258; contextHost.Groups.Send(userID.ToString().ToLower(), jd.ToJson()); } } }