2018-03-21 10:23:15 +01:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
2018-03-21 10:23:15 +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-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Communication.Contracts.Hosts;
|
|
|
|
|
using SafeExamBrowser.Configuration.Contracts;
|
|
|
|
|
using SafeExamBrowser.Core.Contracts.OperationModel;
|
|
|
|
|
using SafeExamBrowser.Core.Contracts.OperationModel.Events;
|
|
|
|
|
using SafeExamBrowser.I18n.Contracts;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2020-08-27 20:10:15 +02:00
|
|
|
|
using SafeExamBrowser.SystemComponents.Contracts;
|
2018-03-21 10:23:15 +01:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Runtime.Operations
|
2018-03-21 10:23:15 +01:00
|
|
|
|
{
|
2018-10-12 11:16:59 +02:00
|
|
|
|
internal class SessionInitializationOperation : SessionOperation
|
2018-03-21 10:23:15 +01:00
|
|
|
|
{
|
|
|
|
|
private IConfigurationRepository configuration;
|
2020-08-27 20:10:15 +02:00
|
|
|
|
private IFileSystem fileSystem;
|
2018-03-21 10:23:15 +01:00
|
|
|
|
private ILogger logger;
|
|
|
|
|
private IRuntimeHost runtimeHost;
|
|
|
|
|
|
2018-10-12 11:16:59 +02:00
|
|
|
|
public override event ActionRequiredEventHandler ActionRequired { add { } remove { } }
|
|
|
|
|
public override event StatusChangedEventHandler StatusChanged;
|
2018-03-21 10:23:15 +01:00
|
|
|
|
|
2018-10-12 11:16:59 +02:00
|
|
|
|
public SessionInitializationOperation(
|
|
|
|
|
IConfigurationRepository configuration,
|
2020-08-27 20:10:15 +02:00
|
|
|
|
IFileSystem fileSystem,
|
2018-10-12 11:16:59 +02:00
|
|
|
|
ILogger logger,
|
|
|
|
|
IRuntimeHost runtimeHost,
|
|
|
|
|
SessionContext sessionContext) : base(sessionContext)
|
2018-03-21 10:23:15 +01:00
|
|
|
|
{
|
|
|
|
|
this.configuration = configuration;
|
2020-08-27 20:10:15 +02:00
|
|
|
|
this.fileSystem = fileSystem;
|
2018-03-21 10:23:15 +01:00
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.runtimeHost = runtimeHost;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 11:16:59 +02:00
|
|
|
|
public override OperationResult Perform()
|
2018-03-21 10:23:15 +01:00
|
|
|
|
{
|
|
|
|
|
InitializeSessionConfiguration();
|
|
|
|
|
|
|
|
|
|
return OperationResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 11:16:59 +02:00
|
|
|
|
public override OperationResult Repeat()
|
2018-03-21 10:23:15 +01:00
|
|
|
|
{
|
2018-10-12 11:16:59 +02:00
|
|
|
|
InitializeSessionConfiguration();
|
|
|
|
|
|
|
|
|
|
return OperationResult.Success;
|
2018-03-21 10:23:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 11:16:59 +02:00
|
|
|
|
public override OperationResult Revert()
|
2018-03-21 10:23:15 +01:00
|
|
|
|
{
|
2018-11-28 15:43:30 +01:00
|
|
|
|
FinalizeSessionConfiguration();
|
|
|
|
|
|
2018-10-10 09:19:03 +02:00
|
|
|
|
return OperationResult.Success;
|
2018-03-21 10:23:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void InitializeSessionConfiguration()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Initializing new session configuration...");
|
2018-10-03 15:42:50 +02:00
|
|
|
|
StatusChanged?.Invoke(TextKey.OperationStatus_InitializeSession);
|
2018-03-21 10:23:15 +01:00
|
|
|
|
|
2018-10-12 11:16:59 +02:00
|
|
|
|
Context.Next = configuration.InitializeSessionConfiguration();
|
2018-03-21 10:23:15 +01:00
|
|
|
|
|
2018-10-12 11:16:59 +02:00
|
|
|
|
logger.Info($" -> Client-ID: {Context.Next.AppConfig.ClientId}");
|
|
|
|
|
logger.Info($" -> Runtime-ID: {Context.Next.AppConfig.RuntimeId}");
|
2019-06-11 09:53:33 +02:00
|
|
|
|
logger.Info($" -> Session-ID: {Context.Next.SessionId}");
|
2020-08-27 20:10:15 +02:00
|
|
|
|
|
|
|
|
|
fileSystem.CreateDirectory(Context.Next.AppConfig.TemporaryDirectory);
|
2018-03-21 10:23:15 +01:00
|
|
|
|
}
|
2018-11-28 15:43:30 +01:00
|
|
|
|
|
|
|
|
|
private void FinalizeSessionConfiguration()
|
|
|
|
|
{
|
|
|
|
|
Context.Current = null;
|
|
|
|
|
Context.Next = null;
|
|
|
|
|
}
|
2018-03-21 10:23:15 +01:00
|
|
|
|
}
|
|
|
|
|
}
|