Exemple #1
0
        public static async Task <dynamic> GetDeviceAsync(string UUID)
        {
            using (HttpClient client = Balena.HttpClient())
            {
                //                curl - X GET "https://api.balena-cloud.com/v4/device(<ID>)" \
                //-H "Content-Type: application/json" \
                //-H "Authorization: Bearer <AUTH_TOKEN>"$"{APIURI}/v4/device({UUID})"
                using (HttpResponseMessage res = await client.GetAsync($"device?$filter=uuid%20eq%20'{UUID}'"))
                {
                    using (HttpContent content = res.Content)
                    {
                        string data = await content.ReadAsStringAsync();

                        if (data != null)
                        {
                            if (res.IsSuccessStatusCode && JObject.Parse(data).Count > 0)
                            {
                                return(((dynamic)JObject.Parse(data)).d[0].id);
                            }
                        }
                        return(null);
                    }
                }
            }
        }
Exemple #2
0
        public static async Task <bool> SetTenantID(String DeviceUUID, String TenantId)
        {
            using (HttpClient client = Balena.HttpClient())
            {
                Hashtable ht = new Hashtable();
                ht.Add("device", GetDeviceIdAsync(DeviceUUID, client).GetAwaiter().GetResult());
                ht.Add("name", "TENANT_ID");
                ht.Add("value", TenantId);

                using (HttpResponseMessage res = await client.PostAsJsonAsync("device_environment_variable", ht))
                {
                    if (res.StatusCode == System.Net.HttpStatusCode.NotFound)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemple #3
0
        public static async Task <dynamic> GetEnvironmentVariablesAsync(string DeviceUUID)
        {
            using (HttpClient client = Balena.HttpClient())
            {
                String deviceID = GetDeviceIdAsync(DeviceUUID).GetAwaiter().GetResult();
                using (HttpResponseMessage res = await client.GetAsync($"device_environment_variable?$filter=device eq {deviceID}")){
                    if (res.IsSuccessStatusCode)
                    {
                        string data = await res.Content.ReadAsStringAsync();

                        if (data != null)
                        {
                            if (res.IsSuccessStatusCode)  // && JObject.Parse(data).Count > 0)
                            {
                                return(((dynamic)JObject.Parse(data)).d);
                                //return ((dynamic)JObject.Parse(data)).d[0].id;
                            }
                        }
                    }
                }
            }
            return(null);
        }
Exemple #4
0
 public static async Task <string> GetDeviceAppIdAsync(string UUID)
 {
     return((await Balena.GetDeviceAsync(UUID).GetAwaiter().GetResult()).belongs_to__application.__id);
 }
Exemple #5
0
 public static async Task <string> GetDeviceIdAsync(string UUID)
 {
     return((await Balena.GetDeviceAsync(UUID).GetAwaiter().GetResult()).id);
 }