コード例 #1
0
        public async Task <Device> GetDeviceByIdAsync(DeviceRepository deviceRepo, string id, EntityHeader org, EntityHeader user, bool populateMetaData = false)
        {
            if (deviceRepo.RepositoryType.Value == RepositoryTypes.AzureIoTHub)
            {
                var setRepoResult = await SetDeviceRepoAccessKeyAsync(deviceRepo, org, user);

                if (!setRepoResult.Successful)
                {
                    return(null);
                }
            }

            Device device;

            if (deviceRepo.RepositoryType.Value == RepositoryTypes.Local)
            {
                device = await _deviceConnectorService.GetDeviceByIdAsync(deviceRepo.Instance.Id, id, org, user);
            }
            else
            {
                device = await _deviceRepo.GetDeviceByIdAsync(deviceRepo, id);
            }

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

            if (String.IsNullOrEmpty(device.Name))
            {
                device.Name = device.DeviceId;
            }

            await AuthorizeAsync(device, AuthorizeActions.Read, user, org);

            deviceRepo.AccessKey = null;

            if (populateMetaData)
            {
                await _deviceConfigHelper.PopulateDeviceConfigToDeviceAsync(device, deviceRepo.Instance, org, user);
            }
            return(device);
        }
コード例 #2
0
        public async Task <InvokeResult> AddDeviceToGroupAsync(DeviceRepository deviceRepo, String deviceGroupId, String deviceId, EntityHeader org, EntityHeader user)
        {
            var group = await GetDeviceGroupAsync(deviceRepo, deviceGroupId, org, user);

            var device = await _deviceManagementRepo.GetDeviceByIdAsync(deviceRepo, deviceId);

            await AuthorizeAsync(group, AuthorizeResult.AuthorizeActions.Update, user, org);
            await AuthorizeAsync(device, AuthorizeResult.AuthorizeActions.Read, user, org);

            await _deviceGroupEntryRepo.AddDeviceToGroupAsync(deviceRepo, group.ToEntityHeader(), device.ToEntityHeader());

            return(InvokeResult.Success);
        }
コード例 #3
0
        public async Task <InvokeResult <MediaResource> > AddDeviceImageAsync(DeviceRepository deviceRepo, string deviceId, Stream stream, string fileName, string contentType, EntityHeader org, EntityHeader user)
        {
            var imageId = Guid.NewGuid().ToId();

            await AuthorizeAsync(user.Id, org.Id, "Upload Device Image", $"Firmware Id: {deviceId}");

            var mediaSummary = await _mediaServicesManager.AddResourceMediaAsync(imageId, stream, fileName, contentType, org, user);

            var device = await _defaultRepo.GetDeviceByIdAsync(deviceRepo, deviceId);

            device.DeviceImages.Add(mediaSummary.Result);

            return(mediaSummary);
        }