/// <summary> /// Initializes a new instance of the <see cref="TimerOptions"/> class. /// </summary> public TimerOptions() { this.title = string.Empty; this.alwaysOnTop = false; this.loopTimer = false; this.popUpWhenExpired = true; this.closeWhenExpired = false; this.color = Color.DefaultColor; this.sound = Sound.DefaultSound; this.loopSound = false; this.windowSize = new WindowSize( new Rect(double.PositiveInfinity, double.PositiveInfinity, 350, 150), WindowState.Normal, WindowState.Normal, false /* isFullScreen */); }
/// <summary> /// Plays a <see cref="Sound"/> asynchronously. /// </summary> /// <param name="sound">A <see cref="Sound"/>.</param> /// <param name="loop">A value indicating whether playback should be looped.</param> /// <returns><c>true</c> if the <see cref="Sound"/> plays successfully, or <c>false</c> otherwise.</returns> public bool Play(Sound sound, bool loop) { this.ThrowIfDisposed(); // Stop all playback if (!this.Stop()) { return false; } // Do not play nothing if (sound == null) { return true; } try { this.IsPlaying = true; this.IsLooping = loop; if (sound.IsBuiltIn) { // Use the sound player this.soundPlayer.Stream = sound.GetStream(); if (loop) { // Asynchronously play looping sound this.soundPlayer.PlayLooping(); } else { // Asynchronously play sound once this.soundPlayer.Play(); // Start a timer to notify the completion of playback if we know the duration if (sound.Duration.HasValue) { this.dispatcherTimer.Interval = sound.Duration.Value; this.dispatcherTimer.Start(); } } } else { // Use the media player this.mediaPlayer.Open(new Uri(sound.Path)); this.mediaPlayer.Play(); } } catch { return false; } // Raise an event this.OnPlaybackStarted(); return true; }
/// <summary> /// Sets all of the options from an instance of the <see cref="TimerOptionsInfo"/> class. /// </summary> /// <param name="info">A <see cref="TimerOptionsInfo"/>.</param> public void Set(TimerOptionsInfo info) { if (info == null) { throw new ArgumentNullException("info"); } this.title = info.Title; this.alwaysOnTop = info.AlwaysOnTop; this.promptOnExit = info.PromptOnExit; this.doNotKeepComputerAwake = info.DoNotKeepComputerAwake; this.showTimeElapsed = info.ShowTimeElapsed; this.loopTimer = info.LoopTimer; this.popUpWhenExpired = info.PopUpWhenExpired; this.closeWhenExpired = info.CloseWhenExpired; this.shutDownWhenExpired = info.ShutDownWhenExpired; this.color = Color.FromIdentifier(info.ColorIdentifier); this.sound = Sound.FromIdentifier(info.SoundIdentifier); this.loopSound = info.LoopSound; this.windowSize = WindowSize.FromWindowSizeInfo(info.WindowSize); }
/// <summary> /// Sets all of the options from another instance of the <see cref="TimerOptions"/> class. /// </summary> /// <param name="options">A <see cref="TimerOptions"/>.</param> public void Set(TimerOptions options) { if (options == null) { throw new ArgumentNullException("options"); } this.title = options.title; this.alwaysOnTop = options.alwaysOnTop; this.promptOnExit = options.promptOnExit; this.doNotKeepComputerAwake = options.doNotKeepComputerAwake; this.showTimeElapsed = options.showTimeElapsed; this.loopTimer = options.loopTimer; this.popUpWhenExpired = options.popUpWhenExpired; this.closeWhenExpired = options.closeWhenExpired; this.shutDownWhenExpired = options.shutDownWhenExpired; this.color = options.color; this.sound = options.sound; this.loopSound = options.loopSound; this.windowSize = WindowSize.FromWindowSize(options.WindowSize); }
/// <summary> /// Returns the next <see cref="Sound"/> value in <paramref name="remainingArgs"/>, or throws an exception if /// <paramref name="remainingArgs"/> is empty or the next argument is not "none", "last", or a valid /// representation of a <see cref="Sound"/>. /// </summary> /// <param name="arg">The name of the argument for which the value is to be returned.</param> /// <param name="remainingArgs">The unparsed arguments.</param> /// <param name="last">The value of the argument returned when the user specifies "last".</param> /// <returns>The next <see cref="Sound"/> value in <paramref name="remainingArgs"/>.</returns> /// <exception cref="ParseException">if <paramref name="remainingArgs"/> is empty or the next argument is not /// "none", "last", or a valid representation of a <see cref="Sound"/>.</exception> private static Sound GetSoundValue(string arg, Queue<string> remainingArgs, Sound last) { string value = GetRequiredValue(arg, remainingArgs); switch (value) { case "none": return null; case "last": return last; default: Sound sound = SoundManager.Instance.GetSoundByName(value, StringComparison.CurrentCultureIgnoreCase); if (sound == null) { string message = string.Format( Resources.ResourceManager.GetEffectiveProvider(), Resources.CommandLineArgumentsParseExceptionInvalidValueForSwitchFormatString, arg, value); throw new ParseException(message); } return sound; } }
/// <summary> /// Creates a <see cref="MenuItem"/> for a <see cref="Sound"/>. /// </summary> /// <param name="sound">A <see cref="Sound"/>.</param> private void CreateSoundMenuItem(Sound sound) { MenuItem menuItem = new MenuItem(); menuItem.Header = sound != null ? sound.Name : Properties.Resources.ContextMenuNoSoundMenuItem; menuItem.Tag = sound; menuItem.IsCheckable = true; menuItem.Click += this.SoundMenuItemClick; menuItem.Click += this.CheckableMenuItemClick; this.soundMenuItem.Items.Add(menuItem); this.selectableSoundMenuItems.Add(menuItem); }
/// <summary> /// Sets all of the options from an instance of the <see cref="TimerOptionsInfo"/> class. /// </summary> /// <param name="info">A <see cref="TimerOptionsInfo"/>.</param> public void Set(TimerOptionsInfo info) { if (info == null) { throw new ArgumentNullException("info"); } this.title = info.Title; this.alwaysOnTop = info.AlwaysOnTop; this.promptOnExit = info.PromptOnExit; this.doNotKeepComputerAwake = info.DoNotKeepComputerAwake; this.showTimeElapsed = info.ShowTimeElapsed; this.loopTimer = info.LoopTimer; this.popUpWhenExpired = info.PopUpWhenExpired; this.closeWhenExpired = info.CloseWhenExpired; this.shutDownWhenExpired = info.ShutDownWhenExpired; this.theme = Theme.FromIdentifier(info.ThemeIdentifier); this.sound = Sound.FromIdentifier(info.SoundIdentifier); this.loopSound = info.LoopSound; this.windowTitleMode = info.WindowTitleMode; this.windowSize = WindowSize.FromWindowSizeInfo(info.WindowSize); this.OnPropertyChanged( "Title", "AlwaysOnTop", "PromptOnExit", "DoNotKeepComputerAwake", "ShowTimeElapsed", "LoopTimer", "PopUpWhenExpired", "CloseWhenExpired", "ShutDownWhenExpired", "Theme", "Sound", "LoopSound", "WindowTitleMode", "WindowSize"); }
/// <summary> /// Sets all of the options from another instance of the <see cref="TimerOptions"/> class. /// </summary> /// <param name="options">A <see cref="TimerOptions"/>.</param> public void Set(TimerOptions options) { if (options == null) { throw new ArgumentNullException("options"); } this.title = options.title; this.alwaysOnTop = options.alwaysOnTop; this.promptOnExit = options.promptOnExit; this.doNotKeepComputerAwake = options.doNotKeepComputerAwake; this.showTimeElapsed = options.showTimeElapsed; this.loopTimer = options.loopTimer; this.popUpWhenExpired = options.popUpWhenExpired; this.closeWhenExpired = options.closeWhenExpired; this.shutDownWhenExpired = options.shutDownWhenExpired; this.theme = options.theme; this.sound = options.sound; this.loopSound = options.loopSound; this.windowTitleMode = options.windowTitleMode; this.windowSize = WindowSize.FromWindowSize(options.WindowSize); this.OnPropertyChanged( "Title", "AlwaysOnTop", "PromptOnExit", "DoNotKeepComputerAwake", "ShowTimeElapsed", "LoopTimer", "PopUpWhenExpired", "CloseWhenExpired", "ShutDownWhenExpired", "Theme", "Sound", "LoopSound", "WindowTitleMode", "WindowSize"); }
/// <summary> /// Initializes a new instance of the <see cref="TimerOptions"/> class. /// </summary> public TimerOptions() { this.title = string.Empty; this.alwaysOnTop = false; this.promptOnExit = true; this.doNotKeepComputerAwake = false; this.showTimeElapsed = false; this.loopTimer = false; this.popUpWhenExpired = true; this.closeWhenExpired = false; this.shutDownWhenExpired = false; this.theme = Theme.DefaultTheme; this.sound = Sound.DefaultSound; this.loopSound = false; this.windowTitleMode = WindowTitleMode.ApplicationName; this.windowSize = new WindowSize( new Rect(double.PositiveInfinity, double.PositiveInfinity, 350, 150), WindowState.Normal, WindowState.Normal, false /* isFullScreen */); }
/// <summary> /// Sets all of the options from an instance of the <see cref="TimerOptionsInfo"/> class. /// </summary> /// <param name="info">A <see cref="TimerOptionsInfo"/>.</param> public void Set(TimerOptionsInfo info) { if (info == null) { throw new ArgumentNullException("info"); } this.title = info.Title; this.alwaysOnTop = info.AlwaysOnTop; this.loopTimer = info.LoopTimer; this.popUpWhenExpired = info.PopUpWhenExpired; this.closeWhenExpired = info.CloseWhenExpired; this.color = Color.FromIdentifier(info.ColorIdentifier); this.sound = Sound.FromIdentifier(info.SoundIdentifier); this.loopSound = info.LoopSound; this.windowSize = WindowSize.FromWindowSizeInfo(info.WindowSize); }
/// <summary> /// Sets all of the options from another instance of the <see cref="TimerOptions"/> class. /// </summary> /// <param name="options">A <see cref="TimerOptions"/>.</param> public void Set(TimerOptions options) { if (options == null) { throw new ArgumentNullException("options"); } this.title = options.title; this.alwaysOnTop = options.alwaysOnTop; this.loopTimer = options.loopTimer; this.popUpWhenExpired = options.popUpWhenExpired; this.closeWhenExpired = options.closeWhenExpired; this.color = options.color; this.sound = options.sound; this.loopSound = options.loopSound; this.windowSize = WindowSize.FromWindowSize(options.WindowSize); }