示例#1
0
        void startListeningToNotification(CancellationToken cancellationToken)
        {
            try
            {
                using (IChangeStreamCursor <ChangeStreamDocument <Notification> > cursor = _collection.Watch(_userLogin, cancellationToken))
                {
                    try
                    {
                        // might want to actually create an event inside the DAO
                        //   that way we are not depending on IChangeStreamCursor in the service
                        //    this might make unit tests much harder
                        //  Could also return cursor.ToEnumerable(cancellationToken) inside the DAO that way it simply returns IEnumerable<ChangeStreamDocument<Notification>>
                        //   ChangeStreamDocument<Notification> can easily be faked by creating a bson document
                        foreach (var notif in cursor.ToEnumerable(cancellationToken))
                        {
                            cancellationToken.ThrowIfCancellationRequested();
                            OnNewNotification?.Invoke(new NewNotificationEventArgs(
                                                          new NewNotificationDTO
                            {
                                Id      = notif.FullDocument.Id,
                                Message = notif.FullDocument.Message,
                                DtgUtc  = notif.FullDocument.EventDtgUtc,
                                Type    = notif.FullDocument.Type
                            }
                                                          ));
                        }
                    }
                    catch (OperationCanceledException ex)
                    {
                        Console.WriteLine("Operation was canceled");
                        throw ex;
                    }
                    catch (Exception ex)
                    {
                        notificationServiceErrorCount++;

                        if (notificationServiceErrorCount > 2)
                        {
                            throw ex;
                        }
                    }
                }
            }
            catch (OperationCanceledException)
            {
                Console.WriteLine("Notification service cancellation requested");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Notification service error:");
                Console.WriteLine(ex);
            }
        }
示例#2
0
        public void Add(Notification notification)
        {
            PostProcessNotification(notification);

            UnityThread.DispatchUnattended(() =>
            {
                if (notification.Scope != NotificationScope.Temporary)
                {
                    notifications.Add(notification);
                }
                OnNewNotification?.Invoke(notification);
                return(null);
            });
        }
 /// <summary>
 /// Event called when a new notification arrives.
 /// </summary>
 private void OnNotification(INotification notification)
 {
     OnNewNotification?.Invoke(notification);
 }
示例#4
0
 private void RegisterIncomingEvents()
 {
     HubProxy.On <NotificationInfo>("OnNewNotification", (notificationInfo) =>
     {
         if (notificationInfo.Name == NotificationNames.QUEUE_COMPLETED)
         {
             OnQueueCompleted?.Invoke(this, new EventInfo()
             {
                 Name = EventNames.QUEUE_COMPLETED, Data = notificationInfo.FromUserId
             });
         }
         else if (notificationInfo.Name == NotificationNames.DO_READMESSAGE)
         {
             OnDOReadMessage?.Invoke(this, notificationInfo);
         }
         else if (notificationInfo.Name == NotificationNames.DEVICE_STATUS_CHANGED)
         {
             OnDeviceStatusChanged?.Invoke(this, new EventInfo()
             {
                 Name = EventNames.DEVICE_STATUS_CHANGED, Data = notificationInfo.Data, Source = notificationInfo.Source
             });
         }
         else if (notificationInfo.Name == NotificationNames.APP_DISCONNECTED)
         {
             OnAppDisconnected?.Invoke(this, new EventInfo()
             {
                 Name = EventNames.APP_DISCONNECTED, Source = notificationInfo.Source, Data = notificationInfo.Data
             });
         }
         else if (notificationInfo.Name == NotificationNames.DO_UNBLOCK_SUPERVISEE)
         {
             OnDOUnblockSupervisee?.Invoke(this, notificationInfo);
         }
         else if (notificationInfo.Name == NotificationNames.APPOINTMENT_BOOKED)
         {
             OnAppointmentBooked?.Invoke(this, notificationInfo);
         }
         else if (notificationInfo.Name == NotificationNames.APPOINTMENT_REPORTED)
         {
             OnAppointmentReported?.Invoke(this, notificationInfo);
         }
         else if (notificationInfo.Name == NotificationNames.QUEUE_INSERTED)
         {
             OnQueueInserted?.Invoke(this, notificationInfo);
         }
         else if (notificationInfo.Name == NotificationNames.SSA_COMPLETED)
         {
             OnSSACompleted?.Invoke(this, notificationInfo);
         }
         else if (notificationInfo.Name == NotificationNames.SSA_PRINTING_LABEL)
         {
             OnSSAPrintingLabel?.Invoke(this, notificationInfo);
         }
         else if (notificationInfo.Name == NotificationNames.SHP_COMPLETED || notificationInfo.Name == NotificationNames.SSP_COMPLETED || notificationInfo.Name == NotificationNames.SSP_ERROR)
         {
             OnBackendAPISend?.Invoke(this, notificationInfo);
         }
         else
         {
             OnNewNotification?.Invoke(this, notificationInfo);
         }
     });
 }
 public void RaiseNotification(IAnalogyNotification notification, bool showAsPopup)
 {
     OnNewNotification?.Invoke(this, notification);
 }