Example #1
0
        public static void HandlePackageInstallCompletedToast(SuccessMessage m, ToastNotification progressToast)
        {
            if (!OperatingSystem.IsWindowsVersionAtLeast(10, 0, 18362))
            {
                return;
            }

            PackageBase package = (PackageBase)m.Context;

            var builder = new ToastContentBuilder().SetToastScenario(ToastScenario.Reminder)
                          .AddToastActivationInfo($"package/{package.Urn}", ToastActivationType.Foreground)
                          .AddText(package.ShortTitle)
                          .AddText(package.Title + " just got installed.");

            try
            {
                if (package.GetAppIcon().Result is SDK.Images.FileImage image && !image.Uri.IsFile)
                {
                    builder.AddAppLogoOverride(image.Uri, addImageQuery: false);
                }
            }
            finally { }

            var notif = new ToastNotification(builder.GetXml());

            // Hide progress notification
            Hide(progressToast);
            // Show the final notification
            ToastNotificationManager.GetDefault().CreateToastNotifier().Show(notif);
        }
        /// <summary>
        /// Shows the toast notification.
        /// </summary>
        public async Task Show()
        {
            var builder = new ToastContentBuilder();

            if (AppLogoOverride != null)
            {
                var uri = AppLogoOverride.GetSourceUri() ?? await AppLogoOverride.GetFileUriAsync().ConfigureAwait(false);

                builder.AddAppLogoOverride(uri);
            }

            // Title and Message are required.
            builder.AddText(Title, hintMaxLines: 1)
            .AddText(Message);

            builder.SetToastDuration(ToastDuration == ToastDuration.Short ? UwpNot.ToastDuration.Short : UwpNot.ToastDuration.Long);

            _tcs = new TaskCompletionSource <object>();

            builder.Show(t =>
            {
                TypedEventHandler <Windows.UI.Notifications.ToastNotification, ToastDismissedEventArgs> handler = (sender, args) => { };
                handler = (sender, args) =>
                {
                    sender.Dismissed -= handler;
                    _tcs.SetResult(null);
                };
                t.Dismissed += handler;
            });

            await _tcs.Task;
        }
Example #3
0
        public static async Task SendNotification(string chatId, string?personId, string messageId, string chatName, string contactName, string message)
        {
            var thumbnailUri = await GetPersonId(personId);

            var builder = new ToastContentBuilder()
                          .AddArgument(ActivationHelper.ToastAction, ActivationHelper.ToastActionConversation)
                          .AddArgument(ActivationHelper.ToastActionConversationChat, chatId)
                          .AddHeader(
                chatId,
                chatName,
                $"{ActivationHelper.ToastAction}={ActivationHelper.ToastActionConversation}&" +
                $"{ActivationHelper.ToastActionConversationChat}={chatId}"
                )
                          .AddText(contactName)
                          .AddText(message);

            if (thumbnailUri != null)
            {
                builder.AddAppLogoOverride(thumbnailUri, ToastGenericAppLogoCrop.Circle);
            }

            builder.Show((toast) =>
            {
                toast.Group = chatId;
                toast.Tag   = messageId;
            });
        }
        private void handleNotifications(List <DisplayLobby> displayLobbies)
        {
            if (displayLobbies == null)
            {
                return;
            }

            if (notifiedLobbies == null)
            {
                notifiedLobbies = new HashSet <string>();
            }

            List <DisplayLobby> newLobbies = displayLobbies.Where(dL => !string.IsNullOrEmpty(dL.LobbyID) && !string.IsNullOrEmpty(dL.LobbyName) && !notifiedLobbies.Contains(dL.LobbyID)).ToList();

            if (newLobbies.Count == 0)
            {
                return;
            }

            notifiedLobbies.UnionWith((from dL in newLobbies select dL.LobbyID).ToHashSet());

            List <string> newNames = (from dL in newLobbies select dL.LobbyName).ToList();
            string        title    = newNames.Count + " New Lobbies";
            string        lobbies  = string.Join("; ", newNames.Take(lobbyNamesInNotification).ToList());

            ToastContentBuilder tcb = new ToastContentBuilder();

            tcb.AddAppLogoOverride(new Uri(Storage.GetLogoPath())).
            AddText(title).AddText(lobbies).Show();
        }
Example #5
0
        public void AddAppLogoOverrideTest_WithLogoUriOnly_ReturnSelfWithCustomLogoAdded()
        {
            // Arrange
            Uri testAppLogoUriSrc = new Uri("C:/justatesturi.jpg");

            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder.AddAppLogoOverride(testAppLogoUriSrc);

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual(testAppLogoUriSrc.OriginalString, builder.Content.Visual.BindingGeneric.AppLogoOverride.Source);
        }
Example #6
0
        public static void ShowTextToastNotification(string title, string content, string?logoUri = null, Action <ToastContentBuilder>?contentBuilder = null)
        {
            var builder = new ToastContentBuilder()
                          .AddText(title, AdaptiveTextStyle.Header)
                          .AddText(content, AdaptiveTextStyle.Caption);

            contentBuilder?.Invoke(builder);
            if (logoUri is not null)
            {
                builder.AddAppLogoOverride(logoUri, ToastGenericAppLogoCrop.Default);
            }

            builder.Show();
        }
Example #7
0
        public static ToastNotification GenerateDownloadFailureToast(PackageBase package)
        {
            if (!OperatingSystem.IsWindowsVersionAtLeast(10, 0, 18362))
            {
                return(null);
            }

            var builder = new ToastContentBuilder().SetToastScenario(ToastScenario.Reminder)
                          .AddToastActivationInfo($"package/{package.Urn}", ToastActivationType.Foreground)
                          .AddText(package.Title)
                          .AddText("Failed to download, please try again later");

            if (package.GetAppIcon().Result is SDK.Images.FileImage image && !image.Uri.IsFile)
            {
                builder.AddAppLogoOverride(image.Uri, addImageQuery: false);
            }

            return(new ToastNotification(builder.GetXml()));
        }
Example #8
0
        public void AddAppLogoOverrideTest_WithCustomLogoAndFullOptions_ReturnSelfWithCustomLogoAndOptionsAdded()
        {
            // Arrange
            Uri testAppLogoUriSrc = new Uri("C:/justatesturi.jpg");
            ToastGenericAppLogoCrop testCropOption = ToastGenericAppLogoCrop.Circle;
            string testLogoAltText       = "Test Logo Alt Text";
            bool   testLogoAddImageQuery = true;

            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder.AddAppLogoOverride(testAppLogoUriSrc, testCropOption, testLogoAltText, testLogoAddImageQuery);

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual(testAppLogoUriSrc.OriginalString, builder.Content.Visual.BindingGeneric.AppLogoOverride.Source);
            Assert.AreEqual(testCropOption, builder.Content.Visual.BindingGeneric.AppLogoOverride.HintCrop);
            Assert.AreEqual(testLogoAltText, builder.Content.Visual.BindingGeneric.AppLogoOverride.AlternateText);
            Assert.AreEqual(testLogoAddImageQuery, builder.Content.Visual.BindingGeneric.AppLogoOverride.AddImageQuery);
        }
Example #9
0
        public void Show(NotificationData data)
        {
            var toast = new ToastContentBuilder().SetToastScenario(ToastScenario.Default)
                        .AddText(RemoveInvalidXmlChars(data.Title), AdaptiveTextStyle.Title)
                        .AddText(RemoveInvalidXmlChars(data.Content));

            if (!string.IsNullOrEmpty(data.Image))
            {
                toast.AddAppLogoOverride(new Uri(data.Image));
            }

            if (!string.IsNullOrEmpty(data.Attribution))
            {
                toast.AddAttributionText(RemoveInvalidXmlChars(data.Attribution));
            }
            var result = toast.Content;

            ToastNotificationManager.CreateToastNotifier().Show(new ToastNotification(result.GetXml()));
        }
Example #10
0
        private void OnRafflesWon(object sender, RafflesWonArgs e)
        {
            bool enableToast = Properties.UserConfig.Default.ToastNotifications;

            if (enableToast)
            {
                string logo = Files.LogoFile;
                if (!File.Exists(logo))
                {
                    using (var http = new HttpClient())
                    {
                        string url  = string.Format("https://scrap.tf/apple-touch-icon.png?{0}", Guid.NewGuid());
                        byte[] data = http.GetByteArrayAsync(url).Result;
                        File.WriteAllBytes(logo, data);
                    }
                }

                string message    = e.Message;
                var    viewButton = new ToastButton();
                viewButton.AddArgument("action", "viewRafflesWonPage");
                viewButton.SetContent("View Won Raffles");

                var dismissButton = new ToastButton();
                dismissButton.SetContent("Dismiss");
                dismissButton.SetDismissActivation();

                var toast = new ToastContentBuilder();
                toast.AddAppLogoOverride(new Uri(logo), ToastGenericAppLogoCrop.Circle, null, false);
                toast.AddAttributionText(string.Format("Scraps {0}", Common.Constants.Version.Full));
                toast.AddText("Items Need Withdrawing");
                toast.AddText(message);
                toast.AddButton(viewButton);
                toast.AddButton(dismissButton);
                toast.Show();
            }
        }
Example #11
0
 public IUwpExtension AddAppLogoOverride(Uri uri, ToastGenericAppLogoCrop?hintCrop = null, string?alternateText = null, bool?addImageQuery = null)
 {
     tbc.AddAppLogoOverride(uri, hintCrop, alternateText, addImageQuery);
     return(this);
 }