bfr/BFR/Operations/Operation.cs
adroslice 704b7ea1a9 Added internal Operation Infrastructure + Example
- Overwrite might be a bad example, because it has no fail conditions. The intended behaviour for those is to throw an exception for invalid parameters, with an error text describing to the user what went wrong.
- Fail condition check may be moved to a seperate abstract method, forcing implementers to at least give fail conditions a thought.
- Minor refactor
- TODO: Better folder structure to group operations (Looking for suggestions)
2019-11-16 02:00:17 +01:00

30 lines
1.0 KiB
C#

using System;
using System.Collections.Generic;
using Avalonia;
using BFR.DataModels;
namespace BFR.Operations
{
public abstract class Operation : AvaloniaObject
{
// Needs to be an avalonia property to update the UI with with any potential error.
public AvaloniaProperty<string> errorProperty = AvaloniaProperty.Register<Operation, string>(nameof(Error), defaultValue: "");
public string Error { get => GetValue(errorProperty); set => SetValue(errorProperty, value); }
public bool IsEnabled { get; set; } = true;
public abstract string Name { get; }
public abstract string Description { get; }
public abstract OperationType OperationType { get; }
protected abstract void ApplyToInternal(List<FileModel> files);
// Updates the UI with the appropriate error if the operation fails
public void ApplyTo(List<FileModel> files)
{
try { ApplyToInternal(files); Error = ""; }
catch (Exception e) { Error = e.Message; }
}
}
}