2018-10-12 11:16:59 +02:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
2018-10-12 11:16:59 +02: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.Core.Contracts.OperationModel;
|
|
|
|
|
using SafeExamBrowser.Core.Contracts.OperationModel.Events;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2018-10-12 11:16:59 +02:00
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.Runtime.Operations
|
|
|
|
|
{
|
|
|
|
|
internal class SessionActivationOperation : SessionOperation
|
|
|
|
|
{
|
|
|
|
|
private ILogger logger;
|
|
|
|
|
|
|
|
|
|
public override event ActionRequiredEventHandler ActionRequired { add { } remove { } }
|
|
|
|
|
public override event StatusChangedEventHandler StatusChanged { add { } remove { } }
|
|
|
|
|
|
|
|
|
|
public SessionActivationOperation(ILogger logger, SessionContext sessionContext) : base(sessionContext)
|
|
|
|
|
{
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override OperationResult Perform()
|
|
|
|
|
{
|
2019-01-30 14:43:41 +01:00
|
|
|
|
SwitchLogSeverity();
|
2018-10-12 11:16:59 +02:00
|
|
|
|
ActivateNewSession();
|
|
|
|
|
|
|
|
|
|
return OperationResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override OperationResult Repeat()
|
|
|
|
|
{
|
2019-01-30 14:43:41 +01:00
|
|
|
|
SwitchLogSeverity();
|
2018-10-12 11:16:59 +02:00
|
|
|
|
ActivateNewSession();
|
|
|
|
|
|
|
|
|
|
return OperationResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override OperationResult Revert()
|
|
|
|
|
{
|
|
|
|
|
return OperationResult.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-30 14:43:41 +01:00
|
|
|
|
private void SwitchLogSeverity()
|
|
|
|
|
{
|
|
|
|
|
if (logger.LogLevel != Context.Next.Settings.LogLevel)
|
|
|
|
|
{
|
|
|
|
|
var current = logger.LogLevel.ToString().ToUpper();
|
|
|
|
|
var next = Context.Next.Settings.LogLevel.ToString().ToUpper();
|
|
|
|
|
|
|
|
|
|
logger.Info($"Switching from log severity '{current}' to '{next}' for new session.");
|
|
|
|
|
logger.LogLevel = Context.Next.Settings.LogLevel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-12 11:16:59 +02:00
|
|
|
|
private void ActivateNewSession()
|
|
|
|
|
{
|
|
|
|
|
var isFirstSession = Context.Current == null;
|
|
|
|
|
|
|
|
|
|
if (isFirstSession)
|
|
|
|
|
{
|
2019-06-11 09:53:33 +02:00
|
|
|
|
logger.Info($"Successfully activated first session '{Context.Next.SessionId}'.");
|
2018-10-12 11:16:59 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-06-11 09:53:33 +02:00
|
|
|
|
logger.Info($"Successfully terminated old session '{Context.Current.SessionId}' and activated new session '{Context.Next.SessionId}'.");
|
2018-10-12 11:16:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Context.Current = Context.Next;
|
|
|
|
|
Context.Next = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|