| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 | namespace DeviceManagement.ViewModels;public partial class DeviceManagerViewModel : ObservableObject{    public DeviceManagerViewModel(DeviceCollection deviceCollection, IDialogService dialogService, IUICaller caller)    {        this._DeviceCollection = deviceCollection;        this._DialogService = dialogService;        this._UICaller = caller;        deviceCollection.DeviceList.CollectionChanged += DeviceList_CollectionChanged;        this.DeviceList_CollectionChanged(deviceCollection.DeviceList, null);    }    private void DeviceList_CollectionChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs? e)    {        if (sender is not ObservableDictionary<Guid, DeviceInfo_VM> deviceList)            return;        this.Devices.Clear();        foreach (DeviceInfo_VM device in deviceList.Values)        {            this.Devices[device.DeviceModel] ??= [];            this.Devices[device.DeviceModel].Add(device);        }    }    private readonly IDialogService _DialogService;    private readonly DeviceCollection _DeviceCollection;    private readonly IUICaller _UICaller;    [ObservableProperty]    private ObservableDictionary<DeviceModel, ObservableCollection<DeviceInfo_VM>> _Devices = [];    [RelayCommand]    private void CheckDetail(DeviceInfo_VM deviceInfo)    {        DirectoryInfo directory = new(AppDomain.CurrentDomain.BaseDirectory);        if (directory.Parent is not DirectoryInfo mainFolder)        {            MessageBox.Show("Folder not exist");            return;        }                  string path = Path.Combine(mainFolder.FullName, "Analizer");        try        {            object o = deviceInfo.DeviceModel switch            {                DeviceModel.JetKepler => Process.Start(Path.Combine(path, "Kepler", "KeplerAnalizer.exe")),                DeviceModel.Proxima => Process.Start(Path.Combine(path, "Proxima", "ProximaAnalizer.exe")),                _ => MessageBox.Show("Undefined Type")            };        }        catch        {            MessageBox.Show("Folder not exist");        }    }    [RelayCommand]    private void Remote(DeviceInfo_VM deviceInfo)    {        //string path = Path.Combine(System.Environment.CurrentDirectory, "Analizer");        try        {            object o = deviceInfo.DeviceModel switch            {                //DeviceModel.JetKepler => Process.Start(Path.Combine(path, "Kepler", "KeplerAnalizer.exe")),                DeviceModel.Proxima => Process.Start(@"E:\Furnace\Furnace\FurnaceUI\FurnaceUI.exe"),                _ => MessageBox.Show("Undefined Type")            };        }        catch        {        }    }    [RelayCommand]    private async Task Delete(DeviceInfo_VM deviceInfo)    {        if (deviceInfo.Guid is null || deviceInfo.Guid == Guid.Empty)            return;        MessageBoxResult result = MessageBox.Show($"确认删除 {deviceInfo.DeviceModel}-{deviceInfo.DeviceName} ?", "确认删除", MessageBoxButton.YesNo, MessageBoxImage.Question);        if (result != MessageBoxResult.Yes)            return;        await this._UICaller.RemoveDevice(deviceInfo.Guid.Value);        await this.Refresh();        //this._DeviceCollection.DeviceList.Remove(deviceInfo.Guid.Value);        //MessageBox.Show($"{deviceInfo.DeviceModel}-{deviceInfo.DeviceName} 已删除");    }    [RelayCommand]    private void Setting(DeviceInfo_VM deviceInfo)    {        IDialogParameters para = new DialogParameters() { { "Device", deviceInfo } };        this._DialogService.Show("EditDevice", para, null);    }    [RelayCommand]    private async Task Refresh()    {        IEnumerable<DeviceInfo> devices = await this._UICaller.RequestDeviceLists();        if (devices is null || !devices.Any())            return;        this._DeviceCollection.DeviceList.Clear();        foreach (DeviceInfo device in devices)        {            if (device.Guid is null)                continue;            this._DeviceCollection.DeviceList[device.Guid.Value] = device.Adapt<DeviceInfo_VM>();        }    }}
 |