private void PopToast()
        {
            // Generate the toast notification content
            ToastContentBuilder builder = new ToastContentBuilder();

            // Include launch string so we know what to open when user clicks toast
            builder.AddArgument("action", "viewForecast");
            builder.AddArgument("zip", 98008);

            // We'll always have this summary text on our toast notification
            // (it is required that your toast starts with a text element)
            builder.AddText("Today will be mostly sunny with a high of 63 and a low of 42.");

            // If Adaptive Toast Notifications are supported
            if (IsAdaptiveToastSupported())
            {
                // Use the rich Tile-like visual layout
                builder.AddVisualChild(new AdaptiveGroup()
                {
                    Children =
                    {
                        GenerateSubgroup("Mon", "Mostly Cloudy.png", 63, 42),
                        GenerateSubgroup("Tue", "Cloudy.png",        57, 38),
                        GenerateSubgroup("Wed", "Sunny.png",         59, 43),
                        GenerateSubgroup("Thu", "Sunny.png",         62, 42),
                        GenerateSubgroup("Fri", "Sunny.png",         71, 66)
                    }
                });
            }

            // Otherwise...
            else
            {
                // We'll just add two simple lines of text
                builder
                .AddText("Monday ⛅ 63° / 42°")
                .AddText("Tuesday ☁ 57° / 38°");
            }

            // Set the base URI for the images, so we don't redundantly specify the entire path
            builder.Content.Visual.BaseUri = new Uri("Assets/NotificationAssets/", UriKind.Relative);

            // Show the toast
            builder.Show();
        }
Esempio n. 2
0
        public static void Display(IEnumerable <string> messages)
        {
            // Requires Microsoft.Toolkit.Uwp.Notifications NuGet package version 7.0 or greater
            //Toast
            var toast = new ToastContentBuilder();

            toast.AddArgument("action", "viewConversation");
            toast.AddArgument("conversationId", 9813);
            toast.AddText("Illumination problems detected!");
            foreach (var m in messages)
            {
                if (!string.IsNullOrEmpty(m))
                {
                    toast.AddText(m);
                }
            }
            toast.Show(); // Not seeing the Show() method? Make sure you have version 7.0, and if you're using .NET 5, your TFM must be net5.0-windows10.0.17763.0 or greater
        }
Esempio n. 3
0
        public void AddArgumentTest_Escaping_ReturnSelfWithArgumentsAdded()
        {
            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder
                                                   .AddArgument("user;Id", "andrew=leader%26bares");

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual("user%3BId=andrew%3Dleader%2526bares", builder.Content.Launch);
        }
Esempio n. 4
0
        public void AddArgumentTest_NoValue_ReturnSelfWithArgumentsAdded()
        {
            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder
                                                   .AddArgument("isPurelyInformational");

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual("isPurelyInformational", builder.Content.Launch);
        }
Esempio n. 5
0
        public void AddArgumentTest_Basic_ReturnSelfWithArgumentsAdded()
        {
            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder
                                                   .AddArgument("userId", 542)
                                                   .AddArgument("name", "Andrew");

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual("userId=542;name=Andrew", builder.Content.Launch);
        }
Esempio n. 6
0
        public void AddArgumentTest_BackgroundActivation_ReturnSelfWithArgumentsAdded()
        {
            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder
                                                   .AddArgument("userId", 542)
                                                   .SetBackgroundActivation();

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual("userId=542", builder.Content.Launch);
            Assert.AreEqual(ToastActivationType.Background, builder.Content.ActivationType);
        }
Esempio n. 7
0
        public void MediatorContext_OnEarthquake(object sender, Client.Peer.EPSPQuakeEventArgs e)
        {
            if (e.InformationType == QuakeInformationType.Unknown)
            {
                return;
            }

            var earthquakeNotification = configuration.EarthquakeNotification;

            if (!earthquakeNotification.Enabled)
            {
                return;
            }
            if (!earthquakeNotification.Notice)
            {
                return;
            }

            // 震源情報は震度 3 以上で発表されるため、震度 3 とみなす
            var scale =
                e.InformationType == QuakeInformationType.Destination ?
                30 :
                ScaleConverter.Str2Int(e.Scale);

            if (scale < earthquakeNotification.MinScale)
            {
                return;
            }

            var builder = new ToastContentBuilder();

            // タイトル行
            var type = e.InformationType switch
            {
                QuakeInformationType.ScalePrompt => "震度速報",
                QuakeInformationType.Destination => "震源情報",
                QuakeInformationType.ScaleAndDestination => "震源・震度情報",
                QuakeInformationType.Detail => "地震情報",
                QuakeInformationType.Foreign => "遠地(海外)地震情報",
                _ => "地震情報",
            };

            if (e.InformationType == QuakeInformationType.Foreign || e.InformationType == QuakeInformationType.Destination)
            {
                builder.AddText($"{type} ({e.OccuredTime})");
            }
            else
            {
                builder.AddText($"{type} ({e.OccuredTime} 震度{e.Scale})");
            }

            if (e.InformationType == QuakeInformationType.ScalePrompt)
            {
                var maxScaleGroup = e.PointList.OrderBy(e => e.ScaleInt).Reverse().GroupBy(e => e.Scale).First();
                builder.AddText($"震度{maxScaleGroup.Key}: {string.Join('、', maxScaleGroup.Select(e => e.Name))}");
            }
            else
            {
                var tsunamiDescription = e.TsunamiType switch
                {
                    DomesticTsunamiType.None => "津波の心配なし",
                    DomesticTsunamiType.Checking => "津波の有無調査中",
                    DomesticTsunamiType.Effective => "津波予報 発表中",
                    _ => "津波の有無不明",
                };
                builder.AddText($"{e.Destination} (深さ{e.Depth}, {e.Magnitude}) {tsunamiDescription}");
            }

            builder.AddArgument("type", "quake").AddArgument("receivedAt", e.ReceivedAt.ToString());
            builder.Show();
        }