2021-02-10 23:21:48 +01:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
2021-02-10 23:21:48 +01: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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-03-10 21:26:45 +01:00
|
|
|
|
using System;
|
2024-01-18 18:02:21 +01:00
|
|
|
|
using System.Collections.Generic;
|
2024-02-29 21:05:43 +01:00
|
|
|
|
using KGySoft.CoreLibraries;
|
2024-02-13 11:04:36 +01:00
|
|
|
|
using SafeExamBrowser.Browser.Contracts;
|
2021-03-17 00:05:29 +01:00
|
|
|
|
using SafeExamBrowser.Configuration.Contracts;
|
2021-03-18 23:12:07 +01:00
|
|
|
|
using SafeExamBrowser.Core.Contracts.Notifications;
|
2021-03-25 13:49:45 +01:00
|
|
|
|
using SafeExamBrowser.I18n.Contracts;
|
2021-03-10 21:26:45 +01:00
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2024-02-13 11:04:36 +01:00
|
|
|
|
using SafeExamBrowser.Monitoring.Contracts.Applications;
|
2021-02-10 23:21:48 +01:00
|
|
|
|
using SafeExamBrowser.Proctoring.Contracts;
|
2021-09-17 10:47:02 +02:00
|
|
|
|
using SafeExamBrowser.Proctoring.Contracts.Events;
|
2021-04-12 10:59:31 +02:00
|
|
|
|
using SafeExamBrowser.Server.Contracts;
|
2024-02-01 17:36:11 +01:00
|
|
|
|
using SafeExamBrowser.Server.Contracts.Events.Proctoring;
|
2021-02-19 22:03:52 +01:00
|
|
|
|
using SafeExamBrowser.Settings.Proctoring;
|
2021-03-17 00:05:29 +01:00
|
|
|
|
using SafeExamBrowser.SystemComponents.Contracts;
|
2021-02-19 22:03:52 +01:00
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts;
|
2024-02-06 10:45:45 +01:00
|
|
|
|
using SafeExamBrowser.WindowsApi.Contracts;
|
2021-02-10 23:21:48 +01:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Proctoring
|
|
|
|
|
{
|
2024-01-18 18:02:21 +01:00
|
|
|
|
public class ProctoringController : IProctoringController
|
2021-02-10 23:21:48 +01:00
|
|
|
|
{
|
2024-01-18 18:02:21 +01:00
|
|
|
|
private readonly ProctoringFactory factory;
|
2021-03-10 21:26:45 +01:00
|
|
|
|
private readonly IModuleLogger logger;
|
2021-04-12 10:59:31 +02:00
|
|
|
|
private readonly IServerProxy server;
|
2021-02-10 23:21:48 +01:00
|
|
|
|
|
2024-01-18 18:02:21 +01:00
|
|
|
|
private IEnumerable<ProctoringImplementation> implementations;
|
2021-02-19 22:03:52 +01:00
|
|
|
|
|
2021-09-17 10:47:02 +02:00
|
|
|
|
public bool IsHandRaised { get; private set; }
|
2024-01-18 18:02:21 +01:00
|
|
|
|
public IEnumerable<INotification> Notifications => new List<INotification>(implementations);
|
2021-03-18 23:12:07 +01:00
|
|
|
|
|
2021-09-17 10:47:02 +02:00
|
|
|
|
public event ProctoringEventHandler HandLowered;
|
|
|
|
|
public event ProctoringEventHandler HandRaised;
|
2024-02-29 21:05:43 +01:00
|
|
|
|
public event RemainingWorkUpdatedEventHandler RemainingWorkUpdated
|
|
|
|
|
{
|
|
|
|
|
add { implementations.ForEach(i => i.RemainingWorkUpdated += value); }
|
|
|
|
|
remove { implementations.ForEach(i => i.RemainingWorkUpdated -= value); }
|
|
|
|
|
}
|
2021-03-25 13:49:45 +01:00
|
|
|
|
|
2021-04-12 10:59:31 +02:00
|
|
|
|
public ProctoringController(
|
|
|
|
|
AppConfig appConfig,
|
2024-02-13 11:04:36 +01:00
|
|
|
|
IApplicationMonitor applicationMonitor,
|
|
|
|
|
IBrowserApplication browser,
|
2021-04-12 10:59:31 +02:00
|
|
|
|
IFileSystem fileSystem,
|
|
|
|
|
IModuleLogger logger,
|
2024-02-06 10:45:45 +01:00
|
|
|
|
INativeMethods nativeMethods,
|
2021-04-12 10:59:31 +02:00
|
|
|
|
IServerProxy server,
|
|
|
|
|
IText text,
|
|
|
|
|
IUserInterfaceFactory uiFactory)
|
2021-02-19 22:03:52 +01:00
|
|
|
|
{
|
2021-03-10 21:26:45 +01:00
|
|
|
|
this.logger = logger;
|
2021-04-12 10:59:31 +02:00
|
|
|
|
this.server = server;
|
2021-03-25 13:49:45 +01:00
|
|
|
|
|
2024-02-13 11:04:36 +01:00
|
|
|
|
factory = new ProctoringFactory(appConfig, applicationMonitor, browser, fileSystem, logger, nativeMethods, text, uiFactory);
|
2024-01-18 18:02:21 +01:00
|
|
|
|
implementations = new List<ProctoringImplementation>();
|
2021-03-18 23:12:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-29 21:05:43 +01:00
|
|
|
|
public void ExecuteRemainingWork()
|
|
|
|
|
{
|
|
|
|
|
foreach (var implementation in implementations)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
implementation.ExecuteRemainingWork();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"Failed to execute remaining work for '{implementation.Name}'!", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasRemainingWork()
|
|
|
|
|
{
|
|
|
|
|
var hasWork = false;
|
|
|
|
|
|
|
|
|
|
foreach (var implementation in implementations)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (implementation.HasRemainingWork())
|
|
|
|
|
{
|
|
|
|
|
hasWork = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"Failed to check whether has remaining work for '{implementation.Name}'!", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return hasWork;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-19 22:03:52 +01:00
|
|
|
|
public void Initialize(ProctoringSettings settings)
|
|
|
|
|
{
|
2024-01-18 18:02:21 +01:00
|
|
|
|
implementations = factory.CreateAllActive(settings);
|
2021-03-23 21:12:47 +01:00
|
|
|
|
|
2021-09-17 10:47:02 +02:00
|
|
|
|
server.HandConfirmed += Server_HandConfirmed;
|
2021-04-12 10:59:31 +02:00
|
|
|
|
server.ProctoringConfigurationReceived += Server_ProctoringConfigurationReceived;
|
|
|
|
|
server.ProctoringInstructionReceived += Server_ProctoringInstructionReceived;
|
2021-02-19 22:03:52 +01:00
|
|
|
|
|
2024-01-18 18:02:21 +01:00
|
|
|
|
foreach (var implementation in implementations)
|
2021-04-12 10:59:31 +02:00
|
|
|
|
{
|
2024-01-18 18:02:21 +01:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
implementation.Initialize();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"Failed to initialize proctoring implementation '{implementation.Name}'!", e);
|
|
|
|
|
}
|
2021-04-12 10:59:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-03-04 16:05:22 +01:00
|
|
|
|
|
2021-09-17 10:47:02 +02:00
|
|
|
|
public void LowerHand()
|
|
|
|
|
{
|
|
|
|
|
var response = server.LowerHand();
|
|
|
|
|
|
|
|
|
|
if (response.Success)
|
|
|
|
|
{
|
|
|
|
|
IsHandRaised = false;
|
|
|
|
|
HandLowered?.Invoke();
|
2024-01-18 18:02:21 +01:00
|
|
|
|
|
2021-09-17 10:47:02 +02:00
|
|
|
|
logger.Info("Hand lowered.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"Failed to send lower hand notification to server! Message: {response.Message}.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RaiseHand(string message = null)
|
|
|
|
|
{
|
|
|
|
|
var response = server.RaiseHand(message);
|
|
|
|
|
|
|
|
|
|
if (response.Success)
|
|
|
|
|
{
|
|
|
|
|
IsHandRaised = true;
|
|
|
|
|
HandRaised?.Invoke();
|
2024-01-18 18:02:21 +01:00
|
|
|
|
|
2021-09-17 10:47:02 +02:00
|
|
|
|
logger.Info("Hand raised.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"Failed to send raise hand notification to server! Message: {response.Message}.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-12 10:59:31 +02:00
|
|
|
|
public void Terminate()
|
|
|
|
|
{
|
2024-01-18 18:02:21 +01:00
|
|
|
|
foreach (var implementation in implementations)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
implementation.Terminate();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"Failed to terminate proctoring implementation '{implementation.Name}'!", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-04-12 10:59:31 +02:00
|
|
|
|
}
|
2021-03-23 21:12:47 +01:00
|
|
|
|
|
2021-09-17 10:47:02 +02:00
|
|
|
|
private void Server_HandConfirmed()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Hand confirmation received.");
|
|
|
|
|
|
|
|
|
|
IsHandRaised = false;
|
|
|
|
|
HandLowered?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-12 15:59:42 +02:00
|
|
|
|
private void Server_ProctoringConfigurationReceived(bool allowChat, bool receiveAudio, bool receiveVideo)
|
2021-04-12 10:59:31 +02:00
|
|
|
|
{
|
2024-01-18 18:02:21 +01:00
|
|
|
|
foreach (var implementation in implementations)
|
2021-04-12 10:59:31 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-01-18 18:02:21 +01:00
|
|
|
|
implementation.ProctoringConfigurationReceived(allowChat, receiveAudio, receiveVideo);
|
2021-04-12 10:59:31 +02:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2024-01-18 18:02:21 +01:00
|
|
|
|
logger.Error($"Failed to update proctoring configuration for '{implementation.Name}'!", e);
|
2021-04-12 10:59:31 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-19 22:03:52 +01:00
|
|
|
|
}
|
2021-03-10 21:26:45 +01:00
|
|
|
|
|
2024-02-01 17:36:11 +01:00
|
|
|
|
private void Server_ProctoringInstructionReceived(InstructionEventArgs args)
|
2021-03-10 21:26:45 +01:00
|
|
|
|
{
|
2024-01-18 18:02:21 +01:00
|
|
|
|
foreach (var implementation in implementations)
|
2021-03-10 21:26:45 +01:00
|
|
|
|
{
|
2024-01-18 18:02:21 +01:00
|
|
|
|
try
|
2021-03-10 21:26:45 +01:00
|
|
|
|
{
|
2024-01-18 18:02:21 +01:00
|
|
|
|
implementation.ProctoringInstructionReceived(args);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
logger.Error($"Failed to process proctoring instruction for '{implementation.Name}'!", e);
|
2023-11-01 10:42:26 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-19 02:43:07 +02:00
|
|
|
|
}
|
2021-02-10 23:21:48 +01:00
|
|
|
|
}
|
|
|
|
|
}
|