public void AddNewNotification(object state) { var newId = Id++; var newNotification = new Notification { Id = newId, Title = "New Message Notification...", Description = "Some random mesage, bla bla bla", Importance = Importance.High, TimeCreated = DateTime.Now.ToShortTimeString() }; _notifications.TryAdd(newId, newNotification); BroadcastNewNotification(newNotification); }
public void AddNewNotifications() { while (true) { try { var brokerdMessage = QueueManager.ReceiveMessage(); if (brokerdMessage == null) { //no more messages in the queue break; } else { var message = new Notification { Id = Convert.ToInt32(brokerdMessage.MessageId), Title = brokerdMessage.GetBody<string>().Take(10).ToString(), Description = brokerdMessage.GetBody<string>(), Importance = Importance.High, TimeCreated = DateTime.Now.ToString() }; BroadcastNewNotification(message); brokerdMessage.Complete(); } } catch (MessagingException e) { if (!e.IsTransient) { Trace.WriteLine(e.Message); throw; } else { QueueManager.HandleTransientErrors(e); } } } QueueManager.queueClient.Close(); }
private void BroadcastNewNotification(Notification notification) { GetClients().addNotification(notification); }
private void LoadNotifications() { var notificationList = new List<Notification>(); while (true) { try { var brokerdMessage = QueueManager.ReceiveMessage(); if (brokerdMessage == null) { //no more messages in the queue break; } else { var message = new Notification { Id = Convert.ToInt32(brokerdMessage.MessageId), Title = brokerdMessage.GetBody<string>().Take(10).ToString(), Description = brokerdMessage.GetBody<string>(), Importance = Importance.High, TimeCreated = DateTime.Now.ToString() }; notificationList.Add(message); notificationList.ForEach(notification => _notifications.TryAdd(notification.Id, notification)); brokerdMessage.Complete(); } } catch (MessagingException e) { if (!e.IsTransient) { Trace.WriteLine(e.Message); throw; } else { QueueManager.HandleTransientErrors(e); } } } QueueManager.queueClient.Close(); }