Restore SEBPatch

This commit is contained in:
2025-06-01 11:44:20 +02:00
commit 8c656e3137
1297 changed files with 142172 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2024 ETH Zürich, IT Services
*
* 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/.
*/
using SafeExamBrowser.Communication.Contracts;
using SafeExamBrowser.Core.Contracts.OperationModel;
using SafeExamBrowser.Core.Contracts.OperationModel.Events;
using SafeExamBrowser.I18n.Contracts;
using SafeExamBrowser.Logging.Contracts;
namespace SafeExamBrowser.Core.Operations
{
/// <summary>
/// An operation to handle the lifetime of an <see cref="ICommunicationHost"/>. The host is started during <see cref="Perform"/>,
/// stopped and restarted during <see cref="Repeat"/> (if not running) and stopped during <see cref="Revert"/>.
/// </summary>
public class CommunicationHostOperation : IRepeatableOperation
{
private ICommunicationHost host;
private ILogger logger;
public event ActionRequiredEventHandler ActionRequired { add { } remove { } }
public event StatusChangedEventHandler StatusChanged;
public CommunicationHostOperation(ICommunicationHost host, ILogger logger)
{
this.host = host;
this.logger = logger;
}
public OperationResult Perform()
{
logger.Info("Starting communication host...");
StatusChanged?.Invoke(TextKey.OperationStatus_StartCommunicationHost);
host.Start();
return OperationResult.Success;
}
public OperationResult Repeat()
{
if (!host.IsRunning)
{
logger.Info("Restarting communication host...");
StatusChanged?.Invoke(TextKey.OperationStatus_RestartCommunicationHost);
host.Stop();
host.Start();
}
return OperationResult.Success;
}
public OperationResult Revert()
{
logger.Info("Stopping communication host...");
StatusChanged?.Invoke(TextKey.OperationStatus_StopCommunicationHost);
host.Stop();
return OperationResult.Success;
}
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2024 ETH Zürich, IT Services
*
* 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/.
*/
using System;
using SafeExamBrowser.Core.Contracts.OperationModel;
using SafeExamBrowser.Core.Contracts.OperationModel.Events;
namespace SafeExamBrowser.Core.Operations
{
/// <summary>
/// A generic operation to allow for the (inline) definition of an operation via delegates. Useful if implementing a complete
/// <see cref="IOperation"/> would be an unnecessary overhead.
/// </summary>
public class DelegateOperation : IRepeatableOperation
{
private Action perform;
private Action repeat;
private Action revert;
public event ActionRequiredEventHandler ActionRequired { add { } remove { } }
public event StatusChangedEventHandler StatusChanged { add { } remove { } }
public DelegateOperation(Action perform, Action repeat = null, Action revert = null)
{
this.perform = perform;
this.repeat = repeat;
this.revert = revert;
}
public OperationResult Perform()
{
perform?.Invoke();
return OperationResult.Success;
}
public OperationResult Repeat()
{
repeat?.Invoke();
return OperationResult.Success;
}
public OperationResult Revert()
{
revert?.Invoke();
return OperationResult.Success;
}
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2024 ETH Zürich, IT Services
*
* 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/.
*/
using SafeExamBrowser.Core.Contracts.OperationModel;
using SafeExamBrowser.Core.Contracts.OperationModel.Events;
using SafeExamBrowser.I18n.Contracts;
using SafeExamBrowser.Logging.Contracts;
namespace SafeExamBrowser.Core.Operations
{
/// <summary>
/// An operation to handle the initialization of an <see cref="IText"/> module with text data.
/// </summary>
public class I18nOperation : IOperation
{
private ILogger logger;
private IText text;
public event ActionRequiredEventHandler ActionRequired { add { } remove { } }
public event StatusChangedEventHandler StatusChanged { add { } remove { } }
public I18nOperation(ILogger logger, IText text)
{
this.logger = logger;
this.text = text;
}
public OperationResult Perform()
{
logger.Info($"Loading text data...");
text.Initialize();
return OperationResult.Success;
}
public OperationResult Revert()
{
return OperationResult.Success;
}
}
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2024 ETH Zürich, IT Services
*
* 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/.
*/
using System;
using SafeExamBrowser.Core.Contracts.OperationModel;
using SafeExamBrowser.Core.Contracts.OperationModel.Events;
namespace SafeExamBrowser.Core.Operations
{
/// <summary>
/// A wrapper operation to allow for a lazy (just-in-time) instantiation of an operation, initialized on <see cref="Perform"/>.
/// Is useful when e.g. dependencies for a certain operation are not available during execution of the composition root, but rather
/// only after a preceding operation within an <see cref="IOperationSequence"/> has finished.
/// </summary>
public class LazyInitializationOperation : IOperation
{
private Func<IOperation> initialize;
private IOperation operation;
private event ActionRequiredEventHandler ActionRequiredImpl;
private event StatusChangedEventHandler StatusChangedImpl;
public event ActionRequiredEventHandler ActionRequired
{
add
{
ActionRequiredImpl += value;
if (operation != null)
{
operation.ActionRequired += value;
}
}
remove
{
ActionRequiredImpl -= value;
if (operation != null)
{
operation.ActionRequired -= value;
}
}
}
public event StatusChangedEventHandler StatusChanged
{
add
{
StatusChangedImpl += value;
if (operation != null)
{
operation.StatusChanged += value;
}
}
remove
{
StatusChangedImpl -= value;
if (operation != null)
{
operation.StatusChanged -= value;
}
}
}
public LazyInitializationOperation(Func<IOperation> initialize)
{
this.initialize = initialize;
}
public OperationResult Perform()
{
operation = initialize.Invoke();
operation.ActionRequired += ActionRequiredImpl;
operation.StatusChanged += StatusChangedImpl;
return operation.Perform();
}
public OperationResult Revert()
{
return operation.Revert();
}
}
}