public async Task <ActionResult> ScheduleIconUpdate(ScheduleTwinUpdateModel model) { var twin = new Twin() { ETag = "*" }; twin.Set(model.Tags[0].TagName, model.Tags[0].isDeleted ? null : model.Tags[0].TagValue); await _nameCacheLogic.AddNameAsync(model.Tags[0].TagName); 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, Convert.ToInt64(model.MaxExecutionTimeInMinutes * 60)); await _jobRepository.AddAsync(new JobRepositoryModel(jobId, model.FilterId, model.JobName, deviceListFilter.Name, model.Tags[0].isDeleted ? ExtendJobType.ScheduleRemoveIcon : ExtendJobType.ScheduleUpdateIcon, null)); return(RedirectToAction("Index", "Job", new { jobId = jobId })); }
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 })); }