public async Task AddNameAsyncTest() { var name = "desired.test"; _nameCacheRepositoryMock.Setup(x => x.AddNameAsync(NameCacheEntityType.DesiredProperty, It.IsAny <NameCacheEntity>())).ReturnsAsync(true); var ret = await _nameCacheLogic.AddNameAsync(name); Assert.True(ret); name = "reported.test"; _nameCacheRepositoryMock.Setup(x => x.AddNameAsync(NameCacheEntityType.ReportedProperty, It.IsAny <NameCacheEntity>())).ReturnsAsync(true); ret = await _nameCacheLogic.AddNameAsync(name); Assert.True(ret); name = "tags.test"; _nameCacheRepositoryMock.Setup(x => x.AddNameAsync(NameCacheEntityType.Tag, It.IsAny <NameCacheEntity>())).ReturnsAsync(true); ret = await _nameCacheLogic.AddNameAsync(name); Assert.True(ret); name = "deviceId"; _nameCacheRepositoryMock.Setup(x => x.AddNameAsync(NameCacheEntityType.DeviceInfo, It.IsAny <NameCacheEntity>())).ReturnsAsync(true); ret = await _nameCacheLogic.AddNameAsync(name); Assert.True(ret); }
public async Task <ActionResult> ScheduleTwinUpdate(ScheduleTwinUpdateModel model) { var twin = new Twin(); foreach (var tagModel in model.Tags.Where(m => !string.IsNullOrWhiteSpace(m.TagName))) { string key = tagModel.TagName; if (tagModel.isDeleted) { twin.Set(key, null); } else { TwinExtension.Set(twin, key, getDyanmicValue(tagModel.DataType, tagModel.TagValue)); } await _nameCacheLogic.AddNameAsync(tagModel.TagName); } foreach (var propertyModel in model.DesiredProperties.Where(m => !string.IsNullOrWhiteSpace(m.PropertyName))) { string key = propertyModel.PropertyName; if (propertyModel.isDeleted) { twin.Set(key, null); } else { TwinExtension.Set(twin, key, getDyanmicValue(propertyModel.DataType, propertyModel.PropertyValue)); } await _nameCacheLogic.AddNameAsync(propertyModel.PropertyName); } twin.ETag = "*"; var deviceListFilter = await GetFilterById(model.FilterId); string queryCondition = deviceListFilter.GetSQLCondition(); // The query condition can not be empty when schduling job, use a default clause // is_defined(deviceId) to represent no clause condition for all devices. var jobId = await _iotHubDeviceManager.ScheduleTwinUpdate( string.IsNullOrWhiteSpace(queryCondition)? "is_defined(deviceId)" : queryCondition, twin, model.StartDateUtc, (int)(model.MaxExecutionTimeInMinutes * 60)); await _jobRepository.AddAsync(new JobRepositoryModel(jobId, model.FilterId, model.JobName, deviceListFilter.Name, ExtendJobType.ScheduleUpdateTwin, null)); return(RedirectToAction("Index", "Job", new { jobId = jobId })); }
public async Task AddToNameCache(string deviceId) { var device = await this.GetDeviceAsync(deviceId); var twin = device.Twin; await _nameCacheLogic.AddNameAsync(nameof(device.Twin.DeviceId)); await _nameCacheLogic.AddShortNamesAsync( NameCacheEntityType.Tag, twin.Tags .AsEnumerableFlatten() .Select(pair => pair.Key)); await _nameCacheLogic.AddShortNamesAsync( NameCacheEntityType.DesiredProperty, twin.Properties.Desired .AsEnumerableFlatten() .Select(pair => pair.Key)); await _nameCacheLogic.AddShortNamesAsync( NameCacheEntityType.ReportedProperty, twin.Properties.Reported .AsEnumerableFlatten() .Select(pair => pair.Key) .Where(name => !SupportedMethodsHelper.IsSupportedMethodProperty(name))); foreach (var command in device.Commands.Where(c => c.DeliveryType == DeliveryType.Method)) { await _nameCacheLogic.AddMethodAsync(command); } }
public async Task UpdateDeviceTwinDesiredProps(string deviceId, IEnumerable <PropertyViewModel> newtwin) { Twin updatetwin = new Twin(); updatetwin.ETag = "*"; foreach (var twin in newtwin) { if (String.IsNullOrEmpty(twin.Key)) { continue; } var key = twin.Key; if (key.ToLower().StartsWith("desired.")) { key = key.Substring(8); } setTwinProperties(twin, updatetwin.Properties.Desired, key); var addnametask = _nameCacheLogic.AddNameAsync(twin.Key); } await _deviceManager.UpdateTwinAsync(deviceId, updatetwin); }