public async override Task <CommandProcessingResult> HandleCommandAsync(DeserializableCommand deserializableCommand) { if (deserializableCommand.CommandName == "SetCamera") { var command = deserializableCommand.Command; try { var device = Device as CoolerDevice; if (device != null) { dynamic parameters = WireCommandSchemaHelper.GetParameters(command); if (parameters != null) { dynamic statusstring = ReflectionHelper.GetNamedPropertyValue( parameters, "data", usesCaseSensitivePropertyNameMatch: true, exceptionThrownIfNoMatch: true); bool isboolean = false; if (statusstring != null && bool.TryParse(statusstring.ToString(), out isboolean)) { return(CommandProcessingResult.Success); } 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 override Task <CommandProcessingResult> HandleCommandAsync(DeserializableCommand deserializableCommand) { if (deserializableCommand.CommandName == CHANGE_DEVICE_STATE) { CommandHistory commandHistory = deserializableCommand.CommandHistory; try { var device = Device as CoolerDevice; if (device != null) { dynamic parameters = commandHistory.Parameters; if (parameters != null) { dynamic deviceState = ReflectionHelper.GetNamedPropertyValue( parameters, "DeviceState", usesCaseSensitivePropertyNameMatch: true, exceptionThrownIfNoMatch: true); if (deviceState != null) { await 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 override async Task <CommandProcessingResult> HandleCommandAsync(DeserializableCommand deserializableCommand) { if (deserializableCommand.CommandName == "PingDevice") { CommandHistory command = deserializableCommand.CommandHistory; try { 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 == START_TELEMETRY) { try { var device = Device as CoolerDevice; 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 == "EmergencyStop") { 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 async override Task <CommandProcessingResult> HandleCommandAsync(DeserializableCommand deserializableCommand) { if (deserializableCommand.CommandName == CHANGE_SET_POINT_TEMP) { CommandHistory commandHistory = deserializableCommand.CommandHistory; try { var device = Device as CoolerDevice; if (device != null) { dynamic parameters = commandHistory.Parameters; 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 override Task <CommandProcessingResult> HandleCommandAsync(DeserializableCommand deserializableCommand) { if (deserializableCommand.CommandName == SEND_WAYPOINTS) { var command = deserializableCommand.Command; try { var device = Device as CoolerDevice; if (device != null) { dynamic parameters = WireCommandSchemaHelper.GetParameters(command); if (parameters != null) { dynamic waypoints = ReflectionHelper.GetNamedPropertyValue( parameters, "data", usesCaseSensitivePropertyNameMatch: true, exceptionThrownIfNoMatch: true); if (waypoints != null) { JArray waypointArray = JArray.Parse(waypoints.ToString()); if (waypointArray != null && waypointArray.Count > 0) { 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 override Task <CommandProcessingResult> HandleCommandAsync(DeserializableCommand deserializableCommand) { if (deserializableCommand.CommandName == DIAGNOSTIC_TELEMETRY) { CommandHistory commandHistory = deserializableCommand.CommandHistory; try { var device = Device as CoolerDevice; if (device != null) { dynamic parameters = commandHistory.Parameters; 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); }