コード例 #1
0
        public static SynchronousToastNotificationManager FromBuilder(ToastNotificationBuilder toastNotificationBuilder, Action <ToastNotification> configureNotification = null)
        {
            var notification = toastNotificationBuilder.BuildToastNotification();

            configureNotification?.Invoke(notification);
            return(new SynchronousToastNotificationManager(notification));
        }
コード例 #2
0
        private static void UpdateSoundSelection(string soundParameter, bool loop, ToastNotificationBuilder builder)
        {
            if (string.IsNullOrWhiteSpace(soundParameter))
            {
                return;
            }

            if (_pseudoSoundNamesForDisabled.Any(x => string.Equals(x, soundParameter, StringComparison.OrdinalIgnoreCase)))
            {
                builder.SetDisableSound();
                return;
            }

            builder.SetSoundLooping(loop);
            string sound            = soundParameter;
            ushort variant          = 1;
            bool   variantSpecified = false;

            if (soundParameter.Contains(";"))
            {
                var soundParts = soundParameter.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                sound = soundParts[0];
                if (soundParts.Length > 1)
                {
                    variantSpecified = true;
                    if (!ushort.TryParse(soundParts[1], out variant))
                    {
                        throw new ArgumentException($"Invalid sound variant '{soundParts[1]}' specified!", nameof(soundParameter));
                    }
                }
            }

            if (Enum.TryParse <ToastNotificationBuilder.VariableSounds>(sound, true, out var selectedLooping))
            {
                builder.SetSound(selectedLooping, variant);
                return;
            }

            if (variantSpecified)
            {
                throw new ArgumentException($"You can not specify a variant for the sound '{sound}'");
            }
            if (Enum.TryParse <ToastNotificationBuilder.Sounds>(sound, true, out var selected))
            {
                builder.SetSound(selected);
            }
            else
            {
                throw new ArgumentException($"The specified sound '{sound}' is invalid", nameof(soundParameter));
            }
        }