using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using HardwareData; using Microsoft.Win32; using Mini8SlaveSim.Configuration; using Mini8SlaveSim.Services; using System.Collections.Concurrent; namespace Mini8SlaveSim.ViewModels { public partial class SettingBarViewModel : ObservableObject { private readonly ISharedConfig _sharedConfig; private readonly ISlaveManagementService _slaveManagementService; [ObservableProperty] private string _selectedFolderPath = string.Empty; public SettingBarViewModel(ISharedConfig sharedConfig, ISlaveManagementService slaveManagementService) { _sharedConfig = sharedConfig; _slaveManagementService = slaveManagementService; } [RelayCommand] private void SelectFolder() { var dialog = new OpenFolderDialog() { Title = "Select Folder", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) }; if (dialog.ShowDialog() == true) { SelectedFolderPath = dialog.FolderName; } } [RelayCommand] private void CreateSlave() { if (!_sharedConfig.IsLoaded) { return; } foreach (var mini8 in _sharedConfig.HardwareAddress.Mini8sAddress) { _slaveManagementService.AddSlave(mini8.Key); } } partial void OnSelectedFolderPathChanged(string value) { _sharedConfig.Load(value); } } }