1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using CommunityToolkit.Mvvm.Input;
- using Shaker.Models;
- using ShakerApp.Models;
- using ShakerApp.Tools;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Input;
- namespace ShakerApp.ViewModels
- {
- public class DeviceInfoViewModel : ViewModelBase<DeviceInfoModel>
- {
- public DeviceInfoViewModel()
- {
- }
- public DeviceInfoViewModel(DeviceInfoModel model):base(model)
- {
- }
- public void SaveTdmsConfig(Dictionary<string, string> config)
- {
- if (config == null) config = new Dictionary<string, string>();
- typeof(DeviceInfoModel).GetFields(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
- .Select(x => (x, x.GetValue(Model)))
- .ToList()
- .ForEach(x =>
- {
- if (x.Item2 == null)
- {
- return;
- }
- if (x.x.FieldType.IsAssignableTo(typeof(IList)) || x.x.FieldType.IsArray)
- {
- config[$"{nameof(DeviceInfoModel)}_{x.x.Name}"] = string.Join("", x.Item2.GetBytes().Select(x => $"{x:X2}"));
- }
- else
- {
- config[$"{nameof(DeviceInfoModel)}_{x.x.Name}"] = x.Item2?.ToString() ?? string.Empty;
- }
- });
- }
- [PropertyAssociation(nameof(DeviceInfoModel.Name))]
- public string Name { get => Model.Name; set => SetProperty(ref Model.Name, value); }
- [PropertyAssociation(nameof(DeviceInfoModel.SN))]
- public string SN { get => Model.SN; set => SetProperty(ref Model.SN, value); }
- [PropertyAssociation(nameof(DeviceInfoModel.IP))]
- public string IP { get => Model.IP; set => SetProperty(ref Model.IP, value); }
- [PropertyAssociation(nameof(DeviceInfoModel.Port))]
- public int Port { get => Model.Port; set => SetProperty(ref Model.Port, value); }
- }
- }
|