private void RaiseNotificationEvent(NotificationAttributeCollection attributes) { NotificationSourceData sourceData = Notifications[attributes.NotificationUID]; switch (sourceData.EventId) { case EventID.NotificationAdded: NotificationAdded?.Invoke(this, new AppleNotificationEventArgs(sourceData, attributes)); break; case EventID.NotificationModified: NotificationModified?.Invoke(this, new AppleNotificationEventArgs(sourceData, attributes)); break; case EventID.NotificationRemoved: // Has been handled, but just in case.. NotificationRemoved?.Invoke(this, sourceData); break; } // Remove the notification from the list Notifications.Remove(sourceData.NotificationUID); }
/// <summary> /// When the value is changed a new notification ha arrived. We need to send a query about notification /// to the ControlPoint to get the actual notification message. /// </summary> /// <param name="obj"></param> private async void NotificationSource_ValueChanged(NotificationSourceData obj) { // TODO: Check this out. Not sure why but sometime I get a Notification UID = 0 // which breaks everything. if (obj.NotificationUID == 0) { return; } // We don't care about old notifications if (obj.EventFlags.HasFlag(EventFlags.EventFlagPreExisting)) { return; } // Remove notifications don't need more data if (obj.EventId == EventID.NotificationRemoved) { if (Notifications.ContainsKey(obj.NotificationUID)) { Notifications.Remove(obj.NotificationUID); } NotificationRemoved?.Invoke(this, obj); return; } // Store the notification if (Notifications.ContainsKey(obj.NotificationUID)) { Notifications[obj.NotificationUID] = obj; } else { Notifications.Add(obj.NotificationUID, obj); } // Build the attributes list for the GetNotificationAttributtes command. List <NotificationAttributeID> attributes = new List <NotificationAttributeID>(); attributes.Add(NotificationAttributeID.AppIdentifier); attributes.Add(NotificationAttributeID.Title); attributes.Add(NotificationAttributeID.Message); if (obj.EventFlags.HasFlag(EventFlags.EventFlagPositiveAction)) { attributes.Add(NotificationAttributeID.PositiveActionLabel); } if (obj.EventFlags.HasFlag(EventFlags.EventFlagNegativeAction)) { attributes.Add(NotificationAttributeID.NegativeActionLabel); } try { var communicationStatus = await ControlPoint.GetNotificationAttributesAsync(obj.NotificationUID, attributes); } catch (Exception ex) { // Simply log the exception to output console System.Diagnostics.Debug.WriteLine(ex.Message); } }
public AppleNotificationEventArgs(NotificationSourceData source, NotificationAttributeCollection notificationAttributes) { NotificationSource = source; NotificationAttributes = notificationAttributes; }