private static void AssertAudioPayload(string expectedAudioXml, ToastAudio audio)
 {
     AssertPayload("<toast>" + expectedAudioXml + "</toast>", new ToastContent()
     {
         Audio = audio
     });
 }
Ejemplo n.º 2
0
 //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
 #region --Constructors--
 /// <summary>
 /// Basic Constructor
 /// </summary>
 /// <history>
 /// 17/11/2018 Created [Fabian Sauter]
 /// </history>
 public OnewheelThermalHandler()
 {
     this.ALARM_SOUND = new ToastAudio
     {
         Loop = true,
         Src  = new Uri("ms-winsoundevent:Notification.Looping.Alarm9")
     };
 }
        public void Test_Toast_Xml_Audio_Loop_True()
        {
            var audio = new ToastAudio()
            {
                Loop = true
            };

            AssertAudioPayload("<audio loop='true'/>", audio);
        }
        public void Test_Toast_Xml_Audio_Silent_False()
        {
            var audio = new ToastAudio()
            {
                Silent = false
            };

            AssertAudioPayload("<audio/>", audio);
        }
        public void Test_Toast_Xml_Audio_Silent_True()
        {
            var audio = new ToastAudio()
            {
                Silent = true
            };

            AssertAudioPayload("<audio silent='true'/>", audio);
        }
        public void Test_Toast_Xml_Audio_Src_Value()
        {
            var audio = new ToastAudio()
            {
                Src = new Uri("ms-appx:///Assets/audio.mp3")
            };

            AssertAudioPayload("<audio src='ms-appx:///Assets/audio.mp3'/>", audio);
        }
        public void Test_Toast_Xml_Audio_Loop_False()
        {
            var audio = new ToastAudio()
            {
                Loop = false
            };

            AssertAudioPayload("<audio />", audio);
        }
Ejemplo n.º 8
0
        public void AddAudioTest_WithAudioObject_ReturnSelfWithCustomAudioAdded()
        {
            // Arrange
            var audio = new ToastAudio()
            {
                Silent = true
            };

            // Act
            ToastContentBuilder builder          = new ToastContentBuilder();
            ToastContentBuilder anotherReference = builder.AddAudio(audio);

            // Assert
            Assert.AreSame(builder, anotherReference);
            Assert.AreSame(audio, builder.Content.Audio);
        }
Ejemplo n.º 9
0
        private static AudioOption CheckAudio(ToastAudio audio)
        {
            switch (audio)
            {
            case ToastAudio.Silent:
                return(AudioOption.Silent);

            case ToastAudio.Default:
            case ToastAudio.IM:
            case ToastAudio.Mail:
            case ToastAudio.Reminder:
            case ToastAudio.SMS:
                return(AudioOption.Short);

            default:
                return(AudioOption.Long);
            }
        }
Ejemplo n.º 10
0
 //--------------------------------------------------------Constructor:----------------------------------------------------------------\\
 #region --Constructors--
 /// <summary>
 /// Basic Constructor
 /// </summary>
 /// <history>
 /// 17/11/2018 Created [Fabian Sauter]
 /// </history>
 public OnewheelBatteryHandler()
 {
     this.ALARM_SOUND_5_PERCENT = new ToastAudio
     {
         Loop = false,
         Src  = new Uri("ms-winsoundevent:Notification.Default")
     };
     this.ALARM_SOUND_20_PERCENT = new ToastAudio
     {
         Loop = false,
         Src  = new Uri("ms-winsoundevent:Notification.IM")
     };
     this.ALARM_SOUND_100_PERCENT = new ToastAudio
     {
         Loop = false,
         Src  = new Uri("ms-winsoundevent:Notification.Default")
     };
 }
Ejemplo n.º 11
0
        public ToastContent BuildContent()
        {
            ToastVisual visual = new ToastVisual()
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = Title
                        },
                        new AdaptiveText()
                        {
                            Text = Line0
                        },
                    },
                    AppLogoOverride = new ToastGenericAppLogo()
                    {
                        Source   = ImagePath,
                        HintCrop = ToastGenericAppLogoCrop.Default
                    }
                }
            };
            var toastAudio = new ToastAudio()
            {
                Silent = Silent
            };

            if (SoundFilePath != null)
            {
                toastAudio.Src = new Uri("file:///" + SoundFilePath);
            }
            return(new ToastContent()
            {
                Visual = visual,
                Audio = toastAudio,
                Duration = ToastDuration.Short
            });
        }
Ejemplo n.º 12
0
        public static void Show(string title, string body)
        {
            var visual = new ToastVisual
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = title
                        },
                        new AdaptiveText()
                        {
                            Text = body
                        }
                    }
                }
            };
            var audio = new ToastAudio
            {
                Silent = true
            };
            ToastContent toastContent = new ToastContent()
            {
                Visual = visual,
                Audio  = audio
            };

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(toastContent.GetContent());

            var toast = new ToastNotification(doc);

            ToastNotificationManager.History.Clear();
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
Ejemplo n.º 13
0
        private ToastContent GenerateSimpleToastContent(string title, string content, bool showDismissButton = true, bool isAudioSilent = false)
        {
            var audio = new ToastAudio
            {
                Silent = isAudioSilent
            };

            if (showDismissButton)
            {
                return(new ToastContent()
                {
                    Audio = audio,
                    Scenario = ToastScenario.Default,
                    Visual = new ToastVisual()
                    {
                        BindingGeneric = new ToastBindingGeneric()
                        {
                            Children =
                            {
                                new AdaptiveText()
                                {
                                    Text = title
                                },
                                new AdaptiveText()
                                {
                                    Text = content
                                }
                            }
                        }
                    },
                    Actions = new ToastActionsCustom()
                    {
                        Buttons =
                        {
                            new ToastButtonDismiss()
                        }
                    }
                });
            }
            else
            {
                return(new ToastContent()
                {
                    Audio = audio,
                    Scenario = ToastScenario.Default,
                    Visual = new ToastVisual()
                    {
                        BindingGeneric = new ToastBindingGeneric()
                        {
                            Children =
                            {
                                new AdaptiveText()
                                {
                                    Text = title
                                },
                                new AdaptiveText()
                                {
                                    Text = content
                                }
                            }
                        }
                    }
                });
            }
        }
Ejemplo n.º 14
0
        public string GetInteractiveToastXml()
        {
            var toastVisual = new ToastVisual
            {
                BindingGeneric = new ToastBindingGeneric
                {
                    Children =
                    {
                        new AdaptiveText {
                            Text = _toastModel.Title
                        },                                             // Title
                        new AdaptiveText {
                            Text = _toastModel.Body
                        },                                            // Body
                    },
                    AppLogoOverride = new ToastGenericAppLogo
                    {
                        Source        = _toastModel.ImagePath,
                        AlternateText = "Logo"
                    }
                }
            };
            var toastAction = new ToastActionsCustom
            {
                //Inputs =
                //{
                //    new ToastTextBox(id: MessageId) { PlaceholderContent = "Input a message" }
                //},
                Buttons =
                {
                    // Note that there's no reason to specify background activation, since our COM
                    // activator decides whether to process in background or launch foreground window
                    new ToastButton("Open",  new QueryString()
                    {
                        { "action",          "open"    }
                    }.ToString()),

                    new ToastButton("Close", new QueryString()
                    {
                        { "action",          "dismiss" }
                    }.ToString()),
                }
            };

            var toastAudio = new ToastAudio();

            if (!_toastModel.Silent)
            {
                toastAudio = new ToastAudio
                {
                    Loop = true,
                    Src  = new Uri("ms-winsoundevent:Notification.Looping.Alarm4")
                };
            }

            var toastContent = new ToastContent
            {
                Visual   = toastVisual,
                Actions  = toastAction,
                Duration = ToastDuration.Long,
                Audio    = toastAudio
            };

            return(toastContent.GetContent());
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Show toast notification.
        /// </summary>
        /// <param name="arguments">Notification arguments object.</param>
        /// <returns>Toast notification object.</returns>
        public static async Task <ToastNotification> ShowToast(NotificationArguments arguments)
        {
            //Set the toast visual
            var visual = new ToastVisual()
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = arguments.Title
                        },
                        new AdaptiveText()
                        {
                            Text = arguments.Message
                        }
                    }
                }
            };

            //Set the attribution text
            if (!string.IsNullOrWhiteSpace(arguments.AttributionText))
            {
                visual.BindingGeneric.Attribution = new ToastGenericAttributionText()
                {
                    Text = arguments.AttributionText
                };
            }

            //Set the logo override
            var imagePath       = Globals.GetImageOrDefault(arguments.PicturePath);
            var isInternetImage = IsInternetImage(imagePath);
            var imageSource     = isInternetImage ? await DownloadImageToDisk(imagePath) : imagePath;

            visual.BindingGeneric.AppLogoOverride = new ToastGenericAppLogo()
            {
                Source   = imageSource,
                HintCrop = ToastGenericAppLogoCrop.Circle
            };

            //Set a background image
            if (!string.IsNullOrWhiteSpace(arguments.Image))
            {
                isInternetImage = IsInternetImage(arguments.Image);
                imageSource     = isInternetImage ? await DownloadImageToDisk(arguments.Image) : arguments.Image;

                visual.BindingGeneric.Children.Add(new AdaptiveImage()
                {
                    Source = imageSource
                });
            }

            // Construct the actions for the toast (inputs and buttons)
            var actions = new ToastActionsCustom();

            // Add any inputs
            if (arguments.Inputs != null)
            {
                foreach (var input in arguments.Inputs)
                {
                    var textBox = new ToastTextBox(input.Id)
                    {
                        PlaceholderContent = input.PlaceHolderText
                    };

                    if (!string.IsNullOrWhiteSpace(input.Title))
                    {
                        textBox.Title = input.Title;
                    }
                    actions.Inputs.Add(textBox);
                }
            }

            // Add any buttons
            if (arguments.Buttons != null)
            {
                foreach (var button in arguments.Buttons)
                {
                    actions.Buttons.Add(new ToastButton(button.Text, button.Arguments));

                    //Background activation is not needed the COM activator decides whether
                    //to process in background or launch foreground window
                    //actions.Buttons.Add(new ToastButton(button.Text, button.Arguments)
                    //{
                    //	ActivationType = ToastActivationType.Background
                    //});
                }
            }

            //Set the audio
            ToastAudio audio = null;

            if (!string.IsNullOrWhiteSpace(arguments.WindowsSound) || !string.IsNullOrWhiteSpace(arguments.SoundPath))
            {
                string sound;
                if (string.IsNullOrWhiteSpace(arguments.WindowsSound))
                {
                    sound = "file:///" + arguments.SoundPath;
                }
                else
                {
                    sound = $"ms-winsoundevent:{arguments.WindowsSound}";
                }

                audio = new ToastAudio()
                {
                    Src    = new Uri(sound),
                    Loop   = bool.Parse(arguments.Loop),
                    Silent = arguments.Silent
                };
            }

            // Construct the toast content
            var toastContent = new ToastContent()
            {
                Visual  = visual,
                Actions = actions,
                Audio   = audio
            };

            // Create notification
            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(toastContent.GetContent());

            var toast = new ToastNotification(xmlDocument);

            // Set the expiration time
            if (!string.IsNullOrWhiteSpace(arguments.Duration))
            {
                switch (arguments.Duration)
                {
                case "short":
                    toast.ExpirationTime = DateTime.Now.AddSeconds(5);
                    break;

                case "long":
                    toast.ExpirationTime = DateTime.Now.AddSeconds(25);
                    break;
                }
            }

            //Add event handlers
            var events = new NotificationEvents();

            toast.Activated += events.Activated;
            toast.Dismissed += events.Dismissed;
            toast.Failed    += events.Failed;

            //Show notification
            DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast);

            return(toast);
        }
Ejemplo n.º 16
0
        public void pushNotification(dynamic tootNotification /*, int type*/)
        {
            String typeStr = tootNotification["type"];

            if (typeStr == null)
            {
                return;
            }

            if (typeStr == "favourite")
            {
                typeStr = "favorited your post";
            }
            else if (typeStr == "mention")
            {
                typeStr = "mentioned you";
            }
            else if (typeStr == "reblog")
            {
                typeStr = "boosted you";
            }
            else
            {
                Console.WriteLine("Unhandled type: " + typeStr);
                return;
            }

            /*if (type == 0)
             *  typeStr = "mentioned you.";
             * else if (type == 1)
             *  typeStr = "sent you a direct message.";
             * dynamic user;
             * if (type == 1)
             *  user = tootNotification["sender"];
             * else
             *  user = tootNotification["account"];*/

            dynamic user = tootNotification["account"];

            dynamic toot = tootNotification["status"];

            String content = toot["content"];

            content = Regex.Replace(content, "<.*?>", String.Empty);

            if (currentOS.IsEqualTo(OsVersion.Win7))
            {
                WPFGrowlNotification.Notification notification = new WPFGrowlNotification.Notification
                {
                    Title    = (String)user["display_name"] + " (" + "@" + (String)user["acct"] + ") " + typeStr,
                    ImageUrl = ((String)user["avatar"]),
                    Message  = content
                };
                growlNotifications.AddNotification(notification);
                PlaySound();
            }
            else
            {
                // Construct notification
                WebClient webClient = new WebClient();
                String    tempFile  = Path.GetTempFileName();
                webClient.DownloadFileCompleted += (sender, e) =>
                {
                    ToastVisual visual = new ToastVisual()
                    {
                        BindingGeneric = new ToastBindingGeneric()
                        {
                            Children =
                            {
                                new AdaptiveText()
                                {
                                    Text         = (String)user["display_name"] + " " + typeStr,
                                    HintMaxLines = 3
                                },

                                new AdaptiveText()
                                {
                                    Text = WebUtility.HtmlDecode(content)
                                }
                            },

                            /*Attribution = new ToastGenericAttributionText()
                             * {
                             *  Text = $"Via {(String)toot["application"]["name"]}"
                             * },*/

                            AppLogoOverride = new ToastGenericAppLogo()
                            {
                                Source   = tempFile,
                                HintCrop = ToastGenericAppLogoCrop.Circle
                            }
                        }
                    };

                    ToastAudio toastAudio = new ToastAudio();
                    toastAudio.Src = new Uri("pack://*****:*****@" + (String)user["screen_name"];
             * notification.tootCell.userHandle = (String)user["screen_name"];
             *
             * notification.tootCell.tootText.Text = WebUtility.HtmlDecode((String)tootNotification["text"]);
             *
             * BitmapImage profilePic = new BitmapImage();
             * profilePic.BeginInit();
             * profilePic.UriSource = ImageURL;
             * profilePic.CacheOption = BitmapCacheOption.OnLoad;
             * profilePic.EndInit();
             * notification.tootCell.profilePic.Source = profilePic;
             *
             * notification.tootCell.tootText.Arrange(new Rect(0, 0, notification.tootCell.tootText.Width, 1000));
             * double pageHeight = notification.tootCell.tootText.DesiredSize.Height;
             * //cell.tootText.Height = pageHeight + 10;
             * notification.tootCell.Height = 10 + pageHeight;
             * notification.Height = notification.tootCell.Height + 24;
             *
             * Rect desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
             * if (notifications.Count > 0)
             *  notification.Top = notifications[notifications.Count - 1].Top - (notifications[notifications.Count - 1].ActualHeight + 5);
             * else
             *  notification.Top = desktopWorkingArea.Height - (notification.Height + 40);
             * notification.Left = desktopWorkingArea.Width - notification.Width;
             *
             * Console.WriteLine("Showing notification!");
             *
             * notification.Show();
             * notifications.Add(notification);*/
        }
Ejemplo n.º 17
0
		private static AudioOption CheckAudio(ToastAudio audio)
		{
			switch (audio)
			{
				case ToastAudio.Silent:
					return AudioOption.Silent;

				case ToastAudio.Default:
				case ToastAudio.IM:
				case ToastAudio.Mail:
				case ToastAudio.Reminder:
				case ToastAudio.SMS:
					return AudioOption.Short;

				default:
					return AudioOption.Long;
			}
		}
Ejemplo n.º 18
0
		private static string GetAudio(ToastAudio audio)
		{
			return String.Format("ms-winsoundevent:Notification.{0}", audio.ToString().ToCamelWithSeparator('.'));
		}
Ejemplo n.º 19
0
        /// <summary>
        /// Show toast notification.
        /// </summary>
        /// <param name="arguments">Notification arguments object.</param>
        /// <returns>Toast notification object.</returns>
        public static ToastNotification ShowToast(NotificationArguments arguments)
        {
            var notifier  = ToastNotificationManager.CreateToastNotifier(arguments.ApplicationId);
            var scheduled = notifier.GetScheduledToastNotifications();

            for (var i = 0; i < scheduled.Count; i++)
            {
                // The itemId value is the unique ScheduledTileNotification.Id assigned to the notification when it was created.
                if (scheduled[i].Id == "")
                {
                    notifier.RemoveFromSchedule(scheduled[i]);
                }
            }

            //Set the toast visual
            var visual = new ToastVisual()
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText()
                        {
                            Text = arguments.Title
                        },
                        new AdaptiveText()
                        {
                            Text = arguments.Message
                        }
                    }
                }
            };

            //Set the image
            var imagePath = Globals.GetImageOrDefault(arguments.PicturePath);

            visual.BindingGeneric.AppLogoOverride = new ToastGenericAppLogo()
            {
                Source   = imagePath,
                HintCrop = ToastGenericAppLogoCrop.Circle
            };

            // Construct the actions for the toast (inputs and buttons)

            var actions = new ToastActionsCustom();

            // Add any inputs
            foreach (var input in arguments.Inputs)
            {
                actions.Inputs.Add(
                    new ToastTextBox(input.Id)
                {
                    Title = input.Title,
                    PlaceholderContent = input.PlaceHolderText
                });
            }

            // Add any buttons
            foreach (var button in arguments.Buttons)
            {
                actions.Buttons.Add(
                    new ToastButton(button.Text, new QueryString()
                {
                    { "Notification ID", arguments.NotificationId },
                    { "Button ID", button.Id },
                    { "Arguments", button.Arguments }
                }.ToString())
                {
                    ActivationType = ToastActivationType.Background
                });
            }

            //Set the audio
            ToastAudio audio = null;

            if (!string.IsNullOrWhiteSpace(arguments.WindowsSound) || !string.IsNullOrWhiteSpace(arguments.SoundPath))
            {
                string sound;
                if (string.IsNullOrWhiteSpace(arguments.WindowsSound))
                {
                    sound = "file:///" + arguments.SoundPath;
                }
                else
                {
                    sound = $"ms-winsoundevent:{arguments.WindowsSound}";
                }

                audio = new ToastAudio()
                {
                    Src    = new Uri(sound),
                    Loop   = bool.Parse(arguments.Loop),
                    Silent = arguments.Silent
                };
            }

            // Construct the toast content
            var toastContent = new ToastContent()
            {
                Visual  = visual,
                Actions = actions,
                Audio   = audio
            };

            // Create notification
            var toast = new ToastNotification(toastContent.GetXml());

            // Set the expiration time
            if (!string.IsNullOrWhiteSpace(arguments.Duration))
            {
                switch (arguments.Duration)
                {
                case "short":
                    toast.ExpirationTime = DateTime.Now.AddSeconds(5);
                    break;

                case "long":
                    toast.ExpirationTime = DateTime.Now.AddSeconds(25);
                    break;
                }
            }

            //Add event handlers
            var events = new NotificationEvents();

            toast.Activated += events.Activated;
            toast.Dismissed += events.Dismissed;
            toast.Failed    += events.Failed;

            //Show notification
            ToastNotificationManager.CreateToastNotifier().Show(toast);

            return(toast);
        }
Ejemplo n.º 20
0
        public void ChangeDevice(List <IAudioDevice> activeDevices, List <AudioDeviceMBState> deviceMBStateList)
        {
            if (deviceMBStateList.Count == 0)
            {
                return;
            }

            // refresh devices on state list
            foreach (var device in deviceMBStateList)
            {
                try
                {
                    device.AudioDevice = activeDevices.Where(x => x.Id == device.Id).First();
                }
                catch
                {
                    Console.WriteLine($"Couldn't find device {device.Name} in active device list");
                }
            }

            // get system default
            var mbDeviceStateQueue           = new Queue <AudioDeviceMBState>(deviceMBStateList.ToArray());
            AudioDeviceMBState mbDeviceState = null;

            do
            {
                mbDeviceState = mbDeviceStateQueue.Dequeue();
                mbDeviceStateQueue.Enqueue(mbDeviceState);
            } while (!mbDeviceState.AudioDevice.IsDefault(Role.Console));

            AudioDeviceMBState deviceToSetDefault = mbDeviceStateQueue.First();

            foreach (var device in mbDeviceStateQueue)
            {
                if (device.InRotation)
                {
                    deviceToSetDefault = device;
                    break;
                }
            }

            deviceToSetDefault.AudioDevice.SetAsDefault(Role.Console);

            try
            {
                ToastAudio toastAudio = new ToastAudio();
                if (PlayChimeOnChange)
                {
                    toastAudio.Src = new Uri("ms-appx:///chime.wav");
                }
                else
                {
                    toastAudio.Silent = true;
                }

                ToastContent toastContent = new ToastContentBuilder()
                                            .AddText($"{(_playDevices == deviceMBStateList ? "Device" : "Input device")} changed: {deviceToSetDefault.AudioDevice.FriendlyName}")
                                            .AddAudio(toastAudio)
                                            .GetToastContent();

                // And create the toast notification
                var toast = new ToastNotification(toastContent.GetXml())
                {
                    Tag            = "ChangedDevice",
                    ExpirationTime = DateTime.Now.AddSeconds(10)
                };

                // And then show it
                ToastNotificationManagerCompat.CreateToastNotifier().Show(toast);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Exception {e}");
            }
        }
Ejemplo n.º 21
0
        public static void Toast(string title, string content,
                                 string buttonText    = null, string buttonActionName = "",
                                 string propertyName  = "", string propertyValue      = "",
                                 string propertyName2 = "", string propertyValue2     = "",
                                 ToastActivationType toastActivationType = ToastActivationType.Foreground,
                                 bool silent = false)
        {
            // Construct the visuals of the toast
            ToastVisual visual = new ToastVisual()
            {
                BindingGeneric = new ToastBindingGeneric()
                {
                    Children =
                    {
                        new AdaptiveText {
                            Text = title
                        },
                        new AdaptiveText {
                            Text = content
                        },
                    },
                }
            };

            ToastActionsCustom actions = null;

            if (!string.IsNullOrEmpty(buttonText))
            {
                // Construct the actions for the toast (inputs and buttons)
                actions = new ToastActionsCustom()
                {
                    Buttons =
                    {
                        new ToastButton(buttonText, new QueryString()
                        {
                            { "action",             buttonActionName},
                            { propertyName,         propertyValue  },
                            { propertyName2,        propertyValue2 },
                        }.ToString())
                        {
                            ActivationType = toastActivationType
                        }
                    }
                };
            }

            ToastAudio audio = new ToastAudio
            {
                Silent = silent
            };

            // Now we can construct the final toast content
            ToastContent toastContent = new ToastContent()
            {
                Visual  = visual,
                Actions = actions,
                Audio   = audio
            };

            // And create the toast notification
            var toast = new ToastNotification(toastContent.GetXml());

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
        public void Test_Toast_Xml_Audio_Defaults()
        {
            var audio = new ToastAudio();

            AssertAudioPayload("<audio />", audio);
        }