private bool SendSignalRToast(Toast toast, ConnectedUser connectedUser, IHubContext context) { try { context.Clients.Client(connectedUser.Id).toastMessage(toast.Name, toast.Message); UpdateNotificationsBadgeNum(connectedUser, context); return true; } catch (Exception) { return false; } }
// // GET: /NotificationsAPI/ //[HttpPost] public void SendToast() { var toast = new Toast { Message = "", Name = "", UserId = "0da98ebd-dfa6-46f5-9123-d5a472f8dc47" }; using (var session=MasterStore.OpenSession()) { var context = GlobalHost.ConnectionManager.GetHubContext<NotificationHub>(); foreach (var conUser in session.Query<ConnectedUser>().Where(cu => cu.UserId == toast.UserId)) { context.Clients.Client(conUser.Id).toastMessage(toast.Name, toast.Message); UpdateNotificationsBadgeNum(conUser, context); } } }
public static void AddToastsToDB() { var toasts = new List<Toast>(); for (var i = 0; i < 100; i++) { var toast = new Toast { UserId = "user_293ebdcf-d47c-4e63-9c12-3fbb6603b644", Message = "hellohello message message" + i.ToString(), Id = i.ToString(), Name = "TestToast", CreatedDate = DateTime.Now }; // set user ID to mine as I'll be logging in... strangely i have the same user id as Andy, which I guess is why my name comes up as his. toasts.Add(toast); } var store2 = new DocumentStore { ConnectionStringName = "MasterDB" }; store2.Initialize(); //using (var session = MvcApplication.DataBase.MasterStore.OpenSession()) using(var session = store2.OpenSession()) { foreach (var toast in toasts) { session.Store(toast); } session.SaveChanges(); } }