Пример #1
0
        protected override void Launch()
        {
            _applicationStateManager = new ApplicationStateManager(Kernel, Args);
            Core.Utilities.PrepareFirstLaunch();

            ILogger logger = Kernel.Get <ILogger>();

            if (_applicationStateManager.FocusExistingInstance())
            {
                logger.Information("Shutting down because a different instance is already running.");
                Application.Current.Shutdown(1);
                return;
            }

            IViewManager viewManager = Kernel.Get <IViewManager>();

            StartupArguments = Args.ToList();

            // Create the Artemis core
            try
            {
                _core = Kernel.Get <ICoreService>();
            }
            catch (Exception e)
            {
                HandleFatalException(e, logger);
                throw;
            }

            // Ensure WPF uses the right culture in binding converters
            FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

            // Create and bind the root view, this is a tray icon so don't show it with the window manager
            Execute.OnUIThreadSync(() =>
            {
                UIElement view = viewManager.CreateAndBindViewForModelIfNecessary(RootViewModel);
                ((TrayViewModel)RootViewModel).SetTaskbarIcon(view);
            });

            // Initialize the core async so the UI can show the progress
            Task.Run(() =>
            {
                try
                {
                    _core.StartupArguments = StartupArguments;
                    _core.IsElevated       = _applicationStateManager.IsElevated;
                    _core.Initialize();
                }
                catch (Exception e)
                {
                    HandleFatalException(e, logger);
                    throw;
                }
            });

            IRegistrationService registrationService = Kernel.Get <IRegistrationService>();

            registrationService.RegisterInputProvider();
            registrationService.RegisterControllers();

            Execute.OnUIThreadSync(() => { registrationService.ApplyPreferredGraphicsContext(); });

            // Initialize background services
            Kernel.Get <IDeviceLayoutService>();
        }