2017-08-07 18:08:55 +02:00
|
|
|
|
/*
|
2024-03-05 18:37:42 +01:00
|
|
|
|
* Copyright (c) 2024 ETH Zürich, IT Services
|
2017-08-07 18:08:55 +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.I18n.Contracts;
|
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
2023-07-21 09:31:59 +02:00
|
|
|
|
using SafeExamBrowser.Monitoring.Contracts;
|
2017-08-07 18:08:55 +02:00
|
|
|
|
|
2018-08-31 10:06:27 +02:00
|
|
|
|
namespace SafeExamBrowser.Client.Operations
|
2017-08-07 18:08:55 +02:00
|
|
|
|
{
|
2019-10-01 16:24:10 +02:00
|
|
|
|
internal class ClipboardOperation : ClientOperation
|
2017-08-07 18:08:55 +02:00
|
|
|
|
{
|
2023-07-21 09:31:59 +02:00
|
|
|
|
private readonly IClipboard clipboard;
|
|
|
|
|
private readonly ILogger logger;
|
2017-08-07 18:08:55 +02:00
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
public override event ActionRequiredEventHandler ActionRequired { add { } remove { } }
|
|
|
|
|
public override event StatusChangedEventHandler StatusChanged;
|
2017-08-07 18:08:55 +02:00
|
|
|
|
|
2023-07-21 09:31:59 +02:00
|
|
|
|
public ClipboardOperation(ClientContext context, IClipboard clipboard, ILogger logger) : base(context)
|
2017-08-07 18:08:55 +02:00
|
|
|
|
{
|
2023-07-21 09:31:59 +02:00
|
|
|
|
this.clipboard = clipboard;
|
2017-08-07 18:08:55 +02:00
|
|
|
|
this.logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
public override OperationResult Perform()
|
2017-08-07 18:08:55 +02:00
|
|
|
|
{
|
2023-07-21 09:31:59 +02:00
|
|
|
|
InitializeClipboard();
|
2018-02-28 15:49:06 +01:00
|
|
|
|
|
|
|
|
|
return OperationResult.Success;
|
2017-08-07 18:08:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-01 16:24:10 +02:00
|
|
|
|
public override OperationResult Revert()
|
2017-08-07 18:08:55 +02:00
|
|
|
|
{
|
2023-07-21 09:31:59 +02:00
|
|
|
|
FinalizeClipboard();
|
2018-10-10 09:19:03 +02:00
|
|
|
|
|
|
|
|
|
return OperationResult.Success;
|
2017-08-07 18:08:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-21 09:31:59 +02:00
|
|
|
|
private void InitializeClipboard()
|
2017-08-07 18:08:55 +02:00
|
|
|
|
{
|
2023-07-21 09:31:59 +02:00
|
|
|
|
logger.Info("Initializing clipboard...");
|
|
|
|
|
StatusChanged?.Invoke(TextKey.OperationStatus_InitializeClipboard);
|
|
|
|
|
clipboard.Initialize(Context.Settings.Security.ClipboardPolicy);
|
|
|
|
|
}
|
2017-08-07 18:08:55 +02:00
|
|
|
|
|
2023-07-21 09:31:59 +02:00
|
|
|
|
private void FinalizeClipboard()
|
|
|
|
|
{
|
|
|
|
|
logger.Info("Finalizing clipboard...");
|
|
|
|
|
StatusChanged?.Invoke(TextKey.OperationStatus_FinalizeClipboard);
|
|
|
|
|
clipboard.Terminate();
|
2017-08-07 18:08:55 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|