Skip to content

Commit

Permalink
add telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
KerlyJiang1 committed Dec 7, 2019
1 parent cbec36c commit 1e37c19
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,17 +324,10 @@ public override AsyncUnaryCall<Metric> GetMetricAsync(GetMetricRequest request,

public override AsyncUnaryCall<Switch> GetSwitchAsync(GetSwitchRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default)
{
var switchInfo = Switches[request.DeviceId];

return TestCalls.AsyncUnaryCall(
Task.FromResult(new Switch
{
DevicePowerOn = RandomUtils.Equals(true, false),
ExhausterPowerOn = RandomUtils.Equals(true, false),
HeaterAutoOn = RandomUtils.Equals(true, false),
HeaterCompressorOn = RandomUtils.Equals(true, false),
HeaterFanOn = RandomUtils.Equals(true, false),
HeaterFourWayReversingOn = RandomUtils.Equals(true, false),
HeaterPowerOn = RandomUtils.Equals(true, false),
}),
Task.FromResult(switchInfo),
Task.FromResult(new Metadata()),
() => Status.DefaultSuccess,
() => new Metadata(),
Expand All @@ -353,6 +346,13 @@ public override AsyncUnaryCall<Switch> UpdateSwitchAsync(UpdateSwitchRequest req
request.UpdateMask.Merge(request.Switch, switchInfo);
}

if (Switches.ContainsKey(request.DeviceId))
{
Switches.Remove(request.DeviceId);
}

Switches.Add(request.DeviceId, switchInfo);

return TestCalls.AsyncUnaryCall(
Task.FromResult(switchInfo),
Task.FromResult(new Metadata()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task LoadMetricAsync()
DeviceId = this.ViewModelContext.SelectedDevice.Id,
},
deadline: DateTime.Now.AddMilliseconds(500));
this.metric = response;
this.Metric = response;
}

public async Task LoadSwitchAsync()
Expand All @@ -67,34 +67,36 @@ public async Task LoadSwitchAsync()
DeviceId = this.ViewModelContext.SelectedDevice.Id,
},
deadline: DateTime.Now.AddMilliseconds(500));
this.switchInfo = response;
this.Switch = response;
}

public async Task UpdateSwitchAsync(Switch switchInfo, FieldMask mask)
{
//this.Switch = switchInfo.Clone();

Switch response = await this.client.UpdateSwitchAsync(
new UpdateSwitchRequest()
{
DeviceId = this.ViewModelContext.SelectedDevice.Id,
Switch = switchInfo,
Switch = this.Switch,
UpdateMask = mask,
},
deadline: DateTime.Now.AddMilliseconds(500));
this.switchInfo = response;
this.Switch = response;
}

private async void ExecuteSwitchOnClickCommand(object type)
{
FieldMask updateMask = FieldMask.FromString((string)type);
Switch obj = this.UpdateSwitchInfo((string)type, true);
await this.UpdateSwitchAsync(obj, updateMask).ConfigureAwait(true);
await UpdateSwitchAsync(obj, updateMask).ConfigureAwait(true);
}

private async void ExecuteSwitchOffClickCommand(object type)
{
FieldMask updateMask = FieldMask.FromString((string)type);
Switch obj = this.UpdateSwitchInfo((string)type, false);
await this.UpdateSwitchAsync(obj, updateMask).ConfigureAwait(true);
await this.UpdateSwitchAsync(obj, updateMask).ConfigureAwait(false);
}

private Switch UpdateSwitchInfo(string type, bool status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
Grid.Row="0"
Grid.Column="1"
VerticalAlignment="Center"
Text="0" />
Text="{Binding Metric.OutputWaterCelsiusDegree}" />
<Label
Grid.Row="1"
Grid.Column="0"
Expand All @@ -46,7 +46,7 @@
Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Center"
Text="0" />
Text="{Binding Metric.OutputWaterPressureMeter}" />
<Label
Grid.Row="2"
Grid.Column="0"
Expand All @@ -56,7 +56,7 @@
Grid.Row="2"
Grid.Column="1"
VerticalAlignment="Center"
Text="0" />
Text="{Binding Metric.WaterPumpFlowRateCubicMeterPerHour}" />
<Label
Grid.Row="3"
Grid.Column="0"
Expand All @@ -66,7 +66,7 @@
Grid.Row="3"
Grid.Column="1"
VerticalAlignment="Center"
Text="0" />
Text="{Binding Metric.EnvironmentCelsiusDegree}" />
</Grid>
<Grid Canvas.Left="10" Canvas.Bottom="10">
<Grid.RowDefinitions>
Expand All @@ -88,7 +88,7 @@
Grid.Row="0"
Grid.Column="1"
VerticalAlignment="Center"
Text="0" />
Text="{Binding Metric.InputWaterCelsiusDegree}" />
<Label
Grid.Row="1"
Grid.Column="0"
Expand All @@ -98,7 +98,7 @@
Grid.Row="1"
Grid.Column="1"
VerticalAlignment="Center"
Text="0" />
Text="{Binding Metric.InputWaterPressureMeter}" />
<Label
Grid.Row="2"
Grid.Column="0"
Expand All @@ -108,7 +108,7 @@
Grid.Row="2"
Grid.Column="1"
VerticalAlignment="Center"
Text="0" />
Text="{Binding Metric.HeaterPowerKilowatt}" />
<Label
Grid.Row="3"
Grid.Column="0"
Expand All @@ -118,7 +118,7 @@
Grid.Row="3"
Grid.Column="1"
VerticalAlignment="Center"
Text="0" />
Text="{Binding Metric.HeaterOutputWaterCelsiusDegree}" />
</Grid>
<Line
StrokeEndLineCap="Triangle"
Expand Down Expand Up @@ -262,47 +262,13 @@

</Image.Style>
</Image>
<StackPanel
Canvas.Left="135"
Canvas.Top="30"
Orientation="Horizontal">
<Button
Margin="5"
Padding="5"
Content=""
Command="{Binding SwitchOnClickCommand}"
CommandParameter="heater_fan_on"/>
<Button
Margin="5"
Padding="5"
Content=""
Command="{Binding SwitchOffClickCommand}"
CommandParameter="heater_fan_on"/>
</StackPanel>
<StackPanel
Canvas.Left="142"
Canvas.Top="252"
Orientation="Horizontal">
<Button
Margin="5"
Padding="5"
Content=""
Command="{Binding SwitchOnClickCommand}"
CommandParameter="heater_power_on"/>
<Button
Margin="5"
Padding="5"
Content=""
Command="{Binding SwitchOffClickCommand}"
CommandParameter="heater_power_on"/>
</StackPanel>
<StackPanel
Canvas.Left="335"
Canvas.Top="105"
Orientation="Horizontal">
<Label Content="电源状态:"
VerticalAlignment="Center"/>
<TextBlock Text=""
<TextBlock Text="{Binding Switch.DevicePowerOn}"
VerticalAlignment="Center"
Padding="0,0,10,0"/>
<Button
Expand Down

0 comments on commit 1e37c19

Please sign in to comment.