Toasts – Blame information for rev 29
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | using System; |
2 | using System.Drawing; |
||
3 | using System.IO; |
||
4 | using System.Media; |
||
8 | office | 5 | using System.Reflection; |
6 | using System.Threading.Tasks; |
||
1 | office | 7 | using System.Windows.Forms; |
8 | using Toasts; |
||
9 | |||
10 | namespace Test |
||
11 | { |
||
8 | office | 12 | public partial class TestForm : Form |
1 | office | 13 | { |
14 | #region Private Delegates, Events, Enums, Properties, Indexers and Fields |
||
15 | |||
16 | private bool _initialLoad = true; |
||
17 | |||
18 | #endregion |
||
19 | |||
20 | #region Constructors, Destructors and Finalizers |
||
21 | |||
8 | office | 22 | public TestForm() |
1 | office | 23 | { |
24 | InitializeComponent(); |
||
25 | PopulateComboBoxes(); |
||
26 | } |
||
27 | |||
28 | #endregion |
||
29 | |||
30 | #region Event Handlers |
||
31 | |||
32 | private void ButtonShowNotification_Click(object sender, EventArgs e) |
||
33 | { |
||
34 | ShowNotification(); |
||
35 | } |
||
36 | |||
8 | office | 37 | private async void ComboBoxSound_SelectedIndexChanged(object sender, EventArgs e) |
1 | office | 38 | { |
8 | office | 39 | if (!_initialLoad) |
40 | { |
||
41 | await PlayNotificationSound($"Test.Sounds.{comboBoxSound.Text}.wav"); |
||
42 | } |
||
1 | office | 43 | } |
44 | |||
45 | #endregion |
||
46 | |||
47 | #region Private Methods |
||
48 | |||
49 | private void PopulateComboBoxes() |
||
50 | { |
||
51 | foreach (FormAnimator.AnimationMethod method in Enum.GetValues(typeof(FormAnimator.AnimationMethod))) |
||
52 | comboBoxAnimation.Items.Add(method.ToString()); |
||
53 | |||
54 | comboBoxAnimation.SelectedIndex = 2; |
||
55 | |||
56 | foreach (FormAnimator.AnimationDirection direction in Enum.GetValues( |
||
57 | typeof(FormAnimator.AnimationDirection))) |
||
58 | comboBoxAnimationDirection.Items.Add(direction.ToString()); |
||
59 | |||
60 | comboBoxAnimationDirection.SelectedIndex = 3; |
||
61 | |||
62 | var soundsFolder = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sounds")); |
||
63 | foreach (var file in soundsFolder.GetFiles()) |
||
64 | comboBoxSound.Items.Add(Path.GetFileNameWithoutExtension(file.FullName)); |
||
65 | |||
66 | comboBoxSound.SelectedIndex = 5; |
||
67 | _initialLoad = false; |
||
68 | |||
69 | comboBoxDuration.SelectedIndex = 0; |
||
70 | } |
||
71 | |||
8 | office | 72 | private async void ShowNotification() |
1 | office | 73 | { |
74 | int duration; |
||
75 | int.TryParse(comboBoxDuration.SelectedItem.ToString(), out duration); |
||
76 | if (duration <= 0) duration = -1; |
||
77 | |||
78 | var animationMethod = FormAnimator.AnimationMethod.Slide; |
||
79 | foreach (FormAnimator.AnimationMethod method in Enum.GetValues(typeof(FormAnimator.AnimationMethod))) |
||
80 | if (Equals(method.ToString(), comboBoxAnimation.SelectedItem)) |
||
81 | { |
||
82 | animationMethod = method; |
||
83 | break; |
||
84 | } |
||
85 | |||
86 | var animationDirection = FormAnimator.AnimationDirection.Up; |
||
87 | foreach (FormAnimator.AnimationDirection direction in Enum.GetValues( |
||
88 | typeof(FormAnimator.AnimationDirection))) |
||
89 | if (Equals(direction.ToString(), comboBoxAnimationDirection.SelectedItem)) |
||
90 | { |
||
91 | animationDirection = direction; |
||
92 | break; |
||
93 | } |
||
94 | |||
95 | var imagesFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images"); |
||
96 | |||
97 | var backgroundFile = Path.Combine(imagesFolder, "background.png"); |
||
98 | var background = new Bitmap(backgroundFile); |
||
99 | |||
100 | var logoFile = Path.Combine(imagesFolder, "was.png"); |
||
101 | var logo = new Bitmap(logoFile); |
||
102 | |||
8 | office | 103 | var sound = await LoadResource($"Test.Sounds.{comboBoxSound.Text}.wav"); |
104 | |||
29 | office | 105 | var toastNotification = new ToastForm(textBoxTitle.Text, textBoxBody.Text); |
8 | office | 106 | |
1 | office | 107 | toastNotification.Show(); |
108 | } |
||
109 | |||
8 | office | 110 | private static async Task<byte[]> LoadResource(string resource) |
1 | office | 111 | { |
8 | office | 112 | var assembly = Assembly.GetExecutingAssembly(); |
1 | office | 113 | |
8 | office | 114 | using (var manifestResourceStream = assembly.GetManifestResourceStream(resource)) |
1 | office | 115 | { |
8 | office | 116 | if (manifestResourceStream == null) |
117 | { |
||
118 | return null; |
||
119 | } |
||
120 | |||
121 | var memoryStream = new MemoryStream(); |
||
122 | |||
123 | await manifestResourceStream.CopyToAsync(memoryStream); |
||
124 | |||
125 | memoryStream.Position = 0L; |
||
126 | |||
127 | return memoryStream.ToArray(); |
||
1 | office | 128 | } |
129 | } |
||
130 | |||
8 | office | 131 | private static async Task PlayNotificationSound(string sound) |
132 | { |
||
133 | var resource = await LoadResource(sound); |
||
134 | |||
135 | using (var memoryStream = new MemoryStream(resource)) |
||
136 | { |
||
137 | using (var player = new SoundPlayer(memoryStream)) |
||
138 | { |
||
139 | player.Play(); |
||
140 | } |
||
141 | } |
||
142 | } |
||
143 | |||
1 | office | 144 | #endregion |
145 | } |
||
146 | } |