public async Task <IActionResult> SendSignalR(ExSignalRNotificationData notification) { //PushNachricht versenden RestAccess ra = new RestAccess(Constants.ServiceClientEndPointWithApiPrefix); await ra.SignalRSendMessage(notification); return(RedirectToAction("Index", "Device")); }
/// <summary> /// View für das Senden der Pushnachricht /// </summary> /// <param name="id">ID des Gerätes</param> /// <returns>View</returns> public IActionResult SendSignalR(int id) { //Model erzeugen und ID anlegen ExSignalRNotificationData model = new ExSignalRNotificationData { UserId = id }; return(View(model)); }
public async Task <bool> SignalRSendMessage([FromBody] ExSignalRNotificationData notification) { //TODO: SignalRMessage versenden! ExNotificationData n = new ExNotificationData { Body = notification.Body, CustomData = notification.CustomData, Title = notification.Title }; if (notification.UserId <= 0) //Nachricht geht an alle Benutzer { foreach (var user in Clients) { foreach (var client in user.Value) { await HubContext.Clients.Client(client.ConnectionId).SendAsync("message", n); } } } else //Benutzer im Dict suchen und alle verbundenen Clients benachrichtigen { if (Clients.ContainsKey(notification.UserId)) { var clients = Clients[notification.UserId]; foreach (var client in clients) { await HubContext.Clients.Client(client.ConnectionId).SendAsync("message", n); } } else { return(false); } } return(true); }
/// <summary> /// Notifizierung an einen oder alle verbundenen Clients senden /// </summary> /// <param name="notification">Notifizierung</param> /// <returns>True wenn der Client noch verbunden ansonsten falsch </returns> public async Task <ResultData <bool?> > SignalRSendMessage(ExSignalRNotificationData notification) { return(await _wap.Post <bool?>("SignalRSendMessage", notification)); }