public async void Run(IBackgroundTaskInstance taskInstance) { Debug.WriteLine("Started RawNotificationReceiver background task."); // Füge einen CancelationHandler hinzu, der gerufen wird sollte die BackgroundTask abgebrochen werden. taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled); // Fordere ein BackgroundTaskDeferral Objekt an. Wenn asynchrone Operationen innerhalb der BackgroundTask ausgeführt werden // dann wird ein solches Objekt benötigt, um das vorzeitige Schließen der Task zu verhindern. BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); // Hole die RawNotification über die TriggerDetails. RawNotification notification = (RawNotification)taskInstance.TriggerDetails; PushNotificationController pushController = new PushNotificationController(); // Frage PushMessage Objekt zur Notification ab und stoße Behandlung an. PushMessage pm = pushController.GetPushMessageFromNotification(notification); bool handledSuccessfully = await pushController.HandlePushNotificationAsync(pm); // Soll der Nutzer benachrichtigt werden? if(handledSuccessfully && pushController.IsUserNotificationRequired(pm)) { performUserNotification(pushController, pm); } Debug.WriteLine("Finished background task."); // Task als abgeschlossen kennzeichnen. deferral.Complete(); }
/// <summary> /// Führt die Nutzerbenachrichtigung über eine eingegangene Push Nachricht und die /// damit verbundene Aktion durch. /// </summary> /// <param name="pushController">Referenz auf die Instanz des PushNotificationController.</param> /// <param name="pushMsg">Die eingegangene Push-Nachricht, für die /// die Benutzerbenachrichtigung durchgeführt wird.</param> private void performUserNotification(PushNotificationController pushController, PushMessage pushMsg) { string headline = null; string resourceKey = null; string resourceAppendix = null; switch (pushMsg.PushType) { case PushType.ANNOUNCEMENT_NEW: // Ermittle Überschrift und Ressourcen-Schlüssel für Nachrichteninhalt. headline = pushController.GetUserNotificationHeadline(pushMsg); resourceKey = pushController.GetUserNotificationContentLocalizationKey(pushMsg); // Toast mit Ankündigung. showToastNotification(headline, resourceKey); break; case PushType.CONVERSATION_MESSAGE_NEW: // Ermittle Überschrift und Ressourcen-Schlüssel für Nachrichteninhalt. headline = pushController.GetUserNotificationHeadline(pushMsg); resourceKey = pushController.GetUserNotificationContentLocalizationKey(pushMsg); // Toast mit Ankündigung. showToastNotification(headline, resourceKey); break; default: // Ermittle Überschrift und Ressourcen-Schlüssel für Nachrichteninhalt. headline = pushController.GetUserNotificationHeadline(pushMsg); resourceKey = pushController.GetUserNotificationContentLocalizationKey(pushMsg); resourceAppendix = pushController.GetResourceAppendix(pushMsg); // Ghost Toast. showSilentToastNotification(headline, resourceKey, resourceAppendix); break; } }
/// <summary> /// Erzeugt eine Instanz der PushNotificationManager Klasse. /// </summary> private PushNotificationManager(){ pushController = new PushNotificationController(); }