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 <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 })); }
static public async Task Do(CmdArguments args) { var twin = new Twin(); twin.ETag = "*"; twin.Set(args.KVPairs); var startTime = DateTime.UtcNow + TimeSpan.FromSeconds(args.StartOffsetInSeconds); var client = JobClient.CreateFromConnectionString(Settings.Default.ConnectionString); var jobId = args.JobId; if (string.IsNullOrEmpty(jobId)) { jobId = Guid.NewGuid().ToString(); } JobResponse job = await client.ScheduleTwinUpdateAsync( jobId, args.QueryCondition, twin, startTime, args.TimeoutInSeconds); Console.WriteLine($"{job.Type} job {job.JobId} scheduled"); await IoTHubHelper.WaitJob(client, job); }
public void SetTest() { string deviceId = Guid.NewGuid().ToString(); var twin = new Twin(); twin.Set("deviceId", deviceId); twin.Set("tags.x", "one"); twin.Set("twin.tags.X", "ONE"); twin.Set("properties.desired.y", 1); twin.Set("twin.properties.desired.Y", 2); Assert.Equal(twin.DeviceId.ToString(), deviceId); Assert.Equal(twin.Tags["x"].ToString(), "one"); Assert.Equal(twin.Tags["X"].ToString(), "ONE"); Assert.Equal((int)twin.Properties.Desired["y"], 1); Assert.Equal((int)twin.Properties.Desired["Y"], 2); }
static public async Task Do(CmdArguments args) { var client = RegistryManager.CreateFromConnectionString(Settings.Default.ConnectionString); var deviceId = args.Ids.Single(); var twin = new Twin(deviceId); twin.Set(args.KVPairs); twin = await client.UpdateTwinAsync(deviceId, twin, "*"); IoTHubHelper.OutputDevice(twin); Console.WriteLine("1 device updated"); }
static public async Task Do(CmdArguments args) { var client = RegistryManager.CreateFromConnectionString(Settings.Default.ConnectionString); foreach (var deviceId in args.Ids) { await client.AddDeviceAsync(new Device(deviceId)); Console.WriteLine($"{deviceId} added"); if (args.KVPairs != null) { var twin = new Twin(); twin.Set(args.KVPairs); await client.UpdateTwinAsync(deviceId, twin, "*"); } } await IoTHubHelper.QueryDevicesByIds(client, args.Ids); }
public void SetShouldNotThrowIfFullNameIsInvalidate() { var twin = new Twin(); twin.Set("prefix.x", "one"); }