You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.8 KiB
102 lines
3.8 KiB
9 months ago
|
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<TBL_SYS_NOTICE> message;
|
||
|
TBL_SYS_NOTICE msg = new TBL_SYS_NOTICE();
|
||
|
public SendMessageBySignalR()
|
||
|
{
|
||
|
message = new SignalRMessage();
|
||
|
}
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// 发送站内短信
|
||
|
/// </summary>
|
||
|
/// <param name="userID">接收人员ID</param>
|
||
|
/// <param name="userName">接收人员姓名</param>
|
||
|
/// <param name="title">标题</param>
|
||
|
/// <param name="contents">内容</param>
|
||
|
/// <param name="msgType">类别0用户消息 1系统消息</param>
|
||
|
/// <param name="linkUrl">连接地址,点击消息的操作</param>
|
||
|
/// <param name="linkID">连接ID,用着特殊操作的标识</param>
|
||
|
/// <param name="msgID">消息ID,用于提前需要预知ID的情况</param>
|
||
|
/*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 = "<a class=\"blue1\" href=\"" + linkUrl + "\">" + sm.Contents + "</a>";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
msgContents = sm.Contents;
|
||
|
}
|
||
|
SiganalR(userID, sm.ID.ToString(), title, msgContents);
|
||
|
return sm.ID;
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
/// <summary>
|
||
|
/// 调用signalr向客户端发消息
|
||
|
/// </summary>
|
||
|
/// <param name="userID"></param>
|
||
|
/// <param name="id"></param>
|
||
|
/// <param name="title"></param>
|
||
|
/// <param name="contents"></param>
|
||
|
/// <param name="count"></param>
|
||
|
|
||
|
public static void SiganalR(string userID, string id, string title, string contents)
|
||
|
{
|
||
|
userID = "18609986119";
|
||
|
id = "ae033ad0-1343-4085-8bfc-839059088731";
|
||
|
title = "测试发送消息";
|
||
|
contents = "测试发送消息啊,这是正文啊";
|
||
|
Expression<Func<TBL_SYS_NOTICE, bool>> expression= PredicateExtensions.True<TBL_SYS_NOTICE>();
|
||
|
expression=(x=>x.Id==userID);
|
||
|
var contextHost = GlobalHost.ConnectionManager.GetConnectionContext<SignalRConnection>();
|
||
|
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());
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
}
|