//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\ #region --Misc Methods (Public)-- public async void Run(IBackgroundTaskInstance taskInstance) { deferral = taskInstance.GetDeferral(); if (taskInstance.TriggerDetails is RawNotification notification) { if (Settings.GetSettingBoolean(SettingsConsts.PUSH_ENABLED)) { // ToastHelper.ShowSimpleToast("Processing started."); BindableString statusText = new BindableString("status_text"); ToastNotification progressToast = PopProgressiveToast(statusText); try { await ParseAndShowNotificationAsync(notification.Content, progressToast, statusText); } catch (Exception e) { Logger.Error("Failed to process push notification.", e); } ToastNotificationManager.History.Remove(progressToast.Tag); // ToastHelper.ShowSimpleToast("Processing finished."); } else { Logger.Warn("Received a push notification, but push is disabled. Dropping it."); } } deferral.Complete(); }
private ToastNotification PopProgressiveToast(BindableString title) { ToastContent toastContent = new ToastContent { Visual = new ToastVisual { BindingGeneric = new ToastBindingGeneric { Children = { new AdaptiveProgressBar { Value = AdaptiveProgressBarValue.Indeterminate, Title = title, Status = "" } } } }, }; ToastNotification toast = new ToastNotification(toastContent.GetXml()) { Data = new NotificationData(), Tag = "toast_progress_tag" }; toast.Data.Values["status_text"] = "Started"; // ToastNotificationManager.CreateToastNotifier().Show(toast); return(toast); }
private void UpdateProgress(ToastNotification toast, BindableString title, string value) { NotificationData data = new NotificationData { SequenceNumber = 0 }; data.Values[title.BindingName] = value; ToastNotificationManager.CreateToastNotifier().Update(data, toast.Tag); }
public ActionSnoozeDismissToastContentInfo(BindableString greeting, string title, string companyName, string contentSection1, string contentSection2, string action, Uri imageUri, Uri appLogoImageUri, string actionButtonContent, string notNowButtonContent, string notNowAction, string snoozeButtonContent, string snoozeAction) { Greeting = greeting; Title = title; CompanyName = companyName; ContentSection1 = contentSection1; ContentSection2 = contentSection2; Action = action; ImageUri = imageUri; AppLogoImageUri = appLogoImageUri; ActionButtonContent = actionButtonContent; NotNowButtonContent = notNowButtonContent; NotNowAction = notNowAction; SnoozeButtonContent = snoozeButtonContent; SnoozeAction = snoozeAction; }
public ActionDismissToastContentInfo(BindableString greeting, string title, string contentSection1, string contentSection2, string action, ToastActivationType actionActivationType, string actionButtonContent, string notNowButtonContent, string notNowAction, string groupName, Option <string> contentSection3, string companyName) { Greeting = greeting; Title = title; ContentSection1 = contentSection1; ContentSection2 = contentSection2; Action = action; ActionButtonContent = actionButtonContent; NotNowButtonContent = notNowButtonContent; NotNowAction = notNowAction; GroupName = groupName; ContentSection3 = contentSection3; CompanyName = companyName; ActionActivationType = actionActivationType; }
public void Test_Adaptive_Text_Text() { AssertAdaptiveChild("<text>Hello & Goodbye</text>", new AdaptiveText() { Text = "Hello & Goodbye" }); // Data binding should work AssertAdaptiveChild("<text>{title}</text>", new AdaptiveText() { #if WINRT Bindings = { { AdaptiveTextBindableProperty.Text, "title" } } #else Text = new BindableString("title") #endif });
private async Task HandelPushMessageAsync(PushMessage pushMsg, ToastNotification progressToast, BindableString statusText) { // Get account: UpdateProgress(progressToast, statusText, "Getting account..."); AccountModel account = GetAccount(pushMsg.accountId); if (account is null) { Logger.Warn($"Received a push notification for an unknown account ID '{pushMsg.accountId}'. Dropping it."); return; } // Check if the account is enabled: if (!account.enabled) { Logger.Info($"Received a push notification for a deactivated account ('{account.bareJid}'). Dropping it."); } // Init the app service connection: appServiceConnection = new AppServiceConnection { AppServiceName = "uwpx.status", PackageFamilyName = Windows.ApplicationModel.Package.Current.Id.FamilyName }; UpdateProgress(progressToast, statusText, "Checking if the app is running..."); bool appRunning = await IsAppRunningAsync(); if (appRunning) { // Only check for connected here since everything else can be handled later like replacing the placeholder message. bool accountConnected = await IsAccountConnectedAsync(account.bareJid); UpdateProgress(progressToast, statusText, $"App is running. Account connected: {accountConnected}"); if (accountConnected) { Logger.Info("No need to toast push. Account already connected."); return; } } if (pushMsg.pendingSubscriptionCount > 0) { ToastHelper.ShowAccountMessageToast($"You might have received new subscription requests while you were away.", account.bareJid, "subscription"); } else { ToastHelper.ShowAccountMessageToast($"📨 You might have received new messages while you were away.", account.bareJid, "message"); } /*UpdateProgress(progressToast, statusText, $"Getting client for: {account.bareJid}"); * ClientConnectionHandler client = ConnectionHandler.INSTANCE.GetClient(account.bareJid); * UpdateProgress(progressToast, statusText, $"Connecting client '{account.bareJid}'..."); * Logger.Info($"Connecting '{account.bareJid}'..."); * await client.ConnectAsync(); * UpdateProgress(progressToast, statusText, $"Client '{account.bareJid}' connected. Waiting 10 seconds..."); * await Task.Delay(TimeSpan.FromSeconds(5)); * UpdateProgress(progressToast, statusText, $"Disconnecting client '{account.bareJid}'..."); * await client.DisconnectAsync(); * UpdateProgress(progressToast, statusText, $"Client '{account.bareJid}' disconnected."); * Logger.Info($"'{account.bareJid}' disconnected.");*/ }
private async Task ParseAndShowNotificationAsync(string s, ToastNotification progressToast, BindableString statusText) { UpdateProgress(progressToast, statusText, "Started"); if (string.IsNullOrEmpty(s)) { Logger.Warn("Received an empty push notification..."); return; } Logger.Trace(s); AbstractMessage msg = MessageParser.Parse(s); if (msg is null) { Logger.Warn("Invalid push message received: " + s); return; } UpdateProgress(progressToast, statusText, "Parsed"); if (msg is TestPushMessage) { ToastHelper.ShowSimpleToast("Here is your test push message. It got successfully received from the push server!🎉"); Logger.Info("Test push message received."); return; } else if (msg is PushMessage pushMsg) { await HandelPushMessageAsync(pushMsg, progressToast, statusText); } else { Logger.Warn("Invalid push message action received: " + msg.action); return; } }