2017-07-26 14:36:20 +02:00
|
|
|
|
/*
|
2019-01-09 11:25:21 +01:00
|
|
|
|
* Copyright (c) 2019 ETH Zürich, Educational Development and Technology (LET)
|
2017-07-26 14:36:20 +02:00
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-07-27 13:57:12 +02:00
|
|
|
|
using System;
|
2018-06-21 07:56:25 +02:00
|
|
|
|
using System.IO;
|
2019-10-04 16:36:12 +02:00
|
|
|
|
using System.Linq;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Browser.Contracts;
|
2019-09-06 08:13:27 +02:00
|
|
|
|
using SafeExamBrowser.Browser.Contracts.Events;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Client.Contracts;
|
2019-10-04 16:36:12 +02:00
|
|
|
|
using SafeExamBrowser.Client.Operations.Events;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Communication.Contracts.Data;
|
|
|
|
|
using SafeExamBrowser.Communication.Contracts.Events;
|
|
|
|
|
using SafeExamBrowser.Communication.Contracts.Hosts;
|
|
|
|
|
using SafeExamBrowser.Communication.Contracts.Proxies;
|
|
|
|
|
using SafeExamBrowser.Configuration.Contracts.Cryptography;
|
|
|
|
|
using SafeExamBrowser.Core.Contracts.OperationModel;
|
|
|
|
|
using SafeExamBrowser.Core.Contracts.OperationModel.Events;
|
|
|
|
|
using SafeExamBrowser.I18n.Contracts;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2019-10-01 11:30:53 +02:00
|
|
|
|
using SafeExamBrowser.Monitoring.Contracts.Applications;
|
2019-09-05 09:00:41 +02:00
|
|
|
|
using SafeExamBrowser.Monitoring.Contracts.Display;
|
2019-10-01 11:30:53 +02:00
|
|
|
|
using SafeExamBrowser.Settings;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.MessageBox;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Shell;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
|
|
|
|
using SafeExamBrowser.WindowsApi.Contracts;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Client
|
2017-07-26 14:36:20 +02:00
|
|
|
|
{
|
2018-01-18 08:16:20 +01:00
|
|
|
|
internal class ClientController : IClientController
|
2017-07-26 14:36:20 +02:00
|
|
|
|
{
|
2019-03-06 16:10:00 +01:00
|
|
|
|
private IActionCenter actionCenter;
|
2019-10-01 11:30:53 +02:00
|
|
|
|
private IApplicationMonitor applicationMonitor;
|
2019-10-01 16:24:10 +02:00
|
|
|
|
private ClientContext context;
|
2017-08-11 08:28:17 +02:00
|
|
|
|
private IDisplayMonitor displayMonitor;
|
2018-08-17 14:48:50 +02:00
|
|
|
|
private IExplorerShell explorerShell;
|
2019-01-10 10:04:30 +01:00
|
|
|
|
private IHashAlgorithm hashAlgorithm;
|
2017-07-27 11:46:31 +02:00
|
|
|
|
private ILogger logger;
|
2018-03-14 12:07:20 +01:00
|
|
|
|
private IMessageBox messageBox;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
private IOperationSequence operations;
|
2018-02-14 15:26:05 +01:00
|
|
|
|
private IRuntimeProxy runtime;
|
2018-02-21 14:01:21 +01:00
|
|
|
|
private Action shutdown;
|
|
|
|
|
private ISplashScreen splashScreen;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
private ITaskbar taskbar;
|
2019-03-29 07:46:21 +01:00
|
|
|
|
private ITerminationActivator terminationActivator;
|
2018-07-04 09:53:33 +02:00
|
|
|
|
private IText text;
|
2018-02-21 14:01:21 +01:00
|
|
|
|
private IUserInterfaceFactory uiFactory;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
private IBrowserApplication Browser => context.Browser;
|
|
|
|
|
private IClientHost ClientHost => context.ClientHost;
|
|
|
|
|
private AppSettings Settings => context.Settings;
|
2018-02-20 15:15:26 +01:00
|
|
|
|
|
2018-01-17 08:26:44 +01:00
|
|
|
|
public ClientController(
|
2019-03-06 16:10:00 +01:00
|
|
|
|
IActionCenter actionCenter,
|
2019-10-01 11:30:53 +02:00
|
|
|
|
IApplicationMonitor applicationMonitor,
|
2019-10-01 16:24:10 +02:00
|
|
|
|
ClientContext context,
|
2017-08-11 08:28:17 +02:00
|
|
|
|
IDisplayMonitor displayMonitor,
|
2018-08-17 14:48:50 +02:00
|
|
|
|
IExplorerShell explorerShell,
|
2019-01-10 10:04:30 +01:00
|
|
|
|
IHashAlgorithm hashAlgorithm,
|
2017-07-27 11:46:31 +02:00
|
|
|
|
ILogger logger,
|
2018-03-14 12:07:20 +01:00
|
|
|
|
IMessageBox messageBox,
|
2018-02-12 12:21:55 +01:00
|
|
|
|
IOperationSequence operations,
|
2018-02-14 15:26:05 +01:00
|
|
|
|
IRuntimeProxy runtime,
|
2018-02-21 14:01:21 +01:00
|
|
|
|
Action shutdown,
|
2017-07-27 11:46:31 +02:00
|
|
|
|
ITaskbar taskbar,
|
2019-03-29 07:46:21 +01:00
|
|
|
|
ITerminationActivator terminationActivator,
|
2018-07-04 09:53:33 +02:00
|
|
|
|
IText text,
|
2019-10-01 11:30:53 +02:00
|
|
|
|
IUserInterfaceFactory uiFactory)
|
2017-07-26 14:36:20 +02:00
|
|
|
|
{
|
2019-03-06 16:10:00 +01:00
|
|
|
|
this.actionCenter = actionCenter;
|
2019-10-01 11:30:53 +02:00
|
|
|
|
this.applicationMonitor = applicationMonitor;
|
2019-10-01 16:24:10 +02:00
|
|
|
|
this.context = context;
|
2017-08-11 08:28:17 +02:00
|
|
|
|
this.displayMonitor = displayMonitor;
|
2018-08-17 14:48:50 +02:00
|
|
|
|
this.explorerShell = explorerShell;
|
2019-01-10 10:04:30 +01:00
|
|
|
|
this.hashAlgorithm = hashAlgorithm;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
this.logger = logger;
|
2018-03-14 12:07:20 +01:00
|
|
|
|
this.messageBox = messageBox;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
this.operations = operations;
|
2018-02-14 15:26:05 +01:00
|
|
|
|
this.runtime = runtime;
|
2018-02-21 14:01:21 +01:00
|
|
|
|
this.shutdown = shutdown;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
this.taskbar = taskbar;
|
2019-03-29 07:46:21 +01:00
|
|
|
|
this.terminationActivator = terminationActivator;
|
2018-07-04 09:53:33 +02:00
|
|
|
|
this.text = text;
|
2018-02-21 14:01:21 +01:00
|
|
|
|
this.uiFactory = uiFactory;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 15:15:26 +01:00
|
|
|
|
public bool TryStart()
|
2018-02-12 12:21:55 +01:00
|
|
|
|
{
|
2018-08-16 11:23:37 +02:00
|
|
|
|
logger.Info("Initiating startup procedure...");
|
2018-02-22 10:00:18 +01:00
|
|
|
|
|
2018-02-21 14:01:21 +01:00
|
|
|
|
splashScreen = uiFactory.CreateSplashScreen();
|
2019-10-01 11:30:53 +02:00
|
|
|
|
operations.ActionRequired += Operations_ActionRequired;
|
2018-10-03 14:35:27 +02:00
|
|
|
|
operations.ProgressChanged += Operations_ProgressChanged;
|
|
|
|
|
operations.StatusChanged += Operations_StatusChanged;
|
2018-02-21 14:01:21 +01:00
|
|
|
|
|
2018-02-28 15:49:06 +01:00
|
|
|
|
var success = operations.TryPerform() == OperationResult.Success;
|
2018-02-14 15:26:05 +01:00
|
|
|
|
|
2018-02-20 15:15:26 +01:00
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
RegisterEvents();
|
2019-03-06 16:10:00 +01:00
|
|
|
|
ShowShell();
|
2018-11-15 08:45:17 +01:00
|
|
|
|
StartBrowser();
|
2018-02-27 15:28:54 +01:00
|
|
|
|
|
2018-08-10 13:23:24 +02:00
|
|
|
|
var communication = runtime.InformClientReady();
|
|
|
|
|
|
|
|
|
|
if (communication.Success)
|
2018-02-27 15:28:54 +01:00
|
|
|
|
{
|
2018-08-16 11:23:37 +02:00
|
|
|
|
logger.Info("Application successfully initialized.");
|
2018-08-10 13:23:24 +02:00
|
|
|
|
logger.Log(string.Empty);
|
2018-02-27 15:28:54 +01:00
|
|
|
|
}
|
2018-08-10 13:23:24 +02:00
|
|
|
|
else
|
2018-02-27 15:28:54 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
success = false;
|
|
|
|
|
logger.Error("Failed to inform runtime that client is ready!");
|
2018-02-27 15:28:54 +01:00
|
|
|
|
}
|
2018-02-22 10:00:18 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-08-16 11:23:37 +02:00
|
|
|
|
logger.Info("Application startup aborted!");
|
2018-02-22 10:00:18 +01:00
|
|
|
|
logger.Log(string.Empty);
|
2018-02-20 15:15:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-06 16:10:00 +01:00
|
|
|
|
splashScreen.Close();
|
|
|
|
|
|
2018-02-20 15:15:26 +01:00
|
|
|
|
return success;
|
2018-02-12 12:21:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 15:15:26 +01:00
|
|
|
|
public void Terminate()
|
2017-07-26 14:36:20 +02:00
|
|
|
|
{
|
2018-02-22 10:00:18 +01:00
|
|
|
|
logger.Log(string.Empty);
|
2018-08-16 11:23:37 +02:00
|
|
|
|
logger.Info("Initiating shutdown procedure...");
|
2018-02-22 10:00:18 +01:00
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
splashScreen = uiFactory.CreateSplashScreen(context.AppConfig);
|
2019-03-06 16:10:00 +01:00
|
|
|
|
actionCenter.Close();
|
|
|
|
|
taskbar.Close();
|
2017-07-26 14:36:20 +02:00
|
|
|
|
|
2018-02-21 14:01:21 +01:00
|
|
|
|
DeregisterEvents();
|
2018-02-27 15:28:54 +01:00
|
|
|
|
|
2018-10-10 09:19:03 +02:00
|
|
|
|
var success = operations.TryRevert() == OperationResult.Success;
|
2018-02-22 10:00:18 +01:00
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
2018-08-16 11:23:37 +02:00
|
|
|
|
logger.Info("Application successfully finalized.");
|
2018-02-22 10:00:18 +01:00
|
|
|
|
logger.Log(string.Empty);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-08-16 11:23:37 +02:00
|
|
|
|
logger.Info("Shutdown procedure failed!");
|
2018-02-22 10:00:18 +01:00
|
|
|
|
logger.Log(string.Empty);
|
|
|
|
|
}
|
2018-02-21 14:01:21 +01:00
|
|
|
|
|
2018-10-04 11:24:16 +02:00
|
|
|
|
splashScreen.Close();
|
2018-02-20 15:15:26 +01:00
|
|
|
|
}
|
2018-02-14 15:26:05 +01:00
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
public void UpdateAppConfig()
|
|
|
|
|
{
|
|
|
|
|
if (splashScreen != null)
|
|
|
|
|
{
|
|
|
|
|
splashScreen.AppConfig = context.AppConfig;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 15:15:26 +01:00
|
|
|
|
private void RegisterEvents()
|
|
|
|
|
{
|
2019-03-15 11:38:59 +01:00
|
|
|
|
actionCenter.QuitButtonClicked += Shell_QuitButtonClicked;
|
2019-10-01 11:30:53 +02:00
|
|
|
|
applicationMonitor.ExplorerStarted += ApplicationMonitor_ExplorerStarted;
|
2018-06-21 07:56:25 +02:00
|
|
|
|
Browser.ConfigurationDownloadRequested += Browser_ConfigurationDownloadRequested;
|
2018-12-14 12:31:31 +01:00
|
|
|
|
ClientHost.MessageBoxRequested += ClientHost_MessageBoxRequested;
|
2018-07-04 09:53:33 +02:00
|
|
|
|
ClientHost.PasswordRequested += ClientHost_PasswordRequested;
|
|
|
|
|
ClientHost.ReconfigurationDenied += ClientHost_ReconfigurationDenied;
|
2018-02-20 15:15:26 +01:00
|
|
|
|
ClientHost.Shutdown += ClientHost_Shutdown;
|
|
|
|
|
displayMonitor.DisplayChanged += DisplayMonitor_DisplaySettingsChanged;
|
2018-02-27 15:28:54 +01:00
|
|
|
|
runtime.ConnectionLost += Runtime_ConnectionLost;
|
2019-03-15 11:38:59 +01:00
|
|
|
|
taskbar.QuitButtonClicked += Shell_QuitButtonClicked;
|
2019-03-29 07:46:21 +01:00
|
|
|
|
terminationActivator.Activated += TerminationActivator_Activated;
|
2018-02-20 15:15:26 +01:00
|
|
|
|
}
|
2018-02-14 15:26:05 +01:00
|
|
|
|
|
2018-02-20 15:15:26 +01:00
|
|
|
|
private void DeregisterEvents()
|
|
|
|
|
{
|
2019-03-15 11:38:59 +01:00
|
|
|
|
actionCenter.QuitButtonClicked -= Shell_QuitButtonClicked;
|
2019-10-01 11:30:53 +02:00
|
|
|
|
applicationMonitor.ExplorerStarted -= ApplicationMonitor_ExplorerStarted;
|
2018-02-20 15:15:26 +01:00
|
|
|
|
displayMonitor.DisplayChanged -= DisplayMonitor_DisplaySettingsChanged;
|
2018-02-27 15:28:54 +01:00
|
|
|
|
runtime.ConnectionLost -= Runtime_ConnectionLost;
|
2019-03-15 11:38:59 +01:00
|
|
|
|
taskbar.QuitButtonClicked -= Shell_QuitButtonClicked;
|
2019-03-29 07:46:21 +01:00
|
|
|
|
terminationActivator.Activated -= TerminationActivator_Activated;
|
2019-01-23 10:07:20 +01:00
|
|
|
|
|
|
|
|
|
if (Browser != null)
|
|
|
|
|
{
|
|
|
|
|
Browser.ConfigurationDownloadRequested -= Browser_ConfigurationDownloadRequested;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ClientHost != null)
|
|
|
|
|
{
|
|
|
|
|
ClientHost.MessageBoxRequested -= ClientHost_MessageBoxRequested;
|
|
|
|
|
ClientHost.PasswordRequested -= ClientHost_PasswordRequested;
|
|
|
|
|
ClientHost.ReconfigurationDenied -= ClientHost_ReconfigurationDenied;
|
|
|
|
|
ClientHost.Shutdown -= ClientHost_Shutdown;
|
|
|
|
|
}
|
2017-07-26 14:36:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-06 16:10:00 +01:00
|
|
|
|
private void ShowShell()
|
|
|
|
|
{
|
|
|
|
|
if (Settings.Taskbar.EnableTaskbar)
|
|
|
|
|
{
|
|
|
|
|
taskbar.Show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 08:45:17 +01:00
|
|
|
|
private void StartBrowser()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Starting browser application...");
|
|
|
|
|
Browser.Start();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 11:30:53 +02:00
|
|
|
|
private void ApplicationMonitor_ExplorerStarted()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Trying to terminate Windows explorer...");
|
|
|
|
|
explorerShell.Terminate();
|
|
|
|
|
logger.Info("Reinitializing working area...");
|
|
|
|
|
displayMonitor.InitializePrimaryDisplay(taskbar.GetAbsoluteHeight());
|
|
|
|
|
logger.Info("Reinitializing shell...");
|
|
|
|
|
actionCenter.InitializeBounds();
|
|
|
|
|
taskbar.InitializeBounds();
|
|
|
|
|
logger.Info("Desktop successfully restored.");
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-21 07:56:25 +02:00
|
|
|
|
private void Browser_ConfigurationDownloadRequested(string fileName, DownloadEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (Settings.ConfigurationMode == ConfigurationMode.ConfigureClient)
|
|
|
|
|
{
|
2019-09-04 15:12:59 +02:00
|
|
|
|
args.AllowDownload = true;
|
|
|
|
|
args.Callback = Browser_ConfigurationDownloadFinished;
|
2019-10-01 16:24:10 +02:00
|
|
|
|
args.DownloadPath = Path.Combine(context.AppConfig.DownloadDirectory, fileName);
|
2019-09-04 15:12:59 +02:00
|
|
|
|
logger.Info($"Allowed download request for configuration file '{fileName}'.");
|
2018-06-21 07:56:25 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-09-04 15:12:59 +02:00
|
|
|
|
args.AllowDownload = false;
|
2018-06-21 07:56:25 +02:00
|
|
|
|
logger.Info($"Denied download request for configuration file '{fileName}' due to '{Settings.ConfigurationMode}' mode.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Browser_ConfigurationDownloadFinished(bool success, string filePath = null)
|
|
|
|
|
{
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
var communication = runtime.RequestReconfiguration(filePath);
|
|
|
|
|
|
|
|
|
|
if (communication.Success)
|
2018-06-21 07:56:25 +02:00
|
|
|
|
{
|
|
|
|
|
logger.Info($"Sent reconfiguration request for '{filePath}' to the runtime.");
|
2019-06-12 08:46:10 +02:00
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
splashScreen = uiFactory.CreateSplashScreen(context.AppConfig);
|
2019-06-12 08:46:10 +02:00
|
|
|
|
splashScreen.SetIndeterminate();
|
|
|
|
|
splashScreen.UpdateStatus(TextKey.OperationStatus_InitializeSession, true);
|
|
|
|
|
splashScreen.Show();
|
2018-06-21 07:56:25 +02:00
|
|
|
|
}
|
2018-08-10 13:23:24 +02:00
|
|
|
|
else
|
2018-06-21 07:56:25 +02:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
logger.Error($"Failed to communicate reconfiguration request for '{filePath}'!");
|
2018-06-21 07:56:25 +02:00
|
|
|
|
messageBox.Show(TextKey.MessageBox_ReconfigurationError, TextKey.MessageBox_ReconfigurationErrorTitle, icon: MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"Failed to download configuration file '{filePath}'!");
|
|
|
|
|
messageBox.Show(TextKey.MessageBox_ConfigurationDownloadError, TextKey.MessageBox_ConfigurationDownloadErrorTitle, icon: MessageBoxIcon.Error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-14 12:31:31 +01:00
|
|
|
|
private void ClientHost_MessageBoxRequested(MessageBoxRequestEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
logger.Info($"Received message box request with id '{args.RequestId}'.");
|
|
|
|
|
|
2019-08-30 14:02:36 +02:00
|
|
|
|
var action = (MessageBoxAction) args.Action;
|
|
|
|
|
var icon = (MessageBoxIcon) args.Icon;
|
|
|
|
|
var result = messageBox.Show(args.Message, args.Title, action, icon, parent: splashScreen);
|
2018-12-14 12:31:31 +01:00
|
|
|
|
|
2019-08-30 14:02:36 +02:00
|
|
|
|
runtime.SubmitMessageBoxResult(args.RequestId, (int) result);
|
2018-12-14 12:31:31 +01:00
|
|
|
|
logger.Info($"Message box request with id '{args.RequestId}' yielded result '{result}'.");
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-04 09:53:33 +02:00
|
|
|
|
private void ClientHost_PasswordRequested(PasswordRequestEventArgs args)
|
|
|
|
|
{
|
2019-01-30 14:43:41 +01:00
|
|
|
|
var message = default(TextKey);
|
|
|
|
|
var title = default(TextKey);
|
2018-07-04 09:53:33 +02:00
|
|
|
|
|
|
|
|
|
logger.Info($"Received input request with id '{args.RequestId}' for the {args.Purpose.ToString().ToLower()} password.");
|
|
|
|
|
|
2019-01-30 14:43:41 +01:00
|
|
|
|
switch (args.Purpose)
|
|
|
|
|
{
|
|
|
|
|
case PasswordRequestPurpose.LocalAdministrator:
|
|
|
|
|
message = TextKey.PasswordDialog_LocalAdminPasswordRequired;
|
|
|
|
|
title = TextKey.PasswordDialog_LocalAdminPasswordRequiredTitle;
|
|
|
|
|
break;
|
|
|
|
|
case PasswordRequestPurpose.LocalSettings:
|
|
|
|
|
message = TextKey.PasswordDialog_LocalSettingsPasswordRequired;
|
|
|
|
|
title = TextKey.PasswordDialog_LocalSettingsPasswordRequiredTitle;
|
|
|
|
|
break;
|
|
|
|
|
case PasswordRequestPurpose.Settings:
|
|
|
|
|
message = TextKey.PasswordDialog_SettingsPasswordRequired;
|
|
|
|
|
title = TextKey.PasswordDialog_SettingsPasswordRequiredTitle;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dialog = uiFactory.CreatePasswordDialog(text.Get(message), text.Get(title));
|
2018-07-04 09:53:33 +02:00
|
|
|
|
var result = dialog.Show();
|
|
|
|
|
|
|
|
|
|
runtime.SubmitPassword(args.RequestId, result.Success, result.Password);
|
|
|
|
|
logger.Info($"Password request with id '{args.RequestId}' was {(result.Success ? "successful" : "aborted by the user")}.");
|
2019-06-12 08:46:10 +02:00
|
|
|
|
|
|
|
|
|
if (!result.Success)
|
|
|
|
|
{
|
|
|
|
|
splashScreen?.Close();
|
|
|
|
|
}
|
2018-07-04 09:53:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ClientHost_ReconfigurationDenied(ReconfigurationEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
logger.Info($"The reconfiguration request for '{args.ConfigurationPath}' was denied by the runtime!");
|
2019-06-12 08:46:10 +02:00
|
|
|
|
messageBox.Show(TextKey.MessageBox_ReconfigurationDenied, TextKey.MessageBox_ReconfigurationDeniedTitle, parent: splashScreen);
|
|
|
|
|
splashScreen?.Close();
|
2018-07-04 09:53:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-20 15:15:26 +01:00
|
|
|
|
private void ClientHost_Shutdown()
|
|
|
|
|
{
|
2018-02-21 14:01:21 +01:00
|
|
|
|
shutdown.Invoke();
|
2018-02-20 15:15:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-15 11:38:59 +01:00
|
|
|
|
private void DisplayMonitor_DisplaySettingsChanged()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Reinitializing working area...");
|
|
|
|
|
displayMonitor.InitializePrimaryDisplay(taskbar.GetAbsoluteHeight());
|
2019-03-19 16:09:07 +01:00
|
|
|
|
logger.Info("Reinitializing shell...");
|
2019-03-20 10:08:10 +01:00
|
|
|
|
actionCenter.InitializeBounds();
|
2019-03-15 11:38:59 +01:00
|
|
|
|
taskbar.InitializeBounds();
|
|
|
|
|
logger.Info("Desktop successfully restored.");
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 11:30:53 +02:00
|
|
|
|
private void Operations_ActionRequired(ActionRequiredEventArgs args)
|
|
|
|
|
{
|
2019-10-04 16:36:12 +02:00
|
|
|
|
switch (args)
|
|
|
|
|
{
|
|
|
|
|
case ApplicationTerminationEventArgs a:
|
|
|
|
|
AskForAutomaticApplicationTermination(a);
|
|
|
|
|
break;
|
|
|
|
|
case ApplicationTerminationFailedEventArgs a:
|
|
|
|
|
InformAboutFailedApplicationTermination(a);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-10-01 11:30:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-03 14:35:27 +02:00
|
|
|
|
private void Operations_ProgressChanged(ProgressChangedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
if (args.CurrentValue.HasValue)
|
|
|
|
|
{
|
|
|
|
|
splashScreen?.SetValue(args.CurrentValue.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (args.IsIndeterminate == true)
|
|
|
|
|
{
|
|
|
|
|
splashScreen?.SetIndeterminate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (args.MaxValue.HasValue)
|
|
|
|
|
{
|
|
|
|
|
splashScreen?.SetMaxValue(args.MaxValue.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (args.Progress == true)
|
|
|
|
|
{
|
|
|
|
|
splashScreen?.Progress();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (args.Regress == true)
|
|
|
|
|
{
|
|
|
|
|
splashScreen?.Regress();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Operations_StatusChanged(TextKey status)
|
|
|
|
|
{
|
2018-10-04 11:24:16 +02:00
|
|
|
|
splashScreen?.UpdateStatus(status, true);
|
2018-10-03 14:35:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-27 15:28:54 +01:00
|
|
|
|
private void Runtime_ConnectionLost()
|
|
|
|
|
{
|
|
|
|
|
logger.Error("Lost connection to the runtime!");
|
2018-03-14 12:07:20 +01:00
|
|
|
|
messageBox.Show(TextKey.MessageBox_ApplicationError, TextKey.MessageBox_ApplicationErrorTitle, icon: MessageBoxIcon.Error);
|
2018-02-27 15:28:54 +01:00
|
|
|
|
|
|
|
|
|
shutdown.Invoke();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-15 11:38:59 +01:00
|
|
|
|
private void Shell_QuitButtonClicked(System.ComponentModel.CancelEventArgs args)
|
2019-03-29 07:46:21 +01:00
|
|
|
|
{
|
|
|
|
|
terminationActivator.Pause();
|
|
|
|
|
args.Cancel = !TryInitiateShutdown();
|
|
|
|
|
terminationActivator.Resume();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TerminationActivator_Activated()
|
|
|
|
|
{
|
|
|
|
|
terminationActivator.Pause();
|
|
|
|
|
TryInitiateShutdown();
|
|
|
|
|
terminationActivator.Resume();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-04 16:36:12 +02:00
|
|
|
|
private void AskForAutomaticApplicationTermination(ApplicationTerminationEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var nl = Environment.NewLine;
|
|
|
|
|
var applicationList = string.Join(Environment.NewLine, args.RunningApplications.Select(a => a.Name));
|
|
|
|
|
var warning = text.Get(TextKey.MessageBox_ApplicationAutoTerminationDataLossWarning);
|
|
|
|
|
var message = $"{text.Get(TextKey.MessageBox_ApplicationAutoTerminationQuestion)}{nl}{nl}{warning}{nl}{nl}{applicationList}";
|
|
|
|
|
var title = text.Get(TextKey.MessageBox_ApplicationAutoTerminationQuestionTitle);
|
|
|
|
|
var result = messageBox.Show(message, title, MessageBoxAction.YesNo, MessageBoxIcon.Question, parent: splashScreen);
|
|
|
|
|
|
|
|
|
|
args.TerminateProcesses = result == MessageBoxResult.Yes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InformAboutFailedApplicationTermination(ApplicationTerminationFailedEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
var applicationList = string.Join(Environment.NewLine, args.Applications.Select(a => a.Name));
|
|
|
|
|
var message = $"{text.Get(TextKey.MessageBox_ApplicationTerminationFailure)}{Environment.NewLine}{Environment.NewLine}{applicationList}";
|
|
|
|
|
var title = text.Get(TextKey.MessageBox_ApplicationTerminationFailureTitle);
|
|
|
|
|
|
|
|
|
|
messageBox.Show(message, title, icon: MessageBoxIcon.Error, parent: splashScreen);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-29 07:46:21 +01:00
|
|
|
|
private bool TryInitiateShutdown()
|
2018-02-20 15:15:26 +01:00
|
|
|
|
{
|
2019-01-10 10:04:30 +01:00
|
|
|
|
var hasQuitPassword = !String.IsNullOrEmpty(Settings.QuitPasswordHash);
|
|
|
|
|
var requestShutdown = false;
|
|
|
|
|
|
|
|
|
|
if (hasQuitPassword)
|
|
|
|
|
{
|
|
|
|
|
requestShutdown = TryValidateQuitPassword();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
requestShutdown = TryConfirmShutdown();
|
|
|
|
|
}
|
2018-02-27 15:28:54 +01:00
|
|
|
|
|
2019-01-10 10:04:30 +01:00
|
|
|
|
if (requestShutdown)
|
2018-02-27 15:28:54 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
var communication = runtime.RequestShutdown();
|
|
|
|
|
|
2019-03-29 07:46:21 +01:00
|
|
|
|
if (communication.Success)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else
|
2018-02-27 15:28:54 +01:00
|
|
|
|
{
|
2018-08-10 13:23:24 +02:00
|
|
|
|
logger.Error("Failed to communicate shutdown request to the runtime!");
|
2018-03-14 12:07:20 +01:00
|
|
|
|
messageBox.Show(TextKey.MessageBox_QuitError, TextKey.MessageBox_QuitErrorTitle, icon: MessageBoxIcon.Error);
|
2018-02-27 15:28:54 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-20 15:15:26 +01:00
|
|
|
|
|
2019-03-29 07:46:21 +01:00
|
|
|
|
return false;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
}
|
2019-01-10 10:04:30 +01:00
|
|
|
|
|
|
|
|
|
private bool TryConfirmShutdown()
|
|
|
|
|
{
|
|
|
|
|
var result = messageBox.Show(TextKey.MessageBox_Quit, TextKey.MessageBox_QuitTitle, MessageBoxAction.YesNo, MessageBoxIcon.Question);
|
|
|
|
|
var quit = result == MessageBoxResult.Yes;
|
|
|
|
|
|
|
|
|
|
if (quit)
|
|
|
|
|
{
|
|
|
|
|
logger.Info("The user chose to terminate the application.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return quit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool TryValidateQuitPassword()
|
|
|
|
|
{
|
|
|
|
|
var dialog = uiFactory.CreatePasswordDialog(TextKey.PasswordDialog_QuitPasswordRequired, TextKey.PasswordDialog_QuitPasswordRequiredTitle);
|
|
|
|
|
var result = dialog.Show();
|
|
|
|
|
|
|
|
|
|
if (result.Success)
|
|
|
|
|
{
|
|
|
|
|
var passwordHash = hashAlgorithm.GenerateHashFor(result.Password);
|
|
|
|
|
var isCorrect = Settings.QuitPasswordHash.Equals(passwordHash, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
if (isCorrect)
|
|
|
|
|
{
|
|
|
|
|
logger.Info("The user entered the correct quit password, the application will now terminate.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Info("The user entered the wrong quit password.");
|
|
|
|
|
messageBox.Show(TextKey.MessageBox_InvalidQuitPassword, TextKey.MessageBox_InvalidQuitPasswordTitle, icon: MessageBoxIcon.Warning);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return isCorrect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-07-26 14:36:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|