Пример #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));
        }
Пример #2
0
        public async Task UpdateFunctionsAndVersionsTwinPropertyAsync(string deviceId)
        {
            var functions = await _deviceFunctionService.GetFunctionsAsync(deviceId);

            string functionsAndVersions = "";

            foreach (var function in functions)
            {
                functionsAndVersions += function.RowKey + ":" + function.Version + ",";
            }
            functionsAndVersions = functionsAndVersions.TrimEnd(',');

            // update device twin
            var patch = new
            {
                properties = new
                {
                    desired = new
                    {
                        functions = new
                        {
                            versions = functionsAndVersions,
                            baseUrl  = _configuration["ExternalBaseUrl"]
                        }
                    }
                }
            };

            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                CheckAdditionalContent = false
            };
            var twin = await _globalRegistryManager.GetTwinAsync(deviceId);

            await _globalRegistryManager.UpdateTwinAsync(deviceId, JsonConvert.SerializeObject(patch),
                                                         twin.ETag);
        }
Пример #3
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);
        }
Пример #4
0
        public async Task <List <DeviceFunctionModel> > Get(string deviceId)
        {
            var result = await _deviceFunctionService.GetFunctionsAsync(deviceId);

            return(result.Select(a => a.ToDeviceFunctionModel()).ToList());
        }