Backend/e-suite.WorkBench/eSuite.WorkBench/Commands/StopContainersCommand.cs
2026-01-20 21:50:10 +00:00

31 lines
1.2 KiB
C#

using eSuite.WorkBench.Services;
using eSuite.WorkBench.WpfHelper;
using System;
using System.Threading.Tasks;
namespace eSuite.WorkBench.Commands
{
public class StopContainersCommand : AsyncCommandBase
{
private readonly MainWindowViewModel _mainWindowViewModel;
private readonly ICommandsService _commandService;
public StopContainersCommand(MainWindowViewModel mainWindowViewModel, ICommandsService commandsService, Action<Exception> onExeception, EventHandler<FeedbackEventArgs> addFeedbackMessage) : base(onExeception)
{
FeedbackMessage += addFeedbackMessage;
_mainWindowViewModel = mainWindowViewModel;
_commandService = commandsService;
IsEnabled = _commandService.IsAnyContainerRunning();
}
protected override async Task ExecuteAsync(object parameter)
{
DoFeedbackMessage("Stopping containers...");
await _commandService.StopContainersAsync();
IsEnabled = await _commandService.IsAnyContainerRunningAsync();
_mainWindowViewModel.StartContainersCommand.IsEnabled = !(IsEnabled);
DoFeedbackMessage("...containers stopped");
}
}
}