1- using Exceptionless . Logging ;
21using Microsoft . Maui . Controls . Shapes ;
32
43namespace Exceptionless . SampleMaui ;
54
65public sealed class MainPage : ContentPage {
76 private readonly ExceptionlessClient _exceptionlessClient ;
7+ private readonly SampleEventService _sampleEvents ;
88 private readonly Label _statusLabel ;
99 private readonly Label _lastReferenceIdLabel ;
10+ private readonly Label _configLabel ;
1011 private readonly ActivityIndicator _activityIndicator ;
1112
12- public MainPage ( ExceptionlessClient exceptionlessClient ) {
13+ public MainPage ( ExceptionlessClient exceptionlessClient , SampleEventService sampleEvents ) {
1314 _exceptionlessClient = exceptionlessClient ;
15+ _sampleEvents = sampleEvents ;
1416
1517 Title = "Exceptionless" ;
1618 BackgroundColor = Color . FromArgb ( "#F6F8FA" ) ;
@@ -29,6 +31,13 @@ public MainPage(ExceptionlessClient exceptionlessClient) {
2931 LineBreakMode = LineBreakMode . TailTruncation
3032 } ;
3133
34+ _configLabel = new Label {
35+ Text = $ "Config { SampleEventService . SampleConfigSettingKey } : not loaded",
36+ FontSize = 13 ,
37+ TextColor = Color . FromArgb ( "#576575" ) ,
38+ LineBreakMode = LineBreakMode . TailTruncation
39+ } ;
40+
3241 _activityIndicator = new ActivityIndicator {
3342 IsVisible = false ,
3443 Color = Color . FromArgb ( "#276749" )
@@ -38,6 +47,7 @@ public MainPage(ExceptionlessClient exceptionlessClient) {
3847 }
3948
4049 private View BuildContent ( ) {
50+ var refreshConfigButton = CreateActionButton ( "Refresh Config" , OnRefreshConfigClicked ) ;
4151 var sendExceptionButton = CreateActionButton ( "Send Handled Exception" , OnSendExceptionClicked ) ;
4252 var sendLogButton = CreateActionButton ( "Send Warning Log" , OnSendLogClicked ) ;
4353 var trackFeatureButton = CreateActionButton ( "Track Feature" , OnTrackFeatureClicked ) ;
@@ -88,22 +98,15 @@ private View BuildContent() {
8898 } ,
8999 _statusLabel ,
90100 _lastReferenceIdLabel ,
101+ _configLabel ,
91102 _activityIndicator
92103 }
93104 }
94105 } ,
95- new Grid {
96- ColumnDefinitions = {
97- new ColumnDefinition { Width = GridLength . Star } ,
98- new ColumnDefinition { Width = GridLength . Star }
99- } ,
100- RowDefinitions = {
101- new RowDefinition { Height = GridLength . Auto } ,
102- new RowDefinition { Height = GridLength . Auto }
103- } ,
104- ColumnSpacing = 12 ,
105- RowSpacing = 12 ,
106+ new VerticalStackLayout {
107+ Spacing = 12 ,
106108 Children = {
109+ refreshConfigButton ,
107110 sendExceptionButton ,
108111 sendLogButton ,
109112 trackFeatureButton ,
@@ -129,43 +132,37 @@ private static Button CreateActionButton(string text, EventHandler clicked) {
129132 return button ;
130133 }
131134
135+ private async void OnRefreshConfigClicked ( object ? sender , EventArgs e ) {
136+ await RunClientActionAsync ( "Configuration refreshed." , async ( ) => {
137+ await _sampleEvents . RefreshProjectConfigurationAsync ( ) ;
138+ SetConfigValue ( _sampleEvents . GetSampleConfigValue ( ) ) ;
139+ } ) ;
140+ }
141+
132142 private async void OnSendExceptionClicked ( object ? sender , EventArgs e ) {
133143 await RunClientActionAsync ( "Handled exception queued." , ( ) => {
134- string referenceId = Guid . NewGuid ( ) . ToString ( "N" ) ;
135-
136- try {
137- throw new InvalidOperationException ( "Exceptionless MAUI sample handled exception." ) ;
138- } catch ( Exception ex ) {
139- ex . ToExceptionless ( _exceptionlessClient )
140- . SetReferenceId ( referenceId )
141- . AddTags ( "handled" )
142- . SetProperty ( "Screen" , nameof ( MainPage ) )
143- . Submit ( ) ;
144- }
145-
144+ string referenceId = _sampleEvents . SubmitHandledException ( ) ;
146145 SetLastReferenceId ( referenceId ) ;
147146 return Task . CompletedTask ;
148147 } ) ;
149148 }
150149
151150 private async void OnSendLogClicked ( object ? sender , EventArgs e ) {
152151 await RunClientActionAsync ( "Warning log queued." , ( ) => {
153- _exceptionlessClient . SubmitLog ( "Exceptionless.SampleMaui.MainPage" , "MAUI sample warning log." , LogLevel . Warn ) ;
154- SetLastReferenceId ( _exceptionlessClient . GetLastReferenceId ( ) ) ;
152+ SetLastReferenceId ( _sampleEvents . SubmitWarningLog ( ) ) ;
155153 return Task . CompletedTask ;
156154 } ) ;
157155 }
158156
159157 private async void OnTrackFeatureClicked ( object ? sender , EventArgs e ) {
160158 await RunClientActionAsync ( "Feature usage queued." , ( ) => {
161- _exceptionlessClient . SubmitFeatureUsage ( "MauiSample.TrackFeature" ) ;
162- SetLastReferenceId ( _exceptionlessClient . GetLastReferenceId ( ) ) ;
159+ SetLastReferenceId ( _sampleEvents . TrackFeatureUsage ( ) ) ;
163160 return Task . CompletedTask ;
164161 } ) ;
165162 }
166163
167164 private async void OnFlushClicked ( object ? sender , EventArgs e ) {
168- await RunClientActionAsync ( "Queue processed." , ( ) => _exceptionlessClient . ProcessQueueAsync ( ) ) ;
165+ await RunClientActionAsync ( "Queue processed." , ( ) => _sampleEvents . FlushQueueAsync ( ) ) ;
169166 }
170167
171168 private async Task RunClientActionAsync ( string successMessage , Func < Task > action ) {
@@ -177,7 +174,9 @@ private async Task RunClientActionAsync(string successMessage, Func<Task> action
177174 await action ( ) ;
178175
179176 _statusLabel . Text = successMessage ;
180- } catch ( Exception ex ) {
177+ } catch ( InvalidOperationException ex ) {
178+ _statusLabel . Text = $ "Error: { ex . Message } ";
179+ } catch ( TaskCanceledException ex ) {
181180 _statusLabel . Text = $ "Error: { ex . Message } ";
182181 } finally {
183182 _activityIndicator . IsRunning = false ;
@@ -190,4 +189,8 @@ private void SetLastReferenceId(string? referenceId) {
190189 ? "Last reference id: none"
191190 : $ "Last reference id: { referenceId } ";
192191 }
192+
193+ private void SetConfigValue ( string value ) {
194+ _configLabel . Text = $ "Config { SampleEventService . SampleConfigSettingKey } : { value } ";
195+ }
193196}
0 commit comments