public async Task LaunchDcsAsync()
        {
            await Task.Run(async() =>
            {
                var install = _profileService.GetSelectedInstall();

                Guard.RequireIsNotNull(install, nameof(install));

                if (!install.IsValidInstall)
                {
                    MessageBoxEx.Show($"The installation path \"{install.Directory}\" appears to be invalid.   Please fix the path and try again.");
                    return;
                }

                await _dcsWorldManager.WriteOptionsAsync();
                await _dcsWorldManager.UpdateAdvancedOptionsAsync();

                await _eventRegistry.InvokeBeforeDcsLaunchedAsync(this, DeferredEventArgs.CreateEmpty());

                //await _dcsWorldManager.PatchViewportsAsync();
                //await _dcsWorldManager.WriteViewportOptionsAsync();

                var processInfo = new ProcessStartInfo(install.ExePath)
                {
                    UseShellExecute = true
                };

                Process.Start(processInfo);

                await _eventRegistry.InvokeAfterDcsLaunchedAsync(this, DeferredEventArgs.CreateEmpty());
            });
        }
        public void GetDeferral_AfterEndInvoke()
        {
            var args = new DeferredEventArgs();

            args.EndInvoke();

            Assert.Throws <InvalidOperationException>(() => args.GetDeferral());
        }
        public void BeginInvoke_SecondCall()
        {
            var args = new DeferredEventArgs();

            args.BeginInvoke(CancellationToken.None);

            Assert.Throws <InvalidOperationException>(() => args.BeginInvoke(CancellationToken.None));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 引发 <see cref="OperationCompleted" /> 事件
        /// </summary>
        /// <param name="ea">包含此事件的参数</param>
        protected virtual void OnOperationCompleted(DeferredEventArgs ea)
        {
            var handler = OperationCompleted;

            if (handler != null)
            {
                handler(this, ea);
            }
        }
        public void NoDeferral()
        {
            var args = new DeferredEventArgs();

            args.BeginInvoke(CancellationToken.None);
            var task = args.EndInvoke();

            Assert.NotNull(task);
            Assert.IsTrue(task.IsCompleted);
        }
Exemplo n.º 6
0
        public void ReUseEventArgs_Pending()
        {
            EventHandler <DeferredEventArgs> handler = (s, e) => e.GetDeferral();
            var eventArgs = new DeferredEventArgs();

            var task = handler.InvokeAsync(null, eventArgs);

            Assert.NotNull(task);
            Assert.IsFalse(task.IsCompleted);

            Assert.Throws <InvalidOperationException>(() => handler.InvokeAsync(null, eventArgs));
        }
        public void OneDeferral_Pending()
        {
            var args = new DeferredEventArgs();

            args.BeginInvoke(CancellationToken.None);

            args.GetDeferral();

            var task = args.EndInvoke();

            Assert.NotNull(task);
            Assert.IsFalse(task.IsCompleted);
        }
Exemplo n.º 8
0
        public void OneHandler_Cancelling()
        {
            var cts = new CancellationTokenSource();

            EventHandler <DeferredEventArgs> handler = (s, e) => cts.Cancel();
            var eventArgs = new DeferredEventArgs();

            var task = handler.InvokeAsync(null, eventArgs, cts.Token);

            Assert.NotNull(task);
            Assert.IsTrue(task.IsCanceled);

            cts.Dispose();
        }
Exemplo n.º 9
0
        private async void App_Startup(object sender, StartupEventArgs e)
        {
            MainWindow = _splashScreen = new SplashScreen();

            _splashScreen.Show();

            UiDispatcher.Initialize();
            GeneralExceptionHandler.Instance = new UserFriendlyExceptionHandler();

#if DEBUG
            Tracer.RegisterListener(new ConsoleOutputEventListener());
#endif
            Tracer.RegisterListener(new FileLogEventListener(Path.Combine(ApplicationPaths.StoragePath, "debug.log")));

            _eventRegistry = new ApplicationEventRegistry();
            _container     = new Container();

            _mainWindow         = new MainWindow();
            _mainWindow.Loaded += OnMainWindowLoaded;

            await Task.WhenAll(RegisterServicesAsync());

            await Task.WhenAll(CheckForUpdatesAsync());

            await Task.WhenAll(UpdateDefinitionFilesAsync());

            _mainWindow.DataContext = _container.Resolve <MainWindowViewModel>();

            await Task.WhenAll(InitializePluginsAsync());

            await Task.WhenAll(FinalizeAppStartupAsync());

            await CheckFirstUseAsync();

            _splashScreen.Close();

            var settingsService = _container.Resolve <ILauncherSettingsService>();

            if (!settingsService.GetValue(LauncherCategories.Launcher, LauncherSettingKeys.AcknowledgedDisclaimer, false))
            {
                MessageBoxEx.Show($"DCS Alternative Launcher modifies files that exist in the DCS World game installation folder as well as your Saved Games folder.{Environment.NewLine}Please make sure you have backed up your data before using this software.{Environment.NewLine}{Environment.NewLine}You've been warned :).", "DISCLAIMER");
                settingsService.SetValue(LauncherCategories.Launcher, LauncherSettingKeys.AcknowledgedDisclaimer, true);
            }

            (MainWindow = _mainWindow).Show();

            await _eventRegistry.InvokeApplicationStartupCompleteAsync(this, DeferredEventArgs.CreateEmpty());

            Tracer.Info("Startup Complete.");
        }
Exemplo n.º 10
0
        public void ReUseEventArgs()
        {
            EventHandler <DeferredEventArgs> handler = (s, e) => { };
            var eventArgs = new DeferredEventArgs();

            var task = handler.InvokeAsync(null, eventArgs);

            Assert.NotNull(task);
            Assert.IsTrue(task.IsCompleted);

            task = handler.InvokeAsync(null, eventArgs);

            Assert.NotNull(task);
            Assert.IsTrue(task.IsCompleted);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 引发 <see cref="OperationFailed" /> 事件
        /// </summary>
        /// <param name="ea">包含此事件的参数</param>
        protected virtual void OnOperationFailed(DeferredEventArgs ea)
        {
            var handler = OperationFailed;

            if (handler != null)
            {
                handler(this, ea);
            }

            if (Context == null)
            {
                OnOperationCompleted(new DeferredEventArgs(Result, Exception));
            }
            else
            {
                Context.Post(_ => OnOperationCompleted(new DeferredEventArgs(Result, Exception)), null);
            }
        }
Exemplo n.º 12
0
        public void OneDeferral_Pending_Cancelled()
        {
            var cts = new CancellationTokenSource();

            var args = new DeferredEventArgs();

            args.BeginInvoke(cts.Token);

            args.GetDeferral();

            var task = args.EndInvoke();

            Assert.NotNull(task);
            Assert.IsFalse(task.IsCompleted);

            cts.Cancel();
            cts.Dispose();

            Assert.IsTrue(task.IsCanceled);
        }
Exemplo n.º 13
0
        public void TwoDeferral_OneComplete_SecondPending()
        {
            var args = new DeferredEventArgs();

            args.BeginInvoke(CancellationToken.None);

            args.GetDeferral()
            .Complete();

            var deferral2 = args.GetDeferral();

            var task = args.EndInvoke();

            Assert.NotNull(task);
            Assert.IsFalse(task.IsCompleted);

            deferral2.Complete();

            Assert.IsTrue(task.IsCompleted);
        }
Exemplo n.º 14
0
        internal async Task InvokeApplicationStartupCompleteAsync(object sender, DeferredEventArgs e)
        {
            var handler = ApplicationStartupComplete;

            await InvokeAsync(handler, sender, e);
        }
Exemplo n.º 15
0
        internal async Task InvokeAfterDcsLaunchedAsync(object sender, DeferredEventArgs e)
        {
            var handler = AfterDcsLaunched;

            await InvokeAsync(handler, sender, e);
        }
Exemplo n.º 16
0
        public void GetDeferral_BeforeBeginInvoke()
        {
            var args = new DeferredEventArgs();

            Assert.Throws <InvalidOperationException>(() => args.GetDeferral());
        }
Exemplo n.º 17
0
        public void BeginInvoke_Cancelled()
        {
            var args = new DeferredEventArgs();

            Assert.Throws <OperationCanceledException>(() => args.BeginInvoke(new CancellationToken(true)));
        }
Exemplo n.º 18
0
        public void BeginInvoke()
        {
            var args = new DeferredEventArgs();

            args.BeginInvoke(CancellationToken.None);
        }
Exemplo n.º 19
0
        private Task FinalizeAppStartupAsync()
        {
            _splashScreen.Status = "Almost there...";

            return(_eventRegistry.InvokeApplicationStartupAsync(this, DeferredEventArgs.CreateEmpty()));
        }