SettingBarViewModel.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using CommunityToolkit.Mvvm.ComponentModel;
  2. using CommunityToolkit.Mvvm.Input;
  3. using HardwareData;
  4. using Microsoft.Win32;
  5. using Mini8SlaveSim.Configuration;
  6. using Mini8SlaveSim.Services;
  7. using System.Collections.Concurrent;
  8. namespace Mini8SlaveSim.ViewModels
  9. {
  10. public partial class SettingBarViewModel : ObservableObject
  11. {
  12. private readonly ISharedConfig _sharedConfig;
  13. private readonly ISlaveManagementService _slaveManagementService;
  14. [ObservableProperty]
  15. private string _selectedFolderPath = string.Empty;
  16. public SettingBarViewModel(ISharedConfig sharedConfig, ISlaveManagementService slaveManagementService)
  17. {
  18. _sharedConfig = sharedConfig;
  19. _slaveManagementService = slaveManagementService;
  20. }
  21. [RelayCommand]
  22. private void SelectFolder()
  23. {
  24. var dialog = new OpenFolderDialog()
  25. {
  26. Title = "Select Folder",
  27. InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer)
  28. };
  29. if (dialog.ShowDialog() == true)
  30. {
  31. SelectedFolderPath = dialog.FolderName;
  32. }
  33. }
  34. [RelayCommand]
  35. private void CreateSlave()
  36. {
  37. if (!_sharedConfig.IsLoaded)
  38. {
  39. return;
  40. }
  41. foreach (var mini8 in _sharedConfig.HardwareAddress.Mini8sAddress)
  42. {
  43. _slaveManagementService.AddSlave(mini8.Key);
  44. }
  45. }
  46. partial void OnSelectedFolderPathChanged(string value)
  47. {
  48. _sharedConfig.Load(value);
  49. }
  50. }
  51. }