Toasts – Diff between revs 3 and 8

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 3 Rev 8
Line 1... Line 1...
1 using System; 1 using System;
2 using System.Drawing; 2 using System.Drawing;
3 using System.IO; 3 using System.IO;
4 using System.Media; 4 using System.Media;
-   5 using System.Reflection;
-   6 using System.Threading.Tasks;
5 using System.Windows.Forms; 7 using System.Windows.Forms;
6 using Toasts; 8 using Toasts;
Line 7... Line 9...
7   9  
8 namespace Test 10 namespace Test
9 { 11 {
10 public partial class Test : Form 12 public partial class TestForm : Form
11 { 13 {
Line 12... Line 14...
12 #region Private Delegates, Events, Enums, Properties, Indexers and Fields 14 #region Private Delegates, Events, Enums, Properties, Indexers and Fields
Line 13... Line 15...
13   15  
Line 14... Line 16...
14 private bool _initialLoad = true; 16 private bool _initialLoad = true;
Line 15... Line 17...
15   17  
16 #endregion 18 #endregion
17   19  
18 #region Constructors, Destructors and Finalizers 20 #region Constructors, Destructors and Finalizers
19   21  
Line 30... Line 32...
30 private void ButtonShowNotification_Click(object sender, EventArgs e) 32 private void ButtonShowNotification_Click(object sender, EventArgs e)
31 { 33 {
32 ShowNotification(); 34 ShowNotification();
33 } 35 }
Line 34... Line 36...
34   36  
35 private void ComboBoxSound_SelectedIndexChanged(object sender, EventArgs e) 37 private async void ComboBoxSound_SelectedIndexChanged(object sender, EventArgs e)
-   38 {
-   39 if (!_initialLoad)
36 { 40 {
-   41 await PlayNotificationSound($"Test.Sounds.{comboBoxSound.Text}.wav");
37 if (!_initialLoad) PlayNotificationSound(comboBoxSound.Text); 42 }
Line 38... Line 43...
38 } 43 }
Line 39... Line 44...
39   44  
Line 62... Line 67...
62 _initialLoad = false; 67 _initialLoad = false;
Line 63... Line 68...
63   68  
64 comboBoxDuration.SelectedIndex = 0; 69 comboBoxDuration.SelectedIndex = 0;
Line 65... Line 70...
65 } 70 }
66   71  
67 private void ShowNotification() 72 private async void ShowNotification()
68 { 73 {
69 int duration; 74 int duration;
Line 93... Line 98...
93 var background = new Bitmap(backgroundFile); 98 var background = new Bitmap(backgroundFile);
Line 94... Line 99...
94   99  
95 var logoFile = Path.Combine(imagesFolder, "was.png"); 100 var logoFile = Path.Combine(imagesFolder, "was.png");
Line -... Line 101...
-   101 var logo = new Bitmap(logoFile);
-   102  
96 var logo = new Bitmap(logoFile); 103 var sound = await LoadResource($"Test.Sounds.{comboBoxSound.Text}.wav");
97   104  
98 var toastNotification = new ToastForm(textBoxTitle.Text, textBoxBody.Text, duration, -  
-   105 var toastNotification = new ToastForm(textBoxTitle.Text, textBoxBody.Text, duration,
99 logo, background, animationMethod, animationDirection); 106 logo, background, sound, animationMethod, animationDirection);
100 PlayNotificationSound(comboBoxSound.Text); 107
Line 101... Line 108...
101 toastNotification.Show(); 108 toastNotification.Show();
102 } 109 }
103   -  
104 private static void PlayNotificationSound(string sound) 110  
Line 105... Line 111...
105 { 111 private static async Task<byte[]> LoadResource(string resource)
106 var soundsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sounds"); 112 {
-   113 var assembly = Assembly.GetExecutingAssembly();
-   114  
-   115 using (var manifestResourceStream = assembly.GetManifestResourceStream(resource))
-   116 {
-   117 if (manifestResourceStream == null)
-   118 {
-   119 return null;
-   120 }
-   121  
-   122 var memoryStream = new MemoryStream();
-   123  
-   124 await manifestResourceStream.CopyToAsync(memoryStream);
-   125  
-   126 memoryStream.Position = 0L;
-   127  
-   128 return memoryStream.ToArray();
-   129 }
-   130 }
-   131  
-   132 private static async Task PlayNotificationSound(string sound)
-   133 {
-   134 var resource = await LoadResource(sound);
-   135  
107 var soundFile = Path.Combine(soundsFolder, sound + ".wav"); 136 using (var memoryStream = new MemoryStream(resource))
-   137 {
108   138 using (var player = new SoundPlayer(memoryStream))
109 using (var player = new SoundPlayer(soundFile)) 139 {
Line 110... Line 140...
110 { 140 player.Play();
111 player.Play(); 141 }