public Task SendAllAsync(NotificationGetFullApiModel model) { try { _hubContext.Clients.All.SendAsync("HandleNotification", model); } catch (Exception ex) { Log.Current.Error(ex); } return(Task.FromResult("Success")); }
private void LogNotification(NotificationGetFullApiModel notification, HubUser user = null) { try { Log.Current.Message($@" ================ Push Notification log ================ User: {notification.ToUserId} Model type: {notification.NotificationDataType} Notification type: {notification.NotificationType} Connectioin ids: {JsonConvert.SerializeObject(user?.ConnectionIds)} ================ End of log ================ "); } catch (Exception) { } }
public Task SendAsync(NotificationGetFullApiModel model) { HubUser user; if (model == null) { throw new ArgumentNullException(nameof(model)); } try { user = _cache.GetUserByUserId(model.ToUserId); if (user == null) { return(Task.FromResult(1)); } foreach (string connection in user.ConnectionIds) { try { _hubContext.Clients.Client(connection).SendAsync("HandleNotification", model); } catch (NullReferenceException ex) { Log.Current.Error(ex); } } } catch (Exception er) { Log.Current.Error(er); } return(Task.FromResult("Success")); }