2017-07-26 14:36:20 +02:00
|
|
|
|
/*
|
2018-01-16 08:24:00 +01:00
|
|
|
|
* Copyright (c) 2018 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-01-24 07:46:22 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
using SafeExamBrowser.Contracts.Monitoring;
|
2017-08-15 15:30:31 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface.Taskbar;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
|
2018-01-18 08:16:20 +01:00
|
|
|
|
namespace SafeExamBrowser.Client.Behaviour
|
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
|
|
|
|
{
|
2017-08-11 08:28:17 +02:00
|
|
|
|
private IDisplayMonitor displayMonitor;
|
2017-07-27 11:46:31 +02:00
|
|
|
|
private ILogger logger;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
private IProcessMonitor processMonitor;
|
|
|
|
|
private ITaskbar taskbar;
|
2017-07-27 11:46:31 +02:00
|
|
|
|
private IWindowMonitor windowMonitor;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
|
2018-01-17 08:26:44 +01:00
|
|
|
|
public ClientController(
|
2017-08-11 08:28:17 +02:00
|
|
|
|
IDisplayMonitor displayMonitor,
|
2017-07-27 11:46:31 +02:00
|
|
|
|
ILogger logger,
|
|
|
|
|
IProcessMonitor processMonitor,
|
|
|
|
|
ITaskbar taskbar,
|
2017-08-11 08:28:17 +02:00
|
|
|
|
IWindowMonitor windowMonitor)
|
2017-07-26 14:36:20 +02:00
|
|
|
|
{
|
2017-08-11 08:28:17 +02:00
|
|
|
|
this.displayMonitor = displayMonitor;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.processMonitor = processMonitor;
|
|
|
|
|
this.taskbar = taskbar;
|
2017-07-27 11:46:31 +02:00
|
|
|
|
this.windowMonitor = windowMonitor;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
2017-08-11 08:28:17 +02:00
|
|
|
|
displayMonitor.DisplayChanged += DisplayMonitor_DisplaySettingsChanged;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
processMonitor.ExplorerStarted += ProcessMonitor_ExplorerStarted;
|
2017-07-27 13:57:12 +02:00
|
|
|
|
windowMonitor.WindowChanged += WindowMonitor_WindowChanged;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Stop()
|
|
|
|
|
{
|
2017-10-10 10:17:28 +02:00
|
|
|
|
displayMonitor.DisplayChanged -= DisplayMonitor_DisplaySettingsChanged;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
processMonitor.ExplorerStarted -= ProcessMonitor_ExplorerStarted;
|
2017-07-27 13:57:12 +02:00
|
|
|
|
windowMonitor.WindowChanged -= WindowMonitor_WindowChanged;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-11 08:28:17 +02:00
|
|
|
|
private void DisplayMonitor_DisplaySettingsChanged()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Reinitializing working area...");
|
|
|
|
|
displayMonitor.InitializePrimaryDisplay(taskbar.GetAbsoluteHeight());
|
|
|
|
|
logger.Info("Reinitializing taskbar bounds...");
|
|
|
|
|
taskbar.InitializeBounds();
|
|
|
|
|
logger.Info("Desktop successfully restored.");
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-26 14:36:20 +02:00
|
|
|
|
private void ProcessMonitor_ExplorerStarted()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Trying to shut down explorer...");
|
|
|
|
|
processMonitor.CloseExplorerShell();
|
|
|
|
|
logger.Info("Reinitializing working area...");
|
2017-08-11 08:28:17 +02:00
|
|
|
|
displayMonitor.InitializePrimaryDisplay(taskbar.GetAbsoluteHeight());
|
2017-07-26 14:36:20 +02:00
|
|
|
|
logger.Info("Reinitializing taskbar bounds...");
|
|
|
|
|
taskbar.InitializeBounds();
|
2017-07-27 13:57:12 +02:00
|
|
|
|
logger.Info("Desktop successfully restored.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void WindowMonitor_WindowChanged(IntPtr window)
|
|
|
|
|
{
|
|
|
|
|
var allowed = processMonitor.BelongsToAllowedProcess(window);
|
|
|
|
|
|
|
|
|
|
if (!allowed)
|
|
|
|
|
{
|
|
|
|
|
var success = windowMonitor.Hide(window);
|
|
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
|
{
|
|
|
|
|
windowMonitor.Close(window);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-26 14:36:20 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|