Push Notifications in SignalR from multiple Databa

2019-08-14 08:04发布

I am relatively new to SignalR, What I have done so far are example chat applications on it to get started.

We have a project that includes multiple databases, it's a machine data collection app. I have created a web control in ASP.NET MVC to view data of multiple machines at one place.

We have multiple users and they can access machines related to their projects. The current solution have a jQuery observer on the mvc page which refreshes the machine controls in a specific time.

I am thinking of making it a Push Notification solution. But as I am a beginner on SignalR I don't know how to approach this.

The goal is to notify the user of changes in data for machines that the user has access to (Not all machines).

Also how can I send messages from a database server to SignalR notifying of changes in the data?

I need some guidance getting started on this.

1条回答
Animai°情兽
2楼-- · 2019-08-14 08:36

SignalR Send method allows you to send data to user! It may use push, frame, server events or websocket techniques. You developer don't care about the technique! It depends on server and client handshake.

What you really need is to retrieve data from your databases and then to users, without worries

 // Server side: 
protected override Task OnConnected(IRequest request,  
                                 string connectionId) 
{ 
    var db = new allEntities();
    var db2 =new allEntities2();
    var data1 = db.Tables.Where(e=>e.LastUpdate<=datetime.now.AddDays(-1));
    var data2=db2.Tables.Where(e=>e.Something==someRef);
    var data=combine(data1,data2);//combine logic goes here
    return Connection.Send(connectionId, data.ToList()); 
}
查看更多
登录 后发表回答