예제 #1
0
 static void CounterChanged(Notification notification, object handback)
 {
     Console.WriteLine("Counter changed! New value is {0}", notification.UserData);
 }
 /// <summary>
 /// Sends a notification. 
 /// </summary>
 /// <param name="notification">The notification to send.</param>
 public void SendNotification(Notification notification)
 {
     if (notification.SequenceNumber == -1)
     {
         notification.SequenceNumber = GetNextSequenceNumber();
     }
     foreach (List<NotificationSubscription> subscrList in _subscriptions.Values)
     {
         foreach (NotificationSubscription subscr in subscrList)
         {
             if (subscr.FilterCallback == null || subscr.FilterCallback(notification))
             {
                 HandleNotification(subscr.Callback, notification, subscr.Handback);
             }
         }
     }
 }
 /// <summary>
 /// This method is called by <see cref="SendNotification(Notification)"/> for each listener in order to send the notification to that 
 /// listener. It can be overridden in subclasses to change the behavior of notification delivery, for 
 /// instance to deliver the notification in a separate thread.
 /// </summary>
 /// <remarks>
 /// It is not guaranteed that this method is called by the same thread as the one that called 
 /// <see cref="SendNotification(Notification)"/>.
 /// The default implementation of this method is equivalent to <code>callback(notification, handback);</code>        
 /// </remarks>
 /// <param name="callback"></param>
 /// <param name="notification"></param>
 /// <param name="handback"></param>
 protected virtual void HandleNotification(NotificationCallback callback, Notification notification, object handback)
 {
     callback((Notification) notification.Clone(), handback);
 }
예제 #4
0
 static void OnTimerEvent(Notification notification, object handback)
 {
     TimerNotification timerNotif = (TimerNotification) notification;
      Console.WriteLine("Timer event {0}! Message: {1}, user provided data: {2}", timerNotif.Type, timerNotif.Message, notification.UserData);
 }