I\'m trying to improve my application which will require calling a hub from C# instead of javascript. The current workflow for adding a task in my app is:
I am using the method explained in this answer.
public class NewsFeedHub : Hub
{
private static IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext();
// Call this from JS: hub.client.send(channel, content)
public void Send(string groupName, string content)
{
Clients.Group(groupName).addMessage(content);
}
// Call this from C#: NewsFeedHub.Static_Send(groupName, content)
public static void Static_Send(string groupName, string content)
{
hubContext.Clients.Group(groupName).addMessage(content);
}
}
The hub defines and uses its hubContext, so you can do:
var newsFeedHub = new NewsFeedHub();
var newsFeedHub.Static_Send("ch1", "HELLO");
Or:
var taskHub = new TaskHub();
var taskHub.InsertTask(task);
If you prefer that, based on your method naming.