2019-03-21 16:05:16 +01:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
2019-03-21 16:05:16 +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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-10-11 15:46:15 +02:00
|
|
|
|
using System.Collections.Generic;
|
2019-03-21 16:05:16 +01:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using FontAwesome.WPF;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Applications.Contracts;
|
|
|
|
|
using SafeExamBrowser.Configuration.Contracts;
|
2021-03-18 23:12:07 +01:00
|
|
|
|
using SafeExamBrowser.Core.Contracts.Notifications;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.I18n.Contracts;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2021-09-17 10:47:02 +02:00
|
|
|
|
using SafeExamBrowser.Proctoring.Contracts;
|
2020-07-28 19:56:25 +02:00
|
|
|
|
using SafeExamBrowser.Server.Contracts.Data;
|
2019-10-11 15:46:15 +02:00
|
|
|
|
using SafeExamBrowser.Settings.Browser;
|
2021-09-17 10:47:02 +02:00
|
|
|
|
using SafeExamBrowser.Settings.Proctoring;
|
2019-08-30 17:33:28 +02:00
|
|
|
|
using SafeExamBrowser.SystemComponents.Contracts.Audio;
|
2019-08-30 15:59:51 +02:00
|
|
|
|
using SafeExamBrowser.SystemComponents.Contracts.Keyboard;
|
2022-04-19 18:21:29 +02:00
|
|
|
|
using SafeExamBrowser.SystemComponents.Contracts.Network;
|
2019-09-03 11:46:36 +02:00
|
|
|
|
using SafeExamBrowser.SystemComponents.Contracts.PowerSupply;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Browser;
|
2021-02-19 22:03:52 +01:00
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Proctoring;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Shell;
|
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Windows;
|
2019-10-11 15:46:15 +02:00
|
|
|
|
using SafeExamBrowser.UserInterface.Contracts.Windows.Data;
|
2020-03-17 10:37:08 +01:00
|
|
|
|
using SafeExamBrowser.UserInterface.Mobile.Windows;
|
|
|
|
|
using SplashScreen = SafeExamBrowser.UserInterface.Mobile.Windows.SplashScreen;
|
2019-03-21 16:05:16 +01:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.UserInterface.Mobile
|
|
|
|
|
{
|
|
|
|
|
public class UserInterfaceFactory : IUserInterfaceFactory
|
|
|
|
|
{
|
2022-04-19 18:21:29 +02:00
|
|
|
|
private readonly IText text;
|
2019-03-21 16:05:16 +01:00
|
|
|
|
|
|
|
|
|
public UserInterfaceFactory(IText text)
|
|
|
|
|
{
|
|
|
|
|
this.text = text;
|
|
|
|
|
|
|
|
|
|
InitializeFontAwesome();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IWindow CreateAboutWindow(AppConfig appConfig)
|
|
|
|
|
{
|
|
|
|
|
return new AboutWindow(appConfig, text);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:07:40 +01:00
|
|
|
|
public IActionCenter CreateActionCenter()
|
|
|
|
|
{
|
|
|
|
|
return new ActionCenter();
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-13 11:04:36 +01:00
|
|
|
|
public IApplicationControl CreateApplicationControl(IApplication<IApplicationWindow> application, Location location)
|
2019-03-21 16:05:16 +01:00
|
|
|
|
{
|
|
|
|
|
if (location == Location.ActionCenter)
|
|
|
|
|
{
|
2020-03-17 10:37:08 +01:00
|
|
|
|
return new Controls.ActionCenter.ApplicationControl(application);
|
2019-03-21 16:05:16 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-17 10:37:08 +01:00
|
|
|
|
return new Controls.Taskbar.ApplicationControl(application);
|
2019-03-21 16:05:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 17:33:28 +02:00
|
|
|
|
public ISystemControl CreateAudioControl(IAudio audio, Location location)
|
2019-08-15 10:46:47 +02:00
|
|
|
|
{
|
2019-08-16 10:08:10 +02:00
|
|
|
|
if (location == Location.ActionCenter)
|
|
|
|
|
{
|
2020-03-17 10:37:08 +01:00
|
|
|
|
return new Controls.ActionCenter.AudioControl(audio, text);
|
2019-08-16 10:08:10 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-17 10:37:08 +01:00
|
|
|
|
return new Controls.Taskbar.AudioControl(audio, text);
|
2019-08-16 10:08:10 +02:00
|
|
|
|
}
|
2019-08-15 10:46:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-05-03 08:59:22 +02:00
|
|
|
|
public IBrowserWindow CreateBrowserWindow(IBrowserControl control, BrowserSettings settings, bool isMainWindow, ILogger logger)
|
2019-03-21 16:05:16 +01:00
|
|
|
|
{
|
2022-05-03 08:59:22 +02:00
|
|
|
|
return Application.Current.Dispatcher.Invoke(() => new BrowserWindow(control, settings, isMainWindow, text, logger));
|
2019-03-21 16:05:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 18:22:22 +02:00
|
|
|
|
public IExamSelectionDialog CreateExamSelectionDialog(IEnumerable<Exam> exams)
|
2020-07-22 18:11:51 +02:00
|
|
|
|
{
|
2020-07-31 22:17:10 +02:00
|
|
|
|
return Application.Current.Dispatcher.Invoke(() => new ExamSelectionDialog(exams, text));
|
2020-07-22 18:11:51 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-30 15:59:51 +02:00
|
|
|
|
public ISystemControl CreateKeyboardLayoutControl(IKeyboard keyboard, Location location)
|
2019-03-21 16:05:16 +01:00
|
|
|
|
{
|
|
|
|
|
if (location == Location.ActionCenter)
|
|
|
|
|
{
|
2020-03-17 10:37:08 +01:00
|
|
|
|
return new Controls.ActionCenter.KeyboardLayoutControl(keyboard, text);
|
2019-03-21 16:05:16 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-17 10:37:08 +01:00
|
|
|
|
return new Controls.Taskbar.KeyboardLayoutControl(keyboard, text);
|
2019-03-21 16:05:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-11 15:46:15 +02:00
|
|
|
|
public ILockScreen CreateLockScreen(string message, string title, IEnumerable<LockScreenOption> options)
|
|
|
|
|
{
|
|
|
|
|
return Application.Current.Dispatcher.Invoke(() => new LockScreen(message, title, text, options));
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 16:05:16 +01:00
|
|
|
|
public IWindow CreateLogWindow(ILogger logger)
|
|
|
|
|
{
|
2020-01-22 15:16:11 +01:00
|
|
|
|
var window = default(LogWindow);
|
|
|
|
|
var windowReadyEvent = new AutoResetEvent(false);
|
|
|
|
|
var windowThread = new Thread(() =>
|
2019-03-21 16:05:16 +01:00
|
|
|
|
{
|
2020-01-22 15:16:11 +01:00
|
|
|
|
window = new LogWindow(logger, text);
|
|
|
|
|
window.Closed += (o, args) => window.Dispatcher.InvokeShutdown();
|
|
|
|
|
window.Show();
|
2019-03-21 16:05:16 +01:00
|
|
|
|
|
2020-01-22 15:16:11 +01:00
|
|
|
|
windowReadyEvent.Set();
|
2019-03-21 16:05:16 +01:00
|
|
|
|
|
|
|
|
|
System.Windows.Threading.Dispatcher.Run();
|
|
|
|
|
});
|
|
|
|
|
|
2020-01-22 15:16:11 +01:00
|
|
|
|
windowThread.SetApartmentState(ApartmentState.STA);
|
|
|
|
|
windowThread.IsBackground = true;
|
|
|
|
|
windowThread.Start();
|
2019-03-21 16:05:16 +01:00
|
|
|
|
|
2020-01-22 15:16:11 +01:00
|
|
|
|
windowReadyEvent.WaitOne();
|
2019-03-21 16:05:16 +01:00
|
|
|
|
|
2020-01-22 15:16:11 +01:00
|
|
|
|
return window;
|
2019-03-21 16:05:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 18:21:29 +02:00
|
|
|
|
public ISystemControl CreateNetworkControl(INetworkAdapter adapter, Location location)
|
|
|
|
|
{
|
|
|
|
|
if (location == Location.ActionCenter)
|
|
|
|
|
{
|
|
|
|
|
return new Controls.ActionCenter.NetworkControl(adapter, text);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new Controls.Taskbar.NetworkControl(adapter, text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-02 10:30:26 +02:00
|
|
|
|
public INetworkDialog CreateNetworkDialog(string message, string title)
|
|
|
|
|
{
|
|
|
|
|
// TODO
|
|
|
|
|
throw new System.NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-18 23:12:07 +01:00
|
|
|
|
public INotificationControl CreateNotificationControl(INotification notification, Location location)
|
2019-03-21 16:05:16 +01:00
|
|
|
|
{
|
|
|
|
|
if (location == Location.ActionCenter)
|
|
|
|
|
{
|
2021-03-18 23:12:07 +01:00
|
|
|
|
return new Controls.ActionCenter.NotificationButton(notification);
|
2019-03-21 16:05:16 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-03-18 23:12:07 +01:00
|
|
|
|
return new Controls.Taskbar.NotificationButton(notification);
|
2019-03-21 16:05:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IPasswordDialog CreatePasswordDialog(string message, string title)
|
|
|
|
|
{
|
|
|
|
|
return Application.Current.Dispatcher.Invoke(() => new PasswordDialog(message, title, text));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IPasswordDialog CreatePasswordDialog(TextKey message, TextKey title)
|
|
|
|
|
{
|
|
|
|
|
return Application.Current.Dispatcher.Invoke(() => new PasswordDialog(text.Get(message), text.Get(title), text));
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-03 11:46:36 +02:00
|
|
|
|
public ISystemControl CreatePowerSupplyControl(IPowerSupply powerSupply, Location location)
|
2019-03-21 16:05:16 +01:00
|
|
|
|
{
|
|
|
|
|
if (location == Location.ActionCenter)
|
|
|
|
|
{
|
2020-03-17 10:37:08 +01:00
|
|
|
|
return new Controls.ActionCenter.PowerSupplyControl(powerSupply, text);
|
2019-03-21 16:05:16 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-03-17 10:37:08 +01:00
|
|
|
|
return new Controls.Taskbar.PowerSupplyControl(powerSupply, text);
|
2019-03-21 16:05:16 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-29 21:05:43 +01:00
|
|
|
|
public IProctoringFinalizationDialog CreateProctoringFinalizationDialog()
|
|
|
|
|
{
|
|
|
|
|
return Application.Current.Dispatcher.Invoke(() => new ProctoringFinalizationDialog(text));
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-19 22:03:52 +01:00
|
|
|
|
public IProctoringWindow CreateProctoringWindow(IProctoringControl control)
|
|
|
|
|
{
|
2021-04-12 19:59:58 +02:00
|
|
|
|
return Application.Current.Dispatcher.Invoke(() => new ProctoringWindow(control));
|
2021-02-19 22:03:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-17 10:47:02 +02:00
|
|
|
|
public INotificationControl CreateRaiseHandControl(IProctoringController controller, Location location, ProctoringSettings settings)
|
|
|
|
|
{
|
|
|
|
|
if (location == Location.ActionCenter)
|
|
|
|
|
{
|
|
|
|
|
return new Controls.ActionCenter.RaiseHandControl(controller, settings, text);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return new Controls.Taskbar.RaiseHandControl(controller, settings, text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 16:05:16 +01:00
|
|
|
|
public IRuntimeWindow CreateRuntimeWindow(AppConfig appConfig)
|
|
|
|
|
{
|
|
|
|
|
return Application.Current.Dispatcher.Invoke(() => new RuntimeWindow(appConfig, text));
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 18:22:22 +02:00
|
|
|
|
public IServerFailureDialog CreateServerFailureDialog(string info, bool showFallback)
|
|
|
|
|
{
|
2020-07-31 22:17:10 +02:00
|
|
|
|
return Application.Current.Dispatcher.Invoke(() => new ServerFailureDialog(info, showFallback, text));
|
2020-07-24 18:22:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 16:05:16 +01:00
|
|
|
|
public ISplashScreen CreateSplashScreen(AppConfig appConfig = null)
|
|
|
|
|
{
|
2020-01-22 15:16:11 +01:00
|
|
|
|
var window = default(SplashScreen);
|
|
|
|
|
var windowReadyEvent = new AutoResetEvent(false);
|
|
|
|
|
var windowThread = new Thread(() =>
|
2019-03-21 16:05:16 +01:00
|
|
|
|
{
|
2020-01-22 15:16:11 +01:00
|
|
|
|
window = new SplashScreen(text, appConfig);
|
|
|
|
|
window.Closed += (o, args) => window.Dispatcher.InvokeShutdown();
|
|
|
|
|
window.Show();
|
2019-03-21 16:05:16 +01:00
|
|
|
|
|
2020-01-22 15:16:11 +01:00
|
|
|
|
windowReadyEvent.Set();
|
2019-03-21 16:05:16 +01:00
|
|
|
|
|
|
|
|
|
System.Windows.Threading.Dispatcher.Run();
|
|
|
|
|
});
|
|
|
|
|
|
2020-01-22 15:16:11 +01:00
|
|
|
|
windowThread.SetApartmentState(ApartmentState.STA);
|
|
|
|
|
windowThread.IsBackground = true;
|
|
|
|
|
windowThread.Start();
|
2019-03-21 16:05:16 +01:00
|
|
|
|
|
2020-01-22 15:16:11 +01:00
|
|
|
|
windowReadyEvent.WaitOne();
|
2019-03-21 16:05:16 +01:00
|
|
|
|
|
2020-01-22 15:16:11 +01:00
|
|
|
|
return window;
|
2019-03-21 16:05:16 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-17 11:07:40 +01:00
|
|
|
|
public ITaskbar CreateTaskbar(ILogger logger)
|
|
|
|
|
{
|
|
|
|
|
return new Taskbar(logger);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ITaskview CreateTaskview()
|
|
|
|
|
{
|
|
|
|
|
return new Taskview();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-21 16:05:16 +01:00
|
|
|
|
private void InitializeFontAwesome()
|
|
|
|
|
{
|
|
|
|
|
// To be able to use FontAwesome in XAML icon resources, we need to make sure that the FontAwesome.WPF assembly is loaded into
|
|
|
|
|
// the AppDomain before attempting to load an icon resource - thus the creation of an unused image below...
|
|
|
|
|
ImageAwesome.CreateImageSource(FontAwesomeIcon.FontAwesome, Brushes.Black);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|