Exemplo n.º 1
0
        public async Task <ActionResult> GetDeviceDetails(string deviceId)
        {
            IEnumerable <DevicePropertyValueModel> propModels;

            dynamic device = await _deviceLogic.GetDeviceAsync(deviceId);

            if (object.ReferenceEquals(device, null))
            {
                throw new InvalidOperationException("Unable to load device with deviceId " + deviceId);
            }

            DeviceDetailModel deviceModel = new DeviceDetailModel
            {
                DeviceID                  = deviceId,
                HubEnabledState           = DeviceSchemaHelper.GetHubEnabledState(device),
                DevicePropertyValueModels = new List <DevicePropertyValueModel>()
            };

            propModels = _deviceLogic.ExtractDevicePropertyValuesModels(device);
            propModels = ApplyDevicePropertyOrdering(propModels);

            deviceModel.DevicePropertyValueModels.AddRange(propModels);

            // check if value is cellular by checking iccid property
            deviceModel.IsCellular = device.SystemProperties.ICCID != null;
            deviceModel.Iccid      = device.SystemProperties.ICCID; // todo: try get rid of null checks

            return(PartialView("_DeviceDetails", deviceModel));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> GetDeviceDetails(string deviceId)
        {
            IEnumerable <DevicePropertyValueModel> propModels;

            dynamic device = await _deviceLogic.GetDeviceAsync(deviceId);

            if (object.ReferenceEquals(device, null))
            {
                throw new InvalidOperationException("Unable to load device with deviceId " + deviceId);
            }

            DeviceDetailModel deviceModel = new DeviceDetailModel()
            {
                DeviceID                  = deviceId,
                HubEnabledState           = DeviceSchemaHelper.GetHubEnabledState(device),
                DevicePropertyValueModels = new List <DevicePropertyValueModel>()
            };

            propModels = _deviceLogic.ExtractDevicePropertyValuesModels(device);
            propModels = ApplyDevicePropertyOrdering(propModels);

            deviceModel.DevicePropertyValueModels.AddRange(propModels);

            return(PartialView("_DeviceDetails", deviceModel));
        }
Exemplo n.º 3
0
        public void GetHubEnabledStateShouldReturnNullButNotThrowIfMissingState()
        {
            var d = GetDeviceWithMissingHubEnabledState();

            var hubEnabledState = DeviceSchemaHelper.GetHubEnabledState(d);

            Assert.AreEqual(null, hubEnabledState);
        }
Exemplo n.º 4
0
        public void GetHubEnabledStateShouldReturnState()
        {
            var d = GetValidDevice();

            var hubEnabledState = DeviceSchemaHelper.GetHubEnabledState(d);

            Assert.AreEqual(true, hubEnabledState);
        }
Exemplo n.º 5
0
        private static bool GetValueMatchesStatus(
            dynamic item,
            string statusName)
        {
            string normalizedStatus;
            bool?  value;

            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (string.IsNullOrEmpty(statusName))
            {
                return(false);
            }

            normalizedStatus = statusName.ToLowerInvariant();
            try
            {
                value = DeviceSchemaHelper.GetHubEnabledState(item);
            }
            catch (DeviceRequiredPropertyNotFoundException)
            {
                value = null;
            }

            switch (normalizedStatus)
            {
            case "running":
                return(value == true);

            case "disabled":
                return(value == false);

            case "pending":
                return(!value.HasValue);

            default:
                throw new ArgumentOutOfRangeException(
                          "statusName",
                          statusName,
                          "statusName has an unhandled status value.");
            }
        }
Exemplo n.º 6
0
        public async Task <ActionResult> Index(string deviceId)
        {
            dynamic device = await _deviceLogic.GetDeviceAsync(deviceId);

            List <SelectListItem> commandListItems = CommandListItems(device);

            var deviceCommandsModel = new DeviceCommandModel
            {
                CommandHistory   = new List <dynamic>(CommandHistorySchemaHelper.GetCommandHistory(device)),
                CommandsJson     = JsonConvert.SerializeObject(device.Commands),
                SendCommandModel = new SendCommandModel
                {
                    DeviceId              = DeviceSchemaHelper.GetDeviceID(device),
                    CommandSelectList     = commandListItems,
                    CanSendDeviceCommands = DeviceSchemaHelper.GetHubEnabledState(device) == true &&
                                            PermsChecker.HasPermission(Permission.SendCommandToDevices)
                },
                DeviceId = DeviceSchemaHelper.GetDeviceID(device)
            };

            return(View(deviceCommandsModel));
        }
Exemplo n.º 7
0
        public async Task <ActionResult> GetDeviceDetails(string deviceId)
        {
            IEnumerable <DevicePropertyValueModel> propModels;

            dynamic device = await this._deviceLogic.GetDeviceAsync(deviceId);

            if (object.ReferenceEquals(device, null))
            {
                throw new InvalidOperationException("Unable to load device with deviceId " + deviceId);
            }

            double version    = 1.0;
            string strversion = DeviceSchemaHelper.GetDeviceVersion(device);

            if (!string.IsNullOrEmpty(strversion))
            {
                double.TryParse(strversion.Trim(), out version);
            }

            DeviceDetailModel deviceModel = new DeviceDetailModel
            {
                DeviceID                  = deviceId,
                HubEnabledState           = DeviceSchemaHelper.GetHubEnabledState(device),
                DevicePropertyValueModels = new List <DevicePropertyValueModel>(),
                DeviceIsNewGeneration     = version > Device_Version_1_0 ? true : false
            };

            propModels = this._deviceLogic.ExtractDevicePropertyValuesModels(device);
            propModels = ApplyDevicePropertyOrdering(propModels);

            deviceModel.DevicePropertyValueModels.AddRange(propModels);

            // check if value is cellular by checking iccid property
            deviceModel.IsCellular = device.SystemProperties.ICCID != null;
            deviceModel.Iccid      = device.SystemProperties.ICCID; // todo: try get rid of null checks

            return(this.PartialView("_DeviceDetails", deviceModel));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Sorts the device list on the given column in the given order
        /// </summary>
        /// <param name="deviceList">List of devices to sort</param>
        /// <param name="sortColumn">Column to sort on</param>
        /// <param name="sortOrder">Order to sort (asc/desc)</param>
        /// <returns>Sorted device list</returns>
        private IQueryable <dynamic> SortDeviceList(IQueryable <dynamic> deviceList, string sortColumn, QuerySortOrder sortOrder)
        {
            Func <dynamic, dynamic> getPropVal;
            Func <dynamic, dynamic> keySelector;

            // if a sort column was not provided then return the full device list in its original sort
            if (string.IsNullOrWhiteSpace(sortColumn))
            {
                return(deviceList);
            }

            getPropVal =
                ReflectionHelper.ProducePropertyValueExtractor(
                    sortColumn,
                    false,
                    false);

            keySelector =
                (item) =>
            {
                dynamic deviceProperties;

                if (item == null)
                {
                    return(null);
                }

                if (string.Equals(
                        "hubEnabledState",
                        sortColumn,
                        StringComparison.CurrentCultureIgnoreCase))
                {
                    try
                    {
                        return(DeviceSchemaHelper.GetHubEnabledState(item));
                    }
                    catch (DeviceRequiredPropertyNotFoundException)
                    {
                        return(null);
                    }
                }

                try
                {
                    deviceProperties =
                        DeviceSchemaHelper.GetDeviceProperties(item);
                }
                catch (DeviceRequiredPropertyNotFoundException)
                {
                    return(null);
                }

                return(getPropVal(deviceProperties));
            };

            if (sortOrder == QuerySortOrder.Ascending)
            {
                return(deviceList.OrderBy(keySelector).AsQueryable());
            }
            else
            {
                return(deviceList.OrderByDescending(keySelector).AsQueryable());
            }
        }
Exemplo n.º 9
0
        public void GetHubEnabledStateShouldThrowIfMissingDeviceProperties()
        {
            var d = GetDeviceWithMissingDeviceProperties();

            Assert.Throws <DeviceRequiredPropertyNotFoundException>(() => DeviceSchemaHelper.GetHubEnabledState(d));
        }