using System.Collections.Generic;
using Microsoft.Maui.Networking;
public class FirmwareRelease
public string Version { get; set; }
public string Release_Date { get; set; }
public string Url { get; set; }
public override string ToString()
return $"Version: {Version}, Release Date (UTC): {Release_Date:yyyy-MM-ddTHH:mm:ssZ}, URL: {Url}";
static void Main(string[] args)
string url = "http://dayton-pub.s3-website.us-east-2.amazonaws.com/dx3files/index.json";
string jsonString = RetrieveJsonFile(url);
Console.WriteLine(jsonString);
if (!string.IsNullOrEmpty(jsonString))
var options = new JsonSerializerOptions
PropertyNameCaseInsensitive = true
var firmwareReleases = JsonSerializer.Deserialize<List<FirmwareRelease>>(jsonString, options);
foreach (var release in firmwareReleases)
Console.WriteLine($"Version: {release.Version}");
Console.WriteLine($"Release Date (UTC): {release.Release_Date}");
Console.WriteLine($"URL: {release.Url}");
static string RetrieveJsonFile(string url)
if (url.StartsWith("file:", StringComparison.OrdinalIgnoreCase))
return RetrieveLocalFile(url);
else if (url.StartsWith("http:", StringComparison.OrdinalIgnoreCase) || url.StartsWith("https:", StringComparison.OrdinalIgnoreCase))
return RetrieveHttpFile(url);
throw new ArgumentException("Unsupported URL scheme. Only file, http, and https are supported.");
static string RetrieveLocalFile(string fileUrl)
string filePath = new Uri(fileUrl).LocalPath;
if (File.Exists(filePath))
return File.ReadAllText(filePath);
throw new FileNotFoundException("The file could not be found.", filePath);
static string RetrieveHttpFile(string httpUrl)
var client = new RestClient(httpUrl);
var request = new RestRequest("", Method.Get);
RestResponse response = client.Execute(request);
if (response.StatusCode == HttpStatusCode.OK)
throw new WebException($"Failed to retrieve the file from {httpUrl}. Status Code: {response.StatusCode}");
static bool IsInternetAvailable()
var current = Connectivity.Current;
return current.NetworkAccess == NetworkAccess.Internet;