Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Exceptionless.Net.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<Project Path="samples/Exceptionless.SampleHosting/Exceptionless.SampleHosting.csproj" />
<Project Path="samples/Exceptionless.SampleLambda/Exceptionless.SampleLambda.csproj" />
<Project Path="samples/Exceptionless.SampleLambdaAspNetCore/Exceptionless.SampleLambdaAspNetCore.csproj" />
<Project Path="samples/Exceptionless.SampleMaui/Exceptionless.SampleMaui.csproj" />
Comment thread
niemyjski marked this conversation as resolved.
<Project Path="samples/Exceptionless.SampleMvc/Exceptionless.SampleMvc.csproj">
<BuildDependency Project="src/Exceptionless/Exceptionless.csproj" />
<BuildDependency Project="src/Platforms/Exceptionless.Mvc/Exceptionless.Mvc.csproj" />
Expand Down
25 changes: 25 additions & 0 deletions samples/Exceptionless.SampleMaui/App.cs
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 samples/Exceptionless.SampleMaui/Exceptionless.SampleMaui.csproj
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>
Comment thread
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>
Comment thread
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>
208 changes: 208 additions & 0 deletions samples/Exceptionless.SampleMaui/MainPage.cs
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")
},
Comment thread
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
},
Comment thread
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")
},
Comment thread
niemyjski marked this conversation as resolved.
new Label {
Text = $"Server: {_exceptionlessClient.Configuration.ServerUrl}",
FontSize = 16,
MinimumHeightRequest = 24,
TextColor = Color.FromArgb("#576575"),
LineBreakMode = LineBreakMode.WordWrap
},
Comment thread
niemyjski marked this conversation as resolved.
new Label {
Text = $"Private information: {_exceptionlessClient.Configuration.IncludePrivateInformation}",
FontSize = 16,
MinimumHeightRequest = 24,
TextColor = Color.FromArgb("#576575")
},
Comment thread
niemyjski marked this conversation as resolved.
_statusLabel,
_lastReferenceIdLabel,
_configLabel,
_activityIndicator
}
}
},
new VerticalStackLayout {
Spacing = 12,
Children = {
refreshConfigButton,
sendExceptionButton,
sendLogButton,
trackFeatureButton,
flushButton
Comment thread
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}";
}
}
39 changes: 39 additions & 0 deletions samples/Exceptionless.SampleMaui/MauiProgram.cs
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;
}
}
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>
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 {
}
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();
}
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();
}
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>
Loading
Loading