Beispiel #1
0
        public async Task <IActionResult> Details(string id)
        {
            var userDevice = await GetMyDevice(id);

            if (userDevice == null)
            {
                return(NotFound()); // no matter if this device does not exist or you just don't have the access rights. Don't give a hint...
            }

            var    rm     = _deviceManagementService.GlobalRegistryManager;
            Device device = await rm.GetDeviceAsync(id);

            var deviceData      = new DeviceData(device, userDevice);
            var deviceStateList = await _deviceStateService.GetDeviceState(id);

            deviceStateList.ForEach(i => i.LocalTimestamp = i.LocalTimestamp.ToLocalTime());
            deviceData.StateList = deviceStateList;

            var deviceFunctions = await _deviceFunctionService.GetFunctionsAsync(id);

            deviceData.DeviceFunctions = deviceFunctions;

            var devicePlugins = await _devicePluginService.GetAsync(id);

            deviceData.DevicePlugins = devicePlugins;

            return(View(deviceData));
        }
Beispiel #2
0
        public async Task <AppConfigurationModel> Get(string deviceId)
        {
            var deviceFunctions = await _deviceFunctionService.GetFunctionsAsync(deviceId);

            var result = new AppConfigurationModel
            {
                DeviceId                   = deviceId,
                ServiceBaseUrl             = _configuration["ExternalBaseUrl"],
                DevicePluginConfigurations = new List <DevicePluginConfigurationModel>
                {
                    new DevicePluginConfigurationModel // default iot hub configuration for tpm
                    {
                        Name       = "iothub",
                        Type       = "IAzureIoTHubPlugin",
                        Properties = new Dictionary <string, string>()
                    }
                },
                DeviceFunctionIds = deviceFunctions.Select(a => a.RowKey).ToList()
            };

            // add device plugin configurations from database
            var devicePlugins = await _devicePluginService.GetAsync(deviceId);

            foreach (var devicePlugin in devicePlugins.Where(p => p.Enabled)) // only the enabled plugins are reported to the device
            {
                var props = await _devicePluginPropertyService.GetAsync(devicePlugin.RowKey);

                result.DevicePluginConfigurations.Add(new DevicePluginConfigurationModel
                {
                    Name       = devicePlugin.RowKey,
                    Type       = devicePlugin.Type,
                    Properties = props.ToDictionary(k => k.RowKey, k => k.Value)
                });
            }
            return(result);
        }