public async Task <GadgetStatus> GetStatusAsync(Gadget gadget)
        {
            GadgetStatus gadgetStatus = SerializeWebResponse <GadgetStatus>(await ManageWebRequestAndReturnResponse(gadget.IpAddress));

            _gadgetStatusRequestService.SaveGadgetStatusRequest(gadget, gadgetStatus);

            return(gadgetStatus ?? null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the StatusIndicationColor for the current GadgetStatus
        /// </summary>
        /// <param name="gadgetStatus"></param>
        /// <returns></returns>
        public static StatusIndicatorColors GetStatusIndicatorColor(GadgetStatus gadgetStatus)
        {
            if (gadgetStatus == null)
            {
                return(StatusIndicatorColors.Black);
            }

            if (gadgetStatus.overtemperature == false && gadgetStatus.temperature <= 90.00 && gadgetStatus.voltage <= 250.00)
            {
                return(StatusIndicatorColors.Green);
            }

            return(StatusIndicatorColors.Red);
        }
Exemplo n.º 3
0
        public void SaveGadgetStatusRequest(Gadget gadget, GadgetStatus gadgetStatus)
        {
            GadgetStatusRequest gadgetStatusRequest = new GadgetStatusRequest
            {
                GadgetId        = gadget.Id,
                RequestDateTime = DateTime.Now,

                Temperature          = 00.00,
                Voltage              = 00.00,
                IsStatusRequestValid = false
            };

            if (gadgetStatus != null && gadgetStatus.temperature > 0.00)
            {
                gadgetStatusRequest.Temperature          = gadgetStatus.temperature;
                gadgetStatusRequest.Voltage              = gadgetStatus.voltage;
                gadgetStatusRequest.IsStatusRequestValid = true;
            }

            SaveGadgetStatusRequest(gadgetStatusRequest);
        }
Exemplo n.º 4
0
        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;
            }
        }