public async override Task<CommandProcessingResult> HandleCommandAsync(DeserializableCommand deserializableCommand) { if (deserializableCommand.CommandName == START_TELEMETRY) { var command = deserializableCommand.Command; try { var device = Device as WeatherShieldDevice; device.StartTelemetryData(); return CommandProcessingResult.Success; } catch (Exception) { return CommandProcessingResult.RetryLater; } } else if (NextCommandProcessor != null) { return await NextCommandProcessor.HandleCommandAsync(deserializableCommand); } return CommandProcessingResult.CannotComplete; }
public async override Task<CommandProcessingResult> HandleCommandAsync(DeserializableCommand deserializableCommand) { if (deserializableCommand.CommandName == CHANGE_DEVICE_STATE) { var command = deserializableCommand.Command; try { var device = Device as WeatherShieldDevice; if (device != null) { dynamic parameters = WireCommandSchemaHelper.GetParameters(command); if (parameters != null) { dynamic deviceState = ReflectionHelper.GetNamedPropertyValue( parameters, "DeviceState", usesCaseSensitivePropertyNameMatch: true, exceptionThrownIfNoMatch: true); if (deviceState != null) { device.ChangeDeviceState(deviceState.ToString()); return CommandProcessingResult.Success; } else { // DeviceState is a null reference. return CommandProcessingResult.CannotComplete; } } else { // parameters is a null reference. return CommandProcessingResult.CannotComplete; } } else { // Unsupported Device type. return CommandProcessingResult.CannotComplete; } } catch (Exception) { return CommandProcessingResult.RetryLater; } } else if (NextCommandProcessor != null) { return await NextCommandProcessor.HandleCommandAsync(deserializableCommand); } return CommandProcessingResult.CannotComplete; }
public async override Task<CommandProcessingResult> HandleCommandAsync(DeserializableCommand deserializableCommand) { if (deserializableCommand.CommandName == "PingDevice") { var command = deserializableCommand.Command; try { return CommandProcessingResult.Success; } catch (Exception) { return CommandProcessingResult.RetryLater; } } else if (NextCommandProcessor != null) { return await NextCommandProcessor.HandleCommandAsync(deserializableCommand); } return CommandProcessingResult.CannotComplete; }
public abstract Task<CommandProcessingResult> HandleCommandAsync(DeserializableCommand message);
public async override Task<CommandProcessingResult> HandleCommandAsync(DeserializableCommand deserializableCommand) { if (deserializableCommand.CommandName == CHANGE_SET_POINT_TEMP) { var command = deserializableCommand.Command; try { var device = Device as WeatherShieldDevice; if (device != null) { dynamic parameters = WireCommandSchemaHelper.GetParameters(command); if (parameters != null) { dynamic setPointTempDynamic = ReflectionHelper.GetNamedPropertyValue( parameters, "SetPointTemp", usesCaseSensitivePropertyNameMatch: true, exceptionThrownIfNoMatch: true); if (setPointTempDynamic != null) { double setPointTemp; if (Double.TryParse(setPointTempDynamic.ToString(), out setPointTemp)) { device.ChangeSetPointTemp(setPointTemp); return CommandProcessingResult.Success; } else { // SetPointTemp cannot be parsed as a double. return CommandProcessingResult.CannotComplete; } } else { // setPointTempDynamic is a null reference. return CommandProcessingResult.CannotComplete; } } else { // parameters is a null reference. return CommandProcessingResult.CannotComplete; } } else { // Unsupported Device type. return CommandProcessingResult.CannotComplete; } } catch (Exception) { return CommandProcessingResult.RetryLater; } } else if (NextCommandProcessor != null) { return await NextCommandProcessor.HandleCommandAsync(deserializableCommand); } return CommandProcessingResult.CannotComplete; }
public async Task SignalRejectedCommand(DeserializableCommand command) { if (command == null) { throw new ArgumentNullException("command"); } Debug.Assert(!string.IsNullOrEmpty(command.LockToken), "command.LockToken is a null reference or empty string."); await AzureRetryHelper.OperationWithBasicRetryAsync( async () => { try { await _deviceClient.RejectAsync(command.LockToken); } catch (Exception ex) { _logger.LogError( "{0}{0}*** Exception: Reject Command ***{0}{0}Command Name: {1}{0}Command: {2}{0}Exception: {3}{0}{0}", "\n",// Console.Out.NewLine, command.CommandName, command.Command, ex); } }); }
public async override Task<CommandProcessingResult> HandleCommandAsync(DeserializableCommand deserializableCommand) { if (deserializableCommand.CommandName == DIAGNOSTIC_TELEMETRY) { var command = deserializableCommand.Command; try { var device = Device as WeatherShieldDevice; if (device != null) { dynamic parameters = WireCommandSchemaHelper.GetParameters(command); if (parameters != null) { dynamic activeAsDynamic = ReflectionHelper.GetNamedPropertyValue( parameters, "Active", usesCaseSensitivePropertyNameMatch: true, exceptionThrownIfNoMatch: true); if (activeAsDynamic != null) { var active = Convert.ToBoolean(activeAsDynamic.ToString()); if (active != null) { device.DiagnosticTelemetry(active); return CommandProcessingResult.Success; } else { // Active is not a boolean. return CommandProcessingResult.CannotComplete; } } else { // Active is a null reference. return CommandProcessingResult.CannotComplete; } } else { // parameters is a null reference. return CommandProcessingResult.CannotComplete; } } } catch (Exception) { return CommandProcessingResult.RetryLater; } } else if (NextCommandProcessor != null) { return await NextCommandProcessor.HandleCommandAsync(deserializableCommand); } return CommandProcessingResult.CannotComplete; }