终端一体化运控平台
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

77 linhas
2.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.Toolkit.Mvvm.ComponentModel;
  7. using System.Collections.Concurrent;
  8. using System.Collections.ObjectModel;
  9. using Microsoft.Toolkit.Mvvm.Input;
  10. using Microsoft.Toolkit.Mvvm.Messaging;
  11. using System.Diagnostics;
  12. using BPASmart.Model;
  13. using System.Reflection;
  14. namespace BPASmart.VariableManager.ViewModels
  15. {
  16. public class NewDeviceViewModel : ObservableObject
  17. {
  18. public NewDeviceViewModel()
  19. {
  20. Init();
  21. CancelCommand = new RelayCommand(() =>
  22. {
  23. if (DelegationNotifi.GetInstance.Cancel != null) DelegationNotifi.GetInstance.Cancel(devcieManagerResult);
  24. });
  25. ConfirmCommand = new RelayCommand(() =>
  26. {
  27. if (DelegationNotifi.GetInstance.AddDeviceVerify != null)
  28. {
  29. if (DelegationNotifi.GetInstance.AddDeviceVerify(devcieManagerResult))
  30. {
  31. if (DelegationNotifi.GetInstance.Confirm != null) DelegationNotifi.GetInstance.Confirm(devcieManagerResult);
  32. }
  33. else
  34. {
  35. LogInfo = $"警告:设备【{devcieManagerResult.DeviceName}】已存在,请重试";
  36. }
  37. }
  38. else
  39. {
  40. LogInfo = $"警告:设备添加失败!";
  41. }
  42. });
  43. }
  44. public ObservableCollection<string> DeviceType { get; set; } = new ObservableCollection<string>();
  45. public RelayCommand CancelCommand { get; set; }
  46. public RelayCommand ConfirmCommand { get; set; }
  47. private void Init()
  48. {
  49. DeviceType.Clear();
  50. var assembly = Assembly.GetAssembly(typeof(ICommunicationDevice))?.GetTypes()?.ToList();
  51. assembly?.ForEach(item =>
  52. {
  53. if (item.GetInterfaces().Contains(typeof(ICommunicationDevice)))
  54. {
  55. DeviceType.Add(item.Name);
  56. }
  57. });
  58. }
  59. public DeviceManagermentResult devcieManagerResult { get { return _mdevcieManagerResult; } set { _mdevcieManagerResult = value; OnPropertyChanged(); } }
  60. private DeviceManagermentResult _mdevcieManagerResult = new DeviceManagermentResult();
  61. public string LogInfo { get { return _mLogInfo; } set { _mLogInfo = value; OnPropertyChanged(); } }
  62. private string _mLogInfo;
  63. }
  64. }