laatzen/Common/Ui/Common.UI.VFM/ViewModels/ProcessStepViewModel.cs
2024-07-01 08:42:23 +02:00

50 lines
1.3 KiB
C#

namespace Common.UI.VFM.ViewModels
{
using Common.UI.VFM.Models;
using System;
using System.Collections.Generic;
using System.Windows;
public class ProcessStepViewModel : AppViewModel
{
private readonly Func<ProcessResult> process;
public ProcessStepViewModel(String name, Func<ProcessResult> process)
{
this.Name = name;
this.process = process;
this.State = ProcessState.Undefined;
}
public String Name { get; }
private ProcessState state;
public ProcessState State
{
get => this.state;
set => this.Set(() => this.state = value);
}
private String message;
public String Message
{
get => this.message;
set => this.Set(() => this.message = value);
}
internal ProcessResult StartProcessing()
{
this.State = ProcessState.Started;
var result = this.process.Invoke();
this.State = result.State;
this.Message = result.Message;
return result;
}
public static implicit operator ProcessStepViewModel(KeyValuePair<String, Func<ProcessResult>> kvp)
=> new ProcessStepViewModel(kvp.Key, kvp.Value);
}
}