2021-02-10 23:21:48 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-03-10 21:26:45 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2021-02-10 23:21:48 +01:00
|
|
|
|
using SafeExamBrowser.Proctoring.Contracts;
|
2021-02-19 22:03:52 +01:00
|
|
|
|
using SafeExamBrowser.Settings.Proctoring;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Proctoring;
|
2021-02-10 23:21:48 +01:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Proctoring
|
|
|
|
|
{
|
|
|
|
|
public class ProctoringController : IProctoringController
|
|
|
|
|
{
|
2021-03-10 21:26:45 +01:00
|
|
|
|
private readonly IModuleLogger logger;
|
2021-02-19 22:03:52 +01:00
|
|
|
|
private readonly IUserInterfaceFactory uiFactory;
|
2021-02-10 23:21:48 +01:00
|
|
|
|
|
2021-02-19 22:03:52 +01:00
|
|
|
|
private IProctoringWindow window;
|
|
|
|
|
|
2021-03-10 21:26:45 +01:00
|
|
|
|
public ProctoringController(IModuleLogger logger, IUserInterfaceFactory uiFactory)
|
2021-02-19 22:03:52 +01:00
|
|
|
|
{
|
2021-03-10 21:26:45 +01:00
|
|
|
|
this.logger = logger;
|
2021-02-19 22:03:52 +01:00
|
|
|
|
this.uiFactory = uiFactory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Initialize(ProctoringSettings settings)
|
|
|
|
|
{
|
2021-03-10 21:26:45 +01:00
|
|
|
|
if (settings.JitsiMeet.Enabled || settings.Zoom.Enabled)
|
|
|
|
|
{
|
|
|
|
|
var control = new ProctoringControl(logger.CloneFor(nameof(ProctoringControl)));
|
2021-02-19 22:03:52 +01:00
|
|
|
|
|
2021-03-10 21:26:45 +01:00
|
|
|
|
control.EnsureCoreWebView2Async().ContinueWith(_ =>
|
|
|
|
|
{
|
|
|
|
|
control.Dispatcher.Invoke(() => control.NavigateToString(LoadContent(settings)));
|
|
|
|
|
});
|
2021-03-04 16:05:22 +01:00
|
|
|
|
|
2021-03-10 21:26:45 +01:00
|
|
|
|
window = uiFactory.CreateProctoringWindow(control);
|
|
|
|
|
window.Show();
|
2021-03-04 16:05:22 +01:00
|
|
|
|
|
2021-03-10 21:26:45 +01:00
|
|
|
|
logger.Info($"Initialized proctoring with {(settings.JitsiMeet.Enabled ? "Jitsi Meet" : "Zoom")}.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger.Warn("Failed to initialize remote proctoring because no provider is enabled in the active configuration.");
|
|
|
|
|
}
|
2021-02-19 22:03:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Terminate()
|
|
|
|
|
{
|
|
|
|
|
window?.Close();
|
|
|
|
|
}
|
2021-03-10 21:26:45 +01:00
|
|
|
|
|
|
|
|
|
private string LoadContent(ProctoringSettings settings)
|
|
|
|
|
{
|
|
|
|
|
var provider = settings.JitsiMeet.Enabled ? "JitsiMeet" : "Zoom";
|
|
|
|
|
var assembly = Assembly.GetAssembly(typeof(ProctoringController));
|
|
|
|
|
var path = $"{typeof(ProctoringController).Namespace}.{provider}.index.html";
|
|
|
|
|
|
|
|
|
|
using (var stream = assembly.GetManifestResourceStream(path))
|
|
|
|
|
using (var reader = new StreamReader(stream))
|
|
|
|
|
{
|
|
|
|
|
var html = reader.ReadToEnd();
|
|
|
|
|
|
|
|
|
|
if (settings.JitsiMeet.Enabled)
|
|
|
|
|
{
|
|
|
|
|
html = html.Replace("%%_DOMAIN_%%", settings.JitsiMeet.ServerUrl);
|
|
|
|
|
html = html.Replace("%%_ROOM_NAME_%%", settings.JitsiMeet.RoomName);
|
|
|
|
|
html = html.Replace("%%_SUBJECT_%%", settings.JitsiMeet.Subject);
|
|
|
|
|
html = html.Replace("%%_TOKEN_%%", settings.JitsiMeet.Token);
|
|
|
|
|
}
|
|
|
|
|
else if (settings.Zoom.Enabled)
|
|
|
|
|
{
|
|
|
|
|
html = html.Replace("%%_API_KEY_%%", settings.Zoom.ApiKey);
|
|
|
|
|
html = html.Replace("%%_API_SECRET_%%", settings.Zoom.ApiSecret);
|
|
|
|
|
html = html.Replace("123456789", Convert.ToString(settings.Zoom.MeetingNumber));
|
|
|
|
|
html = html.Replace("%%_USER_NAME_%%", settings.Zoom.UserName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-10 23:21:48 +01:00
|
|
|
|
}
|
|
|
|
|
}
|