public void UpdateAssignment() { string sql = "select S_RTUID from T_RTIOT_devices where S_assignmentsToken is null "; DataTable dt = DbHelperSQL.Query(sql).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { Assignments ass = JsonConvert.DeserializeObject <Assignments>(sm.getDeviceCurrentAssignment(dt.Rows[i]["S_RTUID"].ToString().Trim())); if (ass != null) { sql = "update T_RTIOT_devices set S_assignmentsToken='" + ass.token + "' where S_RTUID='" + dt.Rows[i]["S_RTUID"].ToString().Trim() + "'"; DbHelperSQL.ExecuteSql(sql); } } }
public string createDeviceAssignment(string deviceHardwareId, string assetModuleId, string assetId) { Assignments assignments = new Assignments(); Dictionary <string, string> dic = new Dictionary <string, string>(); assignments.token = Guid.NewGuid().ToString("N"); assignments.deviceHardwareId = deviceHardwareId; assignments.assignmentType = "Associated"; assignments.assetModuleId = assetModuleId; assignments.assetId = assetId; assignments.metadata = dic; string data = JsonConvert.SerializeObject(assignments); data = gp.HttpPost("http://" + httpurl + "/sitewhere/api/assignments/", data, tenanttoken); string sql = " update T_RTIOT_devices set S_assignmentsToken='" + assignments.token + "' where S_RTUID='" + deviceHardwareId + "'"; DbHelperSQL.ExecuteSql(sql); return(data); }