2017-07-26 14:36:20 +02:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET)
|
|
|
|
|
*
|
|
|
|
|
* 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;
|
2017-07-26 14:36:20 +02:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour;
|
|
|
|
|
using SafeExamBrowser.Contracts.Configuration;
|
|
|
|
|
using SafeExamBrowser.Contracts.Logging;
|
|
|
|
|
using SafeExamBrowser.Contracts.Monitoring;
|
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface;
|
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Core.Behaviour
|
|
|
|
|
{
|
2017-08-02 14:01:20 +02:00
|
|
|
|
public class RuntimeController : IRuntimeController
|
2017-07-26 14:36:20 +02:00
|
|
|
|
{
|
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
|
|
|
|
private IWorkingArea workingArea;
|
|
|
|
|
|
2017-08-02 14:01:20 +02:00
|
|
|
|
public RuntimeController(
|
2017-07-27 11:46:31 +02:00
|
|
|
|
ILogger logger,
|
|
|
|
|
IProcessMonitor processMonitor,
|
|
|
|
|
ITaskbar taskbar,
|
|
|
|
|
IWindowMonitor windowMonitor,
|
|
|
|
|
IWorkingArea workingArea)
|
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
|
|
|
|
this.workingArea = workingArea;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
processMonitor.ExplorerStarted -= ProcessMonitor_ExplorerStarted;
|
2017-07-27 13:57:12 +02:00
|
|
|
|
windowMonitor.WindowChanged -= WindowMonitor_WindowChanged;
|
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...");
|
|
|
|
|
workingArea.InitializeFor(taskbar);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|