2018-02-21 14:01:21 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018 ETH Zürich, Educational Development and Technology (LET)
|
|
|
|
|
*
|
|
|
|
|
* 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;
|
2018-03-06 11:49:51 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.Behaviour.OperationModel;
|
2018-02-21 14:01:21 +01:00
|
|
|
|
using SafeExamBrowser.Contracts.UserInterface;
|
|
|
|
|
|
2018-03-13 10:57:47 +01:00
|
|
|
|
namespace SafeExamBrowser.Core.Behaviour.OperationModel
|
2018-02-21 14:01:21 +01:00
|
|
|
|
{
|
2018-03-06 14:35:10 +01:00
|
|
|
|
/// <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>
|
2018-02-21 14:01:21 +01:00
|
|
|
|
public class DelegateOperation : IOperation
|
|
|
|
|
{
|
|
|
|
|
private Action perform;
|
|
|
|
|
private Action repeat;
|
|
|
|
|
private Action revert;
|
|
|
|
|
|
|
|
|
|
public IProgressIndicator ProgressIndicator { private get; set; }
|
|
|
|
|
|
|
|
|
|
public DelegateOperation(Action perform, Action repeat = null, Action revert = null)
|
|
|
|
|
{
|
|
|
|
|
this.perform = perform;
|
|
|
|
|
this.repeat = repeat;
|
|
|
|
|
this.revert = revert;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-28 15:49:06 +01:00
|
|
|
|
public OperationResult Perform()
|
2018-02-21 14:01:21 +01:00
|
|
|
|
{
|
|
|
|
|
perform?.Invoke();
|
2018-02-28 15:49:06 +01:00
|
|
|
|
|
|
|
|
|
return OperationResult.Success;
|
2018-02-21 14:01:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-28 15:49:06 +01:00
|
|
|
|
public OperationResult Repeat()
|
2018-02-21 14:01:21 +01:00
|
|
|
|
{
|
|
|
|
|
repeat?.Invoke();
|
2018-02-28 15:49:06 +01:00
|
|
|
|
|
|
|
|
|
return OperationResult.Success;
|
2018-02-21 14:01:21 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Revert()
|
|
|
|
|
{
|
|
|
|
|
revert?.Invoke();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|