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 errorProperty = AvaloniaProperty.Register(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 files); // Updates the UI with the appropriate error if the operation fails public void ApplyTo(List files) { try { ApplyToInternal(files); Error = ""; } catch (Exception e) { Error = e.Message; } } } }