1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using System.Linq;
- using System.Threading.Tasks;
- using Avalonia;
- using Avalonia.Controls;
- using Avalonia.Controls.ApplicationLifetimes;
- using Avalonia.Data.Core.Plugins;
- using Avalonia.Markup.Xaml;
- using Comal.Classes;
- using InABox.Avalonia;
- using InABox.Core;
- using PRS.Avalonia.Modules;
- using GeoFence = Comal.Classes.GeoFence;
- namespace PRS.Avalonia;
- public class App : Application
- {
- public static GeoFence? GPS => null;
- public override void Initialize()
- {
- TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
- MobileLogging.LogException += MobileLogging_LogException;
- CoreUtils.RegisterClasses();
- ComalUtils.RegisterClasses();
- CoreUtils.RegisterClasses(typeof(App).Assembly);
-
- AvaloniaXamlLoader.Load(this);
- }
- private void MobileLogging_LogException(Exception ex, string? tag)
- {
- HandleException(ex);
- }
- private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
- {
- HandleException(e.Exception);
- }
- public static void HandleException(Exception e)
- {
- MobileLogging.LogError(CoreUtils.FormatException(e));
- }
- public override void OnFrameworkInitializationCompleted()
- {
- if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
- {
- // Avoid duplicate validations from both Avalonia and the CommunityToolkit.
- // More info: https://docs.avaloniaui.net/docs/guides/development-guides/data-validation#manage-validationplugins
- DisableAvaloniaDataAnnotationValidation();
- desktop.MainWindow = new MainWindow
- {
- DataContext = new MainViewModel(),
- Width = 400,
- Height = 700,
- WindowStartupLocation = WindowStartupLocation.CenterScreen
- };
- }
- else if (ApplicationLifetime is ISingleViewApplicationLifetime singleViewPlatform)
- {
- singleViewPlatform.MainView = new MainView
- {
- DataContext = new MainViewModel()
- };
- }
- base.OnFrameworkInitializationCompleted();
- }
- private 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);
- }
- }
|