Working with warnings
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Data.Core;
|
||||
using Avalonia.Data.Core.Plugins;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using AvaloniaLoggingDI.ViewModels;
|
||||
using AvaloniaLoggingDI.Views;
|
||||
using LogViewer.Avalonia;
|
||||
using MessageBox.Avalonia;
|
||||
using MessageBox.Avalonia.Enums;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MsBox.Avalonia;
|
||||
using MsBox.Avalonia.Enums;
|
||||
using MsLogger.Core;
|
||||
using RandomLogging.Service;
|
||||
using Icon = MessageBox.Avalonia.Enums.Icon;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using Icon = MsBox.Avalonia.Enums.Icon;
|
||||
|
||||
namespace AvaloniaLoggingDI;
|
||||
|
||||
@@ -30,9 +30,9 @@ public partial class App : Application
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
// Line below is needed to remove Avalonia data validation.
|
||||
// Without this line you will get duplicate validations from both Avalonia and CT
|
||||
ExpressionObserver.DataValidators.RemoveAll(x => x is DataAnnotationsValidationPlugin);
|
||||
// Avoid duplicate validations from both Avalonia and the CommunityToolkit.
|
||||
// More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
|
||||
DisableAvaloniaDataAnnotationValidation();
|
||||
|
||||
// catch all unhandled errors
|
||||
AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
|
||||
@@ -94,7 +94,7 @@ public partial class App : Application
|
||||
|
||||
_host = builder.Build();
|
||||
_cancellationTokenSource = new();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
LogStartingMode();
|
||||
@@ -119,7 +119,17 @@ public partial class App : Application
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
private static void DisableAvaloniaDataAnnotationValidation()
|
||||
{
|
||||
// Get an array of plugins to remove
|
||||
var dataValidationPluginsToRemove = BindingPlugins.DataValidators.OfType<DataAnnotationsValidationPlugin>().ToArray();
|
||||
|
||||
// remove each entry found
|
||||
foreach (var plugin in dataValidationPluginsToRemove)
|
||||
{
|
||||
BindingPlugins.DataValidators.Remove(plugin);
|
||||
}
|
||||
}
|
||||
private void OnShutdownRequested(object? sender, ShutdownRequestedEventArgs e)
|
||||
=> _ = _host!.StopAsync(_cancellationTokenSource!.Token);
|
||||
|
||||
@@ -133,24 +143,27 @@ public partial class App : Application
|
||||
private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
=> ShowMessageBox("Unhandled Error", ((Exception)e.ExceptionObject).Message);
|
||||
|
||||
private void ShowMessageBox(string title, string message)
|
||||
private static void ShowMessageBox(string title, string message)
|
||||
{
|
||||
MessageBox.Avalonia.BaseWindows.Base.IMsBoxWindow<ButtonResult> messageBoxStandardWindow = MessageBoxManager
|
||||
.GetMessageBoxStandardWindow(title, message, ButtonEnum.Ok, Icon.Stop);
|
||||
|
||||
messageBoxStandardWindow.Show();
|
||||
}
|
||||
var box = MessageBoxManager.GetMessageBoxStandard(
|
||||
"Exception",
|
||||
text: message,
|
||||
ButtonEnum.Ok,
|
||||
Icon.Stop
|
||||
);
|
||||
_ = box.ShowAsync().GetAwaiter();
|
||||
}
|
||||
|
||||
private void LogStartingMode()
|
||||
{
|
||||
// Get the Launch mode
|
||||
bool isDevelopment = string.Equals(Environment.GetEnvironmentVariable("DOTNET_MODIFIABLE_ASSEMBLIES"), "debug",
|
||||
StringComparison.InvariantCultureIgnoreCase);
|
||||
StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
// initialize a logger & EventId
|
||||
ILogger<App> logger = _host!.Services.GetRequiredService<ILogger<App>>();
|
||||
EventId eventId = new EventId(id: 0, name: Assembly.GetEntryAssembly()!.GetName().Name);
|
||||
|
||||
|
||||
// log a test pattern for each log level
|
||||
logger.TestPattern(eventId: eventId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user