我正在使用signaIR发送聊天消息,以下是我的集线器代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using System.Threading.Tasks;
namespace MvcApplication1.Hubs
{
public class WorkflowHub : Hub
{
/// <summary>
/// static userlist
/// </summary>
private IList<string> userList = UserInfo.userList;
/// <summary>
/// user connectionID and username
/// </summary>
private readonly static Dictionary<string, string> _connections = new Dictionary<string, string>();
public void SendByGroup(string name1, string name2)
{
Clients.Client(_connections[name2]).SendMessage("from"+name1 + " " + DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"));
}
/// <summary>
/// user online method
/// </summary>
/// <param name="name"></param>
public void SendLogin(string name)
{
if (!userList.Contains(name))
{
userList.Add(name);
//bind username and ConnectionId
_connections.Add(name, Context.ConnectionId);
}
else
{
//becauser every time to login,the connectionId will change,so bind it again.
_connections[name] = Context.ConnectionId;
}
//new user loign ,will send a notic to all user.
Clients.All.loginUser(userList);
Clients.All.NewUserLogin(name);
}
public override Task OnConnected()
{
Clients.Client(Context.ConnectionId).ConnectedMessage("Welcome");
return base.OnConnected();
}
public override Task OnDisconnected(bool stopCalled)
{
return base.OnDisconnected(stopCalled);
}
public override Task OnReconnected()
{
return base.OnReconnected();
}
}
}
我有一个MVC控制器接收来自其他帖子的消息,以下是我的控制器我希望代码在这里连接我的signaIR集线器,然后将此requestMessage发送到我的其他平台,如移动APP或网站,我不知道。如何连接到集线器类或signIR集线器服务器,谁都可以帮助我?!!! THX。
public class WeChatController : Controller
{
public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage)
{
//I want code here to connect my signaIR hub ,then send this requestMessage to my other platform,like mobile APP or website,I don't know .how to connect to the hub class or signIR hub server ,anyone can help me?!!! Thx.
}
}