private void RefreshGadgets() { Gadgets.Clear(); service.GetAllGadgets().ForEach(g => Gadgets.Add(g)); }
private async Task ExecuteLoadItemsCommand() { IsBusy = true; try { Gadgets.Clear(); var gadgets = await _gadgetDataStore.GetAllAsync(true); if (gadgets == null || gadgets.Count() == 0) { return; } var unsortedGadgetList = new List <GadgetViewModel>(); foreach (Gadget gadget in gadgets) { GadgetStatus gadgetStatus = await _webRequestService.GetStatusAsync(gadget); var statusIndicatorColor = GadgetHelper.GetStatusIndicatorColor(gadgetStatus); if (gadgetStatus == null) { gadgetStatus = new GadgetStatus { temperature = 0.00, overtemperature = false, temperature_status = "undefined", mac = "", voltage = 0.00 }; } var viewModel = new GadgetViewModel { Id = gadget.Id, DeviceId = gadgetStatus.mac, Name = gadget.Name, Location = gadget.Location, IpAddress = gadget.IpAddress, Description = gadget.Description, IsStatusOk = gadgetStatus.temperature_status == "Normal", StatusIndicatorColor = statusIndicatorColor.ToString(), TemperatureStatus = gadgetStatus.temperature_status, Temperature = gadgetStatus.temperature, TemperatureC = $"{ gadgetStatus.temperature } °C", Voltage = gadgetStatus.voltage, VoltageV = $"{ gadgetStatus.voltage } V" }; if (gadgetStatus.temperature_status == "undefined") { viewModel.TemperatureC = AppTranslations.Page_GadgetDetail_Fallback_NotAvailable; } unsortedGadgetList.Add(viewModel); } List <GadgetViewModel> sortedGadgetList = await GadgetHelper.SortGadgetListBySettingAsync(unsortedGadgetList); sortedGadgetList.ForEach(Gadgets.Add); } catch (Exception ex) { var properties = new Dictionary <string, string> { { "Method", "ExecuteLoadItemsCommand" }, { "Event", "Could not Add GadgetViewModel" } }; AppHelper.TrackError(ex, properties); } finally { IsBusy = false; } }