Example #1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            SetLoggerConfiguration();

            Dispatcher.UnhandledException += (object sender, DispatcherUnhandledExceptionEventArgs e) => UnhandledException(e.Exception, LogLevel.Error);
            // AppDomain.CurrentDomain.FirstChanceException += (object sender, FirstChanceExceptionEventArgs e) => UnhandledException(e.Exception, LogLevel.Info);
            AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => UnhandledException(e.ExceptionObject as Exception, LogLevel.Error);
            TaskScheduler.UnobservedTaskException      += (object sender, UnobservedTaskExceptionEventArgs e) => UnhandledException(e.Exception, LogLevel.Error);

            logger.Info($"Starting XOutput version: {AppVersion}");

            var globalContext = ApplicationContext.Global;

            globalContext.AddFromConfiguration(typeof(CoreConfiguration));
            globalContext.AddFromConfiguration(typeof(ApiConfiguration));
            globalContext.AddFromConfiguration(typeof(AppConfiguration));
            globalContext.Discover(GetOrLoadAssemblies("XOutput.Core", "XOutput.Api", "XOutput.Devices", "XOutput.Emulation", "XOutput.Server"));
            logger.Info("Configuration classes are loaded");
            var configurationManager = globalContext.Resolve <ConfigurationManager>();

            var mainWindow = ApplicationContext.Global.Resolve <MainWindow>();

            MainWindow = mainWindow;

            var hidGuardianManager  = globalContext.Resolve <HidGuardianManager>();
            var notificationService = globalContext.Resolve <NotificationService>();

            if (hidGuardianManager.Installed)
            {
                try
                {
                    hidGuardianManager.ClearPid(Process.GetCurrentProcess().Id);
                    hidGuardianManager.SetPid(Process.GetCurrentProcess().Id);
                }
                catch (Exception)
                {
                    notificationService.Add(Notifications.HidGuardianRegistry, null, NotificationTypes.Warning);
                }
            }
            CheckUpdate(globalContext.Resolve <UpdateChecker>(), notificationService);

            server = globalContext.Resolve <Server.Server>();
            server.StartAsync();
        }