-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathListViewEventSink.cs
More file actions
100 lines (84 loc) · 2.82 KB
/
ListViewEventSink.cs
File metadata and controls
100 lines (84 loc) · 2.82 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Threading.Tasks;
using Waher.Events;
using Windows.UI;
using Windows.UI.Xaml.Controls;
namespace Waher.Mock
{
/// <summary>
/// Event sink displaying incoming events in a ListView component.
/// </summary>
public class ListViewEventSink : EventSink
{
private readonly ListView listView;
private int maxItems = 1000;
/// <summary>
/// Event sink displaying incoming events in a ListView component.
/// </summary>
/// <param name="ObjectID">Object ID.</param>
/// <param name="ListView">Component receiving logged events.</param>
public ListViewEventSink(string ObjectID, ListView ListView)
: base(ObjectID)
{
this.listView = ListView;
}
/// <summary>
/// Component receiving logged events.
/// </summary>
public ListView ListView => this.listView;
/// <summary>
/// Maximum number of items in the list view.
/// </summary>
public int MaxItems
{
get => this.maxItems;
set => this.maxItems = value;
}
private async void Add(SniffItem SniffItem)
{
await this.listView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
int c;
this.listView.Items.Insert(0, SniffItem);
c = this.listView.Items.Count;
while (c > this.maxItems)
this.listView.Items.RemoveAt(--c);
});
}
/// <summary>
/// Queues an event to be output.
/// </summary>
/// <param name="Event">Event to queue.</param>
public override Task Queue(Event Event)
{
switch (Event.Type)
{
case EventType.Debug:
this.Add(new SniffItem(Event.Timestamp, SniffItemType.Information, Event.Message, null, Colors.White, Colors.Indigo));
break;
case EventType.Informational:
this.Add(new SniffItem(Event.Timestamp, SniffItemType.Information, Event.Message, null, Colors.Black, Colors.White));
break;
case EventType.Notice:
this.Add(new SniffItem(Event.Timestamp, SniffItemType.Information, Event.Message, null, Colors.Black, Colors.LemonChiffon));
break;
case EventType.Warning:
this.Add(new SniffItem(Event.Timestamp, SniffItemType.Information, Event.Message, null, Colors.Black, Colors.Yellow));
break;
case EventType.Error:
this.Add(new SniffItem(Event.Timestamp, SniffItemType.Information, Event.Message, null, Colors.White, Colors.IndianRed));
break;
case EventType.Critical:
this.Add(new SniffItem(Event.Timestamp, SniffItemType.Information, Event.Message, null, Colors.White, Colors.Crimson));
break;
case EventType.Alert:
this.Add(new SniffItem(Event.Timestamp, SniffItemType.Information, Event.Message, null, Colors.White, Colors.Maroon));
break;
case EventType.Emergency:
this.Add(new SniffItem(Event.Timestamp, SniffItemType.Information, Event.Message, null, Colors.White, Colors.Black));
break;
}
return Task.CompletedTask;
}
}
}