diff --git a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs index 3bd8cd73..a94b47c3 100644 --- a/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs +++ b/SafeExamBrowser.Client.UnitTests/ClientControllerTests.cs @@ -58,6 +58,7 @@ namespace SafeExamBrowser.Client.UnitTests private Guid sessionId; private AppSettings settings; private Mock shutdown; + private Mock splashScreen; private Mock taskbar; private Mock text; private Mock uiFactory; @@ -84,6 +85,7 @@ namespace SafeExamBrowser.Client.UnitTests sessionId = Guid.NewGuid(); settings = new AppSettings(); shutdown = new Mock(); + splashScreen = new Mock(); taskbar = new Mock(); text = new Mock(); uiFactory = new Mock(); @@ -105,6 +107,7 @@ namespace SafeExamBrowser.Client.UnitTests operationSequence.Object, runtimeProxy.Object, shutdown.Object, + splashScreen.Object, taskbar.Object, text.Object, uiFactory.Object); @@ -300,14 +303,10 @@ namespace SafeExamBrowser.Client.UnitTests [TestMethod] public void Communication_MustCorrectlyHandleAbortedReconfiguration() { - var splashScreen = new Mock(); - - uiFactory.Setup(f => f.CreateSplashScreen(It.IsAny())).Returns(splashScreen.Object); - sut.TryStart(); clientHost.Raise(c => c.ReconfigurationAborted += null); - splashScreen.Verify(s => s.Close(), Times.AtLeastOnce); + splashScreen.Verify(s => s.Hide(), Times.AtLeastOnce); } [TestMethod] @@ -498,9 +497,6 @@ namespace SafeExamBrowser.Client.UnitTests Progress = true, Regress = true }; - var splashScreen = new Mock(); - - uiFactory.Setup(u => u.CreateSplashScreen(It.IsAny())).Returns(splashScreen.Object); sut.TryStart(); operationSequence.Raise(o => o.ProgressChanged += null, args); @@ -516,9 +512,6 @@ namespace SafeExamBrowser.Client.UnitTests public void Operations_MustUpdateStatus() { var key = TextKey.OperationStatus_EmptyClipboard; - var splashScreen = new Mock(); - - uiFactory.Setup(u => u.CreateSplashScreen(It.IsAny())).Returns(splashScreen.Object); sut.TryStart(); operationSequence.Raise(o => o.StatusChanged += null, key); @@ -835,10 +828,6 @@ namespace SafeExamBrowser.Client.UnitTests [TestMethod] public void Startup_MustUpdateAppConfigForSplashScreen() { - var splashScreen = new Mock(); - - uiFactory.Setup(u => u.CreateSplashScreen(It.IsAny())).Returns(splashScreen.Object); - sut.TryStart(); sut.UpdateAppConfig(); diff --git a/SafeExamBrowser.Client/ClientController.cs b/SafeExamBrowser.Client/ClientController.cs index 3f960a56..bf7a636d 100644 --- a/SafeExamBrowser.Client/ClientController.cs +++ b/SafeExamBrowser.Client/ClientController.cs @@ -73,6 +73,7 @@ namespace SafeExamBrowser.Client IOperationSequence operations, IRuntimeProxy runtime, Action shutdown, + ISplashScreen splashScreen, ITaskbar taskbar, IText text, IUserInterfaceFactory uiFactory) @@ -89,6 +90,7 @@ namespace SafeExamBrowser.Client this.operations = operations; this.runtime = runtime; this.shutdown = shutdown; + this.splashScreen = splashScreen; this.taskbar = taskbar; this.text = text; this.uiFactory = uiFactory; @@ -98,11 +100,13 @@ namespace SafeExamBrowser.Client { logger.Info("Initiating startup procedure..."); - splashScreen = uiFactory.CreateSplashScreen(); operations.ActionRequired += Operations_ActionRequired; operations.ProgressChanged += Operations_ProgressChanged; operations.StatusChanged += Operations_StatusChanged; + splashScreen.Show(); + splashScreen.BringToForeground(); + var success = operations.TryPerform() == OperationResult.Success; if (success) @@ -130,7 +134,7 @@ namespace SafeExamBrowser.Client logger.Log(string.Empty); } - splashScreen.Close(); + splashScreen.Hide(); return success; } @@ -140,7 +144,8 @@ namespace SafeExamBrowser.Client logger.Log(string.Empty); logger.Info("Initiating shutdown procedure..."); - splashScreen = uiFactory.CreateSplashScreen(context.AppConfig); + splashScreen.Show(); + splashScreen.BringToForeground(); CloseShell(); DeregisterEvents(); @@ -163,10 +168,7 @@ namespace SafeExamBrowser.Client public void UpdateAppConfig() { - if (splashScreen != null) - { - splashScreen.AppConfig = context.AppConfig; - } + splashScreen.AppConfig = context.AppConfig; } private void RegisterEvents() @@ -340,6 +342,12 @@ namespace SafeExamBrowser.Client args.AllowDownload = true; args.Callback = Browser_ConfigurationDownloadFinished; args.DownloadPath = Path.Combine(context.AppConfig.TemporaryDirectory, fileName); + + splashScreen.Show(); + splashScreen.BringToForeground(); + splashScreen.SetIndeterminate(); + splashScreen.UpdateStatus(TextKey.OperationStatus_InitializeSession, true); + logger.Info($"Allowed download request for configuration file '{fileName}'."); } else @@ -364,22 +372,19 @@ namespace SafeExamBrowser.Client if (communication.Success) { logger.Info($"Sent reconfiguration request for '{filePath}' to the runtime."); - - splashScreen = uiFactory.CreateSplashScreen(context.AppConfig); - splashScreen.SetIndeterminate(); - splashScreen.UpdateStatus(TextKey.OperationStatus_InitializeSession, true); - splashScreen.Show(); } else { logger.Error($"Failed to communicate reconfiguration request for '{filePath}'!"); - messageBox.Show(TextKey.MessageBox_ReconfigurationError, TextKey.MessageBox_ReconfigurationErrorTitle, icon: MessageBoxIcon.Error); + messageBox.Show(TextKey.MessageBox_ReconfigurationError, TextKey.MessageBox_ReconfigurationErrorTitle, icon: MessageBoxIcon.Error, parent: splashScreen); + splashScreen.Hide(); } } else { logger.Error($"Failed to download configuration file '{filePath}'!"); - messageBox.Show(TextKey.MessageBox_ConfigurationDownloadError, TextKey.MessageBox_ConfigurationDownloadErrorTitle, icon: MessageBoxIcon.Error); + messageBox.Show(TextKey.MessageBox_ConfigurationDownloadError, TextKey.MessageBox_ConfigurationDownloadErrorTitle, icon: MessageBoxIcon.Error, parent: splashScreen); + splashScreen.Hide(); } } @@ -428,14 +433,14 @@ namespace SafeExamBrowser.Client private void ClientHost_ReconfigurationAborted() { logger.Info("The reconfiguration was aborted by the runtime."); - splashScreen?.Close(); + splashScreen.Hide(); } private void ClientHost_ReconfigurationDenied(ReconfigurationEventArgs args) { logger.Info($"The reconfiguration request for '{args.ConfigurationPath}' was denied by the runtime!"); messageBox.Show(TextKey.MessageBox_ReconfigurationDenied, TextKey.MessageBox_ReconfigurationDeniedTitle, parent: splashScreen); - splashScreen?.Close(); + splashScreen.Hide(); } private void ClientHost_Shutdown() @@ -476,33 +481,33 @@ namespace SafeExamBrowser.Client { if (args.CurrentValue.HasValue) { - splashScreen?.SetValue(args.CurrentValue.Value); + splashScreen.SetValue(args.CurrentValue.Value); } if (args.IsIndeterminate == true) { - splashScreen?.SetIndeterminate(); + splashScreen.SetIndeterminate(); } if (args.MaxValue.HasValue) { - splashScreen?.SetMaxValue(args.MaxValue.Value); + splashScreen.SetMaxValue(args.MaxValue.Value); } if (args.Progress == true) { - splashScreen?.Progress(); + splashScreen.Progress(); } if (args.Regress == true) { - splashScreen?.Regress(); + splashScreen.Regress(); } } private void Operations_StatusChanged(TextKey status) { - splashScreen?.UpdateStatus(status, true); + splashScreen.UpdateStatus(status, true); } private void Runtime_ConnectionLost() diff --git a/SafeExamBrowser.Client/CompositionRoot.cs b/SafeExamBrowser.Client/CompositionRoot.cs index 52eb67bb..e1e08638 100644 --- a/SafeExamBrowser.Client/CompositionRoot.cs +++ b/SafeExamBrowser.Client/CompositionRoot.cs @@ -105,6 +105,7 @@ namespace SafeExamBrowser.Client var explorerShell = new ExplorerShell(ModuleLogger(nameof(ExplorerShell)), nativeMethods); var fileSystemDialog = BuildFileSystemDialog(); var hashAlgorithm = new HashAlgorithm(); + var splashScreen = uiFactory.CreateSplashScreen(); var operations = new Queue(); @@ -137,6 +138,7 @@ namespace SafeExamBrowser.Client sequence, runtimeProxy, shutdown, + splashScreen, taskbar, text, uiFactory);