Repository navigation
Add .NET MAUI sample app #367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a173a9e
Add .NET MAUI sample app
niemyjski b4a6eab
Dogfood MAUI sample flow
niemyjski 537340a
Address MAUI sample review feedback
niemyjski babe9fe
Use mobile-safe local server URLs
niemyjski 643a626
Refresh dependencies and polish the MAUI sample
niemyjski 9b6df2d
Bundle the MAUI runtime privacy manifest on iOS
niemyjski 35625ad
Simplify MAUI setup using SDK configuration conventions
niemyjski 52c3b11
Declare MAUI sample diagnostic and usage data
niemyjski 9e61fd7
Share Apple privacy declarations and specify Mac signing entitlements
niemyjski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| namespace Exceptionless.SampleMaui; | ||
|
|
||
| public sealed class App : Application { | ||
| private readonly ExceptionlessClient _exceptionlessClient; | ||
| private readonly SampleDogfoodRunner _dogfoodRunner; | ||
| private readonly MainPage _mainPage; | ||
|
|
||
| public App(MainPage mainPage, ExceptionlessClient exceptionlessClient, SampleDogfoodRunner dogfoodRunner) { | ||
| _exceptionlessClient = exceptionlessClient; | ||
| _dogfoodRunner = dogfoodRunner; | ||
| _mainPage = mainPage; | ||
| } | ||
|
|
||
| protected override Window CreateWindow(IActivationState? activationState) { | ||
| var window = new Window(_mainPage); | ||
| _ = _dogfoodRunner.RunIfRequestedAsync(); | ||
|
|
||
| return window; | ||
| } | ||
|
|
||
| protected override void OnSleep() { | ||
| _ = _exceptionlessClient.ProcessQueueAsync(); | ||
| base.OnSleep(); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
samples/Exceptionless.SampleMaui/Exceptionless.SampleMaui.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>net10.0-android</TargetFrameworks> | ||
| <TargetFrameworks Condition="!$([MSBuild]::IsOSPlatform('linux'))">$(TargetFrameworks);net10.0-ios;net10.0-maccatalyst</TargetFrameworks> | ||
|
niemyjski marked this conversation as resolved.
|
||
| <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net10.0-windows10.0.19041.0</TargetFrameworks> | ||
| <OutputType>Exe</OutputType> | ||
| <RootNamespace>Exceptionless.SampleMaui</RootNamespace> | ||
| <UseMaui>true</UseMaui> | ||
| <SingleProject>true</SingleProject> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
|
|
||
| <ApplicationTitle>Exceptionless MAUI Sample</ApplicationTitle> | ||
| <ApplicationId>com.exceptionless.samplemaui</ApplicationId> | ||
| <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> | ||
| <ApplicationVersion>1</ApplicationVersion> | ||
| <WindowsPackageType>None</WindowsPackageType> | ||
|
|
||
| <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion> | ||
| <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">15.0</SupportedOSPlatformVersion> | ||
| <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">15.0</SupportedOSPlatformVersion> | ||
|
niemyjski marked this conversation as resolved.
|
||
| <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion> | ||
| <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'"> | ||
| <CodesignEntitlements>Platforms\MacCatalyst\Entitlements.plist</CodesignEntitlements> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.png" ForegroundScale="0.9" Color="#548C00" /> | ||
| <MauiSplashScreen Include="Resources\AppIcon\appiconfg.png" Color="#548C00" BaseSize="128,128" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Maui.Controls" Version="10.0.110" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios' Or $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'"> | ||
| <BundleResource Include="Resources\PrivacyInfo.xcprivacy" LogicalName="PrivacyInfo.xcprivacy" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\src\Exceptionless\Exceptionless.csproj" SetTargetFramework="TargetFramework=netstandard2.0" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,208 @@ | ||
| 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("#F5F8EF"); | ||
|
|
||
| _statusLabel = new Label { | ||
| Text = !exceptionlessClient.Configuration.IsValid | ||
| ? "Configure Exceptionless__ApiKey before sending events." | ||
| : exceptionlessClient.Configuration.Enabled ? "Ready" : "Exceptionless is disabled.", | ||
| FontSize = 16, | ||
| MinimumHeightRequest = 24, | ||
| TextColor = Color.FromArgb("#314256"), | ||
| LineBreakMode = LineBreakMode.WordWrap | ||
| }; | ||
|
|
||
| _lastReferenceIdLabel = new Label { | ||
| Text = "Last reference id: none", | ||
| FontSize = 16, | ||
| MinimumHeightRequest = 24, | ||
| TextColor = Color.FromArgb("#576575"), | ||
| LineBreakMode = LineBreakMode.TailTruncation | ||
| }; | ||
|
|
||
| _configLabel = new Label { | ||
| Text = $"Config {SampleEventService.SampleConfigSettingKey}: not loaded", | ||
| FontSize = 16, | ||
| MinimumHeightRequest = 24, | ||
| TextColor = Color.FromArgb("#576575"), | ||
| LineBreakMode = LineBreakMode.TailTruncation | ||
| }; | ||
|
|
||
| _activityIndicator = new ActivityIndicator { | ||
| IsVisible = false, | ||
| HeightRequest = 24, | ||
| Color = Color.FromArgb("#548C00") | ||
| }; | ||
|
|
||
| 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, 32), | ||
| MaximumWidthRequest = 820, | ||
| Spacing = 20, | ||
| Children = { | ||
| new Label { | ||
| Text = "Exceptionless MAUI Sample", | ||
| FontSize = 32, | ||
| FontAttributes = FontAttributes.Bold, | ||
| TextColor = Color.FromArgb("#1D2733") | ||
| }, | ||
|
niemyjski marked this conversation as resolved.
|
||
| new Label { | ||
| Text = "Submit sample events through the core Exceptionless client.", | ||
| FontSize = 18, | ||
| TextColor = Color.FromArgb("#576575"), | ||
| LineBreakMode = LineBreakMode.WordWrap | ||
| }, | ||
|
niemyjski marked this conversation as resolved.
|
||
| new Border { | ||
| Stroke = Color.FromArgb("#DCE5CE"), | ||
| StrokeThickness = 1, | ||
| BackgroundColor = Colors.White, | ||
| StrokeShape = new RoundRectangle { CornerRadius = 8 }, | ||
| Padding = new Thickness(18), | ||
| Content = new VerticalStackLayout { | ||
| Spacing = 10, | ||
| Children = { | ||
| new Label { | ||
| Text = "Client", | ||
| FontSize = 22, | ||
| FontAttributes = FontAttributes.Bold, | ||
| TextColor = Color.FromArgb("#1D2733") | ||
| }, | ||
|
niemyjski marked this conversation as resolved.
|
||
| new Label { | ||
| Text = $"Server: {_exceptionlessClient.Configuration.ServerUrl}", | ||
| FontSize = 16, | ||
| MinimumHeightRequest = 24, | ||
| TextColor = Color.FromArgb("#576575"), | ||
| LineBreakMode = LineBreakMode.WordWrap | ||
| }, | ||
|
niemyjski marked this conversation as resolved.
|
||
| new Label { | ||
| Text = $"Private information: {_exceptionlessClient.Configuration.IncludePrivateInformation}", | ||
| FontSize = 16, | ||
| MinimumHeightRequest = 24, | ||
| TextColor = Color.FromArgb("#576575") | ||
| }, | ||
|
niemyjski marked this conversation as resolved.
|
||
| _statusLabel, | ||
| _lastReferenceIdLabel, | ||
| _configLabel, | ||
| _activityIndicator | ||
| } | ||
| } | ||
| }, | ||
| new VerticalStackLayout { | ||
| Spacing = 12, | ||
| Children = { | ||
| refreshConfigButton, | ||
| sendExceptionButton, | ||
| sendLogButton, | ||
| trackFeatureButton, | ||
| flushButton | ||
|
niemyjski marked this conversation as resolved.
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private Button CreateActionButton(string text, EventHandler clicked) { | ||
| var button = new Button { | ||
| Text = text, | ||
| IsEnabled = _exceptionlessClient.Configuration.IsValid && _exceptionlessClient.Configuration.Enabled, | ||
| BackgroundColor = Color.FromArgb("#436F00"), | ||
| TextColor = Colors.White, | ||
| CornerRadius = 8, | ||
| FontAttributes = FontAttributes.Bold, | ||
| FontSize = 17, | ||
| HeightRequest = 60, | ||
| Padding = new Thickness(16, 12) | ||
| }; | ||
|
|
||
| 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}"; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| using Exceptionless.Logging; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Maui.Storage; | ||
|
|
||
| namespace Exceptionless.SampleMaui; | ||
|
|
||
| public static class MauiProgram { | ||
| public static MauiApp CreateMauiApp() { | ||
| var builder = MauiApp.CreateBuilder(); | ||
| var exceptionlessClient = ConfigureExceptionlessClient(); | ||
|
|
||
| builder | ||
| .UseMauiApp<App>(); | ||
|
|
||
| builder.Services.AddSingleton(exceptionlessClient); | ||
| builder.Services.AddSingleton<SampleEventService>(); | ||
| builder.Services.AddSingleton<SampleDogfoodRunner>(); | ||
| builder.Services.AddSingleton<MainPage>(); | ||
|
|
||
| return builder.Build(); | ||
| } | ||
|
|
||
| private static ExceptionlessClient ConfigureExceptionlessClient() { | ||
| string appDataDirectory = FileSystem.Current.AppDataDirectory; | ||
| var client = ExceptionlessClient.Default; | ||
| var config = client.Configuration; | ||
| config.IncludePrivateInformation = false; | ||
| config.DefaultTags.Add("maui"); | ||
| config.DefaultTags.Add("sample"); | ||
| config.DefaultData["Platform"] = DeviceInfo.Current.Platform.ToString(); | ||
| config.DefaultData["DeviceIdiom"] = DeviceInfo.Current.Idiom.ToString(); | ||
| config.SetVersion(AppInfo.Current.VersionString); | ||
| config.UseFolderStorage(Path.Join(appDataDirectory, "exceptionless-queue")); | ||
| config.UseFileLogger(Path.Join(appDataDirectory, "exceptionless-client.log"), LogLevel.Info); | ||
|
|
||
| client.Startup(); | ||
| return client; | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
samples/Exceptionless.SampleMaui/Platforms/Android/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true" android:usesCleartextTraffic="true" /> | ||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
| </manifest> |
8 changes: 8 additions & 0 deletions
8
samples/Exceptionless.SampleMaui/Platforms/Android/MainActivity.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| using Android.App; | ||
| using Android.Content.PM; | ||
|
|
||
| namespace Exceptionless.SampleMaui; | ||
|
|
||
| [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)] | ||
| public class MainActivity : MauiAppCompatActivity { | ||
| } |
12 changes: 12 additions & 0 deletions
12
samples/Exceptionless.SampleMaui/Platforms/Android/MainApplication.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| using Android.App; | ||
| using Android.Runtime; | ||
|
|
||
| namespace Exceptionless.SampleMaui; | ||
|
|
||
| [Application] | ||
| public class MainApplication : MauiApplication { | ||
| public MainApplication(IntPtr handle, JniHandleOwnership ownership) : base(handle, ownership) { | ||
| } | ||
|
|
||
| protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); | ||
| } |
8 changes: 8 additions & 0 deletions
8
samples/Exceptionless.SampleMaui/Platforms/MacCatalyst/AppDelegate.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| using Foundation; | ||
|
|
||
| namespace Exceptionless.SampleMaui; | ||
|
|
||
| [Register("AppDelegate")] | ||
| public class AppDelegate : MauiUIApplicationDelegate { | ||
| protected override MauiApp CreateMauiApp() => MauiProgram.CreateMauiApp(); | ||
| } |
10 changes: 10 additions & 0 deletions
10
samples/Exceptionless.SampleMaui/Platforms/MacCatalyst/Entitlements.plist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>com.apple.security.app-sandbox</key> | ||
| <true/> | ||
| <key>com.apple.security.network.client</key> | ||
| <true/> | ||
| </dict> | ||
| </plist> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.