-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainViewModel.cs
More file actions
52 lines (47 loc) · 2.23 KB
/
MainViewModel.cs
File metadata and controls
52 lines (47 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Threading.Tasks;
using DevExpress.Mvvm;
namespace InteractiveNotifications {
public class MainViewModel {
protected virtual INotificationService NotificationService => null;
public int PredefinedNotificationId { get; set; }
protected MainViewModel() {
PredefinedNotificationId = 100;
}
public void ShowNotification() {
string text1 = "Lorem ipsum dolor sit amet integer fringilla, dui eget ultrices cursus, justo tellus.";
string text2 = "In ornare ante magna, eget volutpat mi bibendum a. Nam ut ullamcorper libero. Pellentesque habitant.";
string text3 = "Quisque sapien odio, mollis tincidunt est id, fringilla euismod neque. Aenean adipiscing lorem dui, nec. ";
INotification notification = NotificationService.CreatePredefinedNotification(text1, text2, text3, null, PredefinedNotificationId.ToString());
PredefinedNotificationId++;
Show(notification);
}
void Show(INotification notification) {
CreateLogLine("Showing...");
notification.ShowAsync().ContinueWith(OnNotificationShown, TaskScheduler.FromCurrentSynchronizationContext());
}
void OnNotificationShown(Task<NotificationResult> task) {
try {
switch(task.Result) {
case NotificationResult.Activated:
CreateLogLine("Activated");
break;
case NotificationResult.TimedOut:
CreateLogLine("Timed out");
break;
case NotificationResult.UserCanceled:
CreateLogLine("Canceled by user");
break;
case NotificationResult.Dropped:
CreateLogLine("Dropped (the queue is full)");
break;
}
} catch(AggregateException e) {
CreateLogLine("Error: " + e.InnerException.Message);
}
}
void CreateLogLine(string text) {
System.Diagnostics.Debug.WriteLine(text);
}
}
}