Пример #1
0
        public INotification Build()
        {
            if (buildCompleted == true)
            {
                throw Exceptions.ExceptionUtils.BuildTwice;
            }
            buildCompleted = true;
            if (string.IsNullOrEmpty(Tag))
            {
                Tag = Guid.NewGuid().ToString();
            }
            if (string.IsNullOrEmpty(launchArgs) == false)
            {
                switch (activationType)
                {
                case ToastActivationType.Foreground:
                    launchArgs += "&" + TagAndGroupActivationArgs();
                    break;

                case ToastActivationType.Background:
                case ToastActivationType.Protocol:
                    break;

                default:
                    throw new InvalidOperationException("unknown activation type");
                }
            }
            else
            {
                launchArgs = TagAndGroupActivationArgs();
            }
            tbc.AddToastActivationInfo(launchArgs, activationType);
            return(new Notification(tbc.Content, this));
        }
Пример #2
0
        public void AddToastActivationInfoTest_WithExpectedArgs_ReturnSelfWithActivationInfoAdded()
        {
            // Arrange
            string testToastLaunchArugments             = "Test Toast Launch Args";
            ToastActivationType testToastActivationType = ToastActivationType.Background;

            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder.AddToastActivationInfo(testToastLaunchArugments, testToastActivationType);

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreEqual(testToastLaunchArugments, builder.Content.Launch);
            Assert.AreEqual(testToastActivationType, builder.Content.ActivationType);
        }
Пример #3
0
        public void AddArgumentTest_AvoidModifyingCustomButtons_ReturnSelfWithArgumentsAdded()
        {
            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder
                                                   .AddToastActivationInfo("myCustomLaunchStr", ToastActivationType.Foreground)

                                                   .AddButton("Accept", ToastActivationType.Background, "myAcceptStr")

                                                   // userId shouldn't be added to any of these except view
                                                   .AddArgument("userId", 542)

                                                   .AddButton("Decline", ToastActivationType.Background, "myDeclineStr")

                                                   .AddButton(new ToastButton()
                                                              .SetContent("View")
                                                              .AddArgument("action", "view"));

            // Assert
            Assert.AreSame(builder, anotherReference);

            // Top level arguments should be the custom string since user set that
            Assert.AreEqual("myCustomLaunchStr", builder.Content.Launch);

            // Buttons should have their custom strings except the last
            var actions = builder.Content.Actions as ToastActionsCustom;

            var button1 = actions.Buttons[0] as ToastButton;

            Assert.AreEqual("Accept", button1.Content);
            Assert.AreEqual("myAcceptStr", button1.Arguments);

            var button2 = actions.Buttons[1] as ToastButton;

            Assert.AreEqual("Decline", button2.Content);
            Assert.AreEqual("myDeclineStr", button2.Arguments);

            var button3 = actions.Buttons[2] as ToastButton;

            Assert.AreEqual("View", button3.Content);
            Assert.AreEqual("action=view;userId=542", button3.Arguments);
        }
Пример #4
0
        public static ToastContent GenerateToastContent()
        {
            ToastContentBuilder builder = new ToastContentBuilder();

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

            // 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);

            return(builder.Content);
        }
Пример #5
0
        private async void NotiBootstrap()
        {
            var builder = new ToastContentBuilder();

            try
            {
                var infos = await AppDiagnosticInfo.RequestInfoForAppAsync();

                var   resourceInfos = infos[0].GetResourceGroups();
                await resourceInfos[0].StartSuspendAsync();

                if (UWPAppEnvironment.toastNotifier == null)
                {
                    UWPAppEnvironment.toastNotifier = ToastNotificationManager.CreateToastNotifier();
                }

                var notiUWP = new NotiScheduleUWP();

                notiUWP.CancelAll();
                notiUWP.ScheduleAll();

                builder.AddToastActivationInfo("BootNotiRegister", ToastActivationType.Foreground);
                builder.AddText(AppResources.BootAlarmRegisterSuccess);
            }
            catch (Exception)
            {
                builder.AddText(AppResources.BootAlarmRegisterFail);
            }
            finally
            {
                if (builder != null)
                {
                    UWPAppEnvironment.toastNotifier.AddToSchedule(new ScheduledToastNotification(builder.GetToastContent().GetXml(), DateTime.Now.AddSeconds(3)));
                }

                await Task.Delay(3000);

                Exit();
            }
        }