30 lines
1.0 KiB
C#
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; }
|
|||
|
}
|
|||
|
}
|
|||
|
}
|