-
-
Notifications
You must be signed in to change notification settings - Fork 144
Expand file tree
/
Copy pathMainPage.cs
More file actions
196 lines (173 loc) · 7.74 KB
/
Copy pathMainPage.cs
File metadata and controls
196 lines (173 loc) · 7.74 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
using Microsoft.Maui.Controls.Shapes;
namespace Exceptionless.SampleMaui;
public sealed class MainPage : ContentPage {
private readonly ExceptionlessClient _exceptionlessClient;
private readonly SampleEventService _sampleEvents;
private readonly Label _statusLabel;
private readonly Label _lastReferenceIdLabel;
private readonly Label _configLabel;
private readonly ActivityIndicator _activityIndicator;
public MainPage(ExceptionlessClient exceptionlessClient, SampleEventService sampleEvents) {
_exceptionlessClient = exceptionlessClient;
_sampleEvents = sampleEvents;
Title = "Exceptionless";
BackgroundColor = Color.FromArgb("#F6F8FA");
_statusLabel = new Label {
Text = "Ready",
FontSize = 14,
TextColor = Color.FromArgb("#314256"),
LineBreakMode = LineBreakMode.WordWrap
};
_lastReferenceIdLabel = new Label {
Text = "Last reference id: none",
FontSize = 13,
TextColor = Color.FromArgb("#576575"),
LineBreakMode = LineBreakMode.TailTruncation
};
_configLabel = new Label {
Text = $"Config {SampleEventService.SampleConfigSettingKey}: not loaded",
FontSize = 13,
TextColor = Color.FromArgb("#576575"),
LineBreakMode = LineBreakMode.TailTruncation
};
_activityIndicator = new ActivityIndicator {
IsVisible = false,
Color = Color.FromArgb("#276749")
};
Content = BuildContent();
}
private View BuildContent() {
var refreshConfigButton = CreateActionButton("Refresh Config", OnRefreshConfigClicked);
var sendExceptionButton = CreateActionButton("Send Handled Exception", OnSendExceptionClicked);
var sendLogButton = CreateActionButton("Send Warning Log", OnSendLogClicked);
var trackFeatureButton = CreateActionButton("Track Feature", OnTrackFeatureClicked);
var flushButton = CreateActionButton("Flush Queue", OnFlushClicked);
return new ScrollView {
Content = new VerticalStackLayout {
Padding = new Thickness(24, 28),
Spacing = 18,
Children = {
new Label {
Text = "Exceptionless MAUI Sample",
FontSize = 26,
FontAttributes = FontAttributes.Bold,
TextColor = Color.FromArgb("#1D2733")
},
new Label {
Text = "Submit sample events through the core Exceptionless client.",
FontSize = 15,
TextColor = Color.FromArgb("#576575"),
LineBreakMode = LineBreakMode.WordWrap
},
new Border {
Stroke = Color.FromArgb("#D8DEE6"),
StrokeThickness = 1,
BackgroundColor = Colors.White,
StrokeShape = new RoundRectangle { CornerRadius = 8 },
Padding = new Thickness(18),
Content = new VerticalStackLayout {
Spacing = 12,
Children = {
new Label {
Text = "Client",
FontSize = 18,
FontAttributes = FontAttributes.Bold,
TextColor = Color.FromArgb("#1D2733")
},
new Label {
Text = $"Server: {_exceptionlessClient.Configuration.ServerUrl}",
FontSize = 13,
TextColor = Color.FromArgb("#576575"),
LineBreakMode = LineBreakMode.TailTruncation
},
new Label {
Text = $"Private information: {_exceptionlessClient.Configuration.IncludePrivateInformation}",
FontSize = 13,
TextColor = Color.FromArgb("#576575")
},
_statusLabel,
_lastReferenceIdLabel,
_configLabel,
_activityIndicator
}
}
},
new VerticalStackLayout {
Spacing = 12,
Children = {
refreshConfigButton,
sendExceptionButton,
sendLogButton,
trackFeatureButton,
flushButton
}
}
}
}
};
}
private static Button CreateActionButton(string text, EventHandler clicked) {
var button = new Button {
Text = text,
BackgroundColor = Color.FromArgb("#285A84"),
TextColor = Colors.White,
CornerRadius = 8,
FontAttributes = FontAttributes.Bold,
MinimumHeightRequest = 48
};
button.Clicked += clicked;
return button;
}
private async void OnRefreshConfigClicked(object? sender, EventArgs e) {
await RunClientActionAsync("Configuration refreshed.", async () => {
await _sampleEvents.RefreshProjectConfigurationAsync();
SetConfigValue(_sampleEvents.GetSampleConfigValue());
});
}
private async void OnSendExceptionClicked(object? sender, EventArgs e) {
await RunClientActionAsync("Handled exception queued.", () => {
string referenceId = _sampleEvents.SubmitHandledException();
SetLastReferenceId(referenceId);
return Task.CompletedTask;
});
}
private async void OnSendLogClicked(object? sender, EventArgs e) {
await RunClientActionAsync("Warning log queued.", () => {
SetLastReferenceId(_sampleEvents.SubmitWarningLog());
return Task.CompletedTask;
});
}
private async void OnTrackFeatureClicked(object? sender, EventArgs e) {
await RunClientActionAsync("Feature usage queued.", () => {
SetLastReferenceId(_sampleEvents.TrackFeatureUsage());
return Task.CompletedTask;
});
}
private async void OnFlushClicked(object? sender, EventArgs e) {
await RunClientActionAsync("Queue processed.", () => _sampleEvents.FlushQueueAsync());
}
private async Task RunClientActionAsync(string successMessage, Func<Task> action) {
try {
_activityIndicator.IsVisible = true;
_activityIndicator.IsRunning = true;
_statusLabel.Text = "Working...";
await action();
_statusLabel.Text = successMessage;
} catch (InvalidOperationException ex) {
_statusLabel.Text = $"Error: {ex.Message}";
} catch (TaskCanceledException ex) {
_statusLabel.Text = $"Error: {ex.Message}";
} finally {
_activityIndicator.IsRunning = false;
_activityIndicator.IsVisible = false;
}
}
private void SetLastReferenceId(string? referenceId) {
_lastReferenceIdLabel.Text = String.IsNullOrEmpty(referenceId)
? "Last reference id: none"
: $"Last reference id: {referenceId}";
}
private void SetConfigValue(string value) {
_configLabel.Text = $"Config {SampleEventService.SampleConfigSettingKey}: {value}";
}
}