private static object RunUpdateAndReturnExitCode(UpdateOptions opts) { if (!configurationHelper.ReadConfig()) { return(false); } bool isSuccess = false; opts = iotDeviceHelper.CleanOptions(opts as object, false) as UpdateOptions; opts = iotDeviceHelper.CompleteMissingUpdateOptions(opts, configurationHelper); var twin = iotDeviceHelper.QueryDeviceTwin(opts.DevEui, configurationHelper).Result; if (twin != null) { twin = iotDeviceHelper.UpdateDeviceTwin(twin, opts); if (iotDeviceHelper.VerifyDeviceTwin(opts.DevEui, opts.NetId, twin, configurationHelper)) { isSuccess = iotDeviceHelper.WriteDeviceTwin(twin, opts.DevEui, configurationHelper, false).Result; if (isSuccess) { var newTwin = iotDeviceHelper.QueryDeviceTwin(opts.DevEui, configurationHelper).Result; Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"DevEUI: {opts.DevEui}"); Console.WriteLine(TwinToString(newTwin)); Console.ResetColor(); } else { Console.WriteLine(); StatusConsole.WriteLine(MessageType.Error, $"Can not update device {opts.DevEui}."); } } else { Console.WriteLine(); StatusConsole.WriteLine(MessageType.Error, $"Errors found in Twin data. Device {opts.DevEui} was not updated."); } } else { Console.WriteLine(); StatusConsole.WriteLine(MessageType.Error, $"Could not get data for device {opts.DevEui}. Failed to update."); isSuccess = false; } return(isSuccess); }
private static async Task <bool> RunUpdateAndReturnExitCode(UpdateOptions opts) { if (!configurationHelper.ReadConfig()) { return(false); } bool isSuccess = false; opts = iotDeviceHelper.CleanOptions(opts as object, false) as UpdateOptions; opts = iotDeviceHelper.CompleteMissingUpdateOptions(opts, configurationHelper); var twin = await iotDeviceHelper.QueryDeviceTwin(opts.DevEui, configurationHelper); if (twin != null) { twin = iotDeviceHelper.UpdateDeviceTwin(twin, opts); if (iotDeviceHelper.VerifyDeviceTwin(opts.DevEui, opts.NetId, twin, configurationHelper, true)) { isSuccess = await iotDeviceHelper.WriteDeviceTwin(twin, opts.DevEui, configurationHelper, false); if (isSuccess) { var newTwin = await iotDeviceHelper.QueryDeviceTwin(opts.DevEui, configurationHelper); StatusConsole.WriteTwin(opts.DevEui, twin); } else { Console.WriteLine(); StatusConsole.WriteLogLine(MessageType.Error, $"Can not update device {opts.DevEui}."); } } else { Console.WriteLine(); StatusConsole.WriteLogLine(MessageType.Error, $"Errors found in Twin data. Device {opts.DevEui} was not updated."); } } else { Console.WriteLine(); StatusConsole.WriteLogLine(MessageType.Error, $"Could not get data for device {opts.DevEui}. Failed to update."); isSuccess = false; } return(isSuccess); }