From e83117730997d9b8d0fcbcb10dd3c5a43a41dec6 Mon Sep 17 00:00:00 2001 From: JSY Date: Sat, 7 Dec 2019 11:56:58 +0800 Subject: [PATCH] fix --- .../ViewModels/DeviceControlViewModel.cs | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/GeothermalResearchInstitute/GeothermalResearchInstitute.Wpf/ViewModels/DeviceControlViewModel.cs b/GeothermalResearchInstitute/GeothermalResearchInstitute.Wpf/ViewModels/DeviceControlViewModel.cs index d8ae4feb..57106869 100644 --- a/GeothermalResearchInstitute/GeothermalResearchInstitute.Wpf/ViewModels/DeviceControlViewModel.cs +++ b/GeothermalResearchInstitute/GeothermalResearchInstitute.Wpf/ViewModels/DeviceControlViewModel.cs @@ -18,10 +18,17 @@ public class DeviceControlViewModel : BindableBase private Switch switchInfo; private Metric metric; private DeviceService.DeviceServiceClient client; + + public DeviceControlViewModel(DeviceService.DeviceServiceClient client) + { + this.client = client ?? throw new ArgumentNullException(nameof(client)); + this.SwitchOnClickCommand = new DelegateCommand(this.ExecuteSwitchOnClickCommand); + this.SwitchOffClickCommand = new DelegateCommand(this.ExecuteSwitchOffClickCommand); + } - public DelegateCommand SwitchOnClickCommand { get; } - - public DelegateCommand SwitchOffClickCommand { get; } + public DelegateCommand SwitchOnClickCommand { get; } + + public DelegateCommand SwitchOffClickCommand { get; } public ViewModelContext ViewModelContext { @@ -76,17 +83,17 @@ public async Task UpdateSwitchAsync(Switch switchInfo, FieldMask mask) this.switchInfo = response; } - private async void ExecuteSwitchOnClickCommand(string type) + private async void ExecuteSwitchOnClickCommand(object type) { - FieldMask updateMask = FieldMask.FromString(type); - Switch obj = this.UpdateSwitchInfo(type, true); + FieldMask updateMask = FieldMask.FromString((string)type); + Switch obj = this.UpdateSwitchInfo((string)type, true); await this.UpdateSwitchAsync(obj, updateMask).ConfigureAwait(true); } - private async void ExecuteSwitchOffClickCommand(string type) + private async void ExecuteSwitchOffClickCommand(object type) { - FieldMask updateMask = FieldMask.FromString(type); - Switch obj = this.UpdateSwitchInfo(type, false); + FieldMask updateMask = FieldMask.FromString((string)type); + Switch obj = this.UpdateSwitchInfo((string)type, false); await this.UpdateSwitchAsync(obj, updateMask).ConfigureAwait(true); }