public bool Enqueue(AbstractNotification notification) { if (_notificationQueue.Contains(notification)) { return false; } _notificationQueue.Enqueue(notification); NotifyAll(); return true; }
/// <summary> /// Check if the queue contain the notification /// </summary> /// <param name="notification">the notification to check</param> /// <returns>true if the queue, otherwise false</returns> public bool Contains(AbstractNotification notification) { return _notificationQueue.Contains(notification); }
//Handle the different type of notification received. private void Handle(AbstractNotification notification) { switch (notification.NotificationCode) { case NotificationCode.MonitorPathNotification: //Inform the SLL that a new Path have been merged { MonitorPathNotification mpNotification = notification as MonitorPathNotification; if (mpNotification == null) //Discard return; _sll.AddTagPath(mpNotification.TargetTag, mpNotification.TargetPath); } break; case NotificationCode.UnmonitorPathNotification: //Inform the SLL that a Path have been untag due to merging { UnMonitorPathNotification umpNotification = notification as UnMonitorPathNotification; if (umpNotification == null)//Discard return; _sll.RemoveTagPath(umpNotification.TargetTag, umpNotification.TargetPath); } break; case NotificationCode.AddTagNotification: //Inform the SLL that a new Tag have been added due to merging { AddTagNotification atNotification = notification as AddTagNotification; if (atNotification == null)//Discard return; _sll.AddTag(atNotification.Tag); } break; case NotificationCode.DeleteTagNotification: //Inform the SLL that a Tag have been deleted due to merging { RemoveTagNotification rmNotification = notification as RemoveTagNotification; if (rmNotification == null)//Discard return; _sll.RemoveTag(rmNotification.Tag); } break; case NotificationCode.MonitorTagNotification: //Inform the SLL to start Monitoring a Tag(Called after a manual sync is completed) { MonitorTagNotification mtNotification = notification as MonitorTagNotification; if (mtNotification == null)//Discard return; _sll.MonitorTag(mtNotification.Tagname); } break; case NotificationCode.TaggedPathDeletedNotification: //Inform the SLL that a tagged folder have been deleted. { TaggedPathDeletedNotification tpdNotification = notification as TaggedPathDeletedNotification; if (tpdNotification == null) // Discard return; _sll.Untag(tpdNotification.DeletedPaths); } break; case NotificationCode.SaveNotification: // Inform the SLL to save. _sll.Save(); break; } }
/// <summary> /// Handles any dequeued notification from the UINotificationQueue by notifying the UI /// </summary> /// <param name="notification">Notification to handle</param> private void Handle(AbstractNotification notification) { // Handles Sync Start Notification if (notification.NotificationCode.Equals(NotificationCode.SyncStartNotification)) { SyncStartNotification ssNotification = notification as SyncStartNotification; if (ssNotification != null) { _main.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { _main.CurrentProgress = ssNotification.Progress; new SyncProgressWatcher(_main, ssNotification.TagName, ssNotification.Progress); })); } } // Handles Sync Complete Notification else if (notification.NotificationCode.Equals(NotificationCode.SyncCompleteNotification)) { SyncCompleteNotification scNotification = notification as SyncCompleteNotification; if (scNotification != null) { _main.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { _main.TagChanged(scNotification.TagName); })); } } // Handles Nothing to Sync Notification else if (notification.NotificationCode.Equals(NotificationCode.NothingToSyncNotification)) { NothingToSyncNotification ntsNotification = notification as NothingToSyncNotification; if (ntsNotification != null) { _main.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { _main.NotifyNothingToSync(ntsNotification.TagName); })); } } // Handles Auto Sync Complete Notification else if (notification.NotificationCode.Equals(NotificationCode.AutoSyncCompleteNotification)) { AutoSyncCompleteNotification ascNotification = notification as AutoSyncCompleteNotification; if (ascNotification != null) { _main.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { _main.NotifyAutoSyncComplete(ascNotification.Path); })); } } }