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)); }
/// <summary> /// Gets <see cref="DevicePropertyValueModel" /> for an edited Device's /// properties. /// </summary> /// <param name="device"> /// The edited Device. /// </param> /// <returns> /// <see cref="DevicePropertyValueModel" />s, representing /// <paramref name="device" />'s properties. /// </returns> public IEnumerable <DevicePropertyValueModel> ExtractDevicePropertyValuesModels( dynamic device) { dynamic deviceProperties; IDynamicMetaObjectProvider dynamicMetaObjectProvider; string hostNameValue; IEnumerable <DevicePropertyValueModel> propValModels; ICustomTypeDescriptor typeDescriptor; if (object.ReferenceEquals(device, null)) { throw new ArgumentNullException("device"); } deviceProperties = DeviceSchemaHelper.GetDeviceProperties(device); if (object.ReferenceEquals(deviceProperties, null)) { throw new ArgumentException("device.DeviceProperties is a null reference.", "device"); } var deviceVersion = DeviceSchemaHelper.GetDeviceVersion(device); if ((dynamicMetaObjectProvider = deviceProperties as IDynamicMetaObjectProvider) != null) { propValModels = ExtractPropertyValueModels(dynamicMetaObjectProvider); } else if ((typeDescriptor = deviceProperties as ICustomTypeDescriptor) != null) { propValModels = ExtractPropertyValueModels(typeDescriptor); } else { propValModels = ExtractPropertyValueModels((object)deviceProperties); } hostNameValue = this._configProvider.GetConfigurationSettingValue("iotHub.HostName"); if (!string.IsNullOrEmpty(hostNameValue) && !string.IsNullOrEmpty(deviceVersion)) { propValModels = propValModels.Concat( new DevicePropertyValueModel[] { new DevicePropertyValueModel() { DisplayOrder = 0, IsEditable = false, IsIncludedWithUnregisteredDevices = true, Name = "HostName", PropertyType = Models.PropertyType.String, Value = hostNameValue }, new DevicePropertyValueModel() { IsEditable = false, IsIncludedWithUnregisteredDevices = true, Name = "DeviceGeneration", PropertyType = Models.PropertyType.String, Value = deviceVersion } }); } return(propValModels); }