diff --git a/Marechai.App/Helpers/UntypedNodeExtractor.cs b/Marechai.App/Helpers/UntypedNodeExtractor.cs
deleted file mode 100644
index 11a0f4cb..00000000
--- a/Marechai.App/Helpers/UntypedNodeExtractor.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using Microsoft.Kiota.Abstractions.Serialization;
-
-namespace Marechai.App.Helpers;
-
-///
-/// Helper class for extracting values from Kiota UntypedNode objects.
-///
-public static class UntypedNodeExtractor
-{
- ///
- /// Extracts an integer value from an UntypedNode.
- ///
- /// The UntypedNode to extract from. Can be null.
- /// The extracted integer value, or 0 if extraction fails.
- public static int ExtractInt(UntypedNode? node)
- {
- if(node == null) return 0;
-
- try
- {
- // Cast to UntypedInteger to access the Value property
- if(node is UntypedInteger intNode) return intNode.GetValue();
-
- // Fallback: try to parse ToString() result
- var stringValue = node.ToString();
-
- if(!string.IsNullOrWhiteSpace(stringValue) && int.TryParse(stringValue, out int result)) return result;
-
- return 0;
- }
- catch
- {
- return 0;
- }
- }
-
- ///
- /// Extracts a long value from an UntypedNode.
- ///
- /// The UntypedNode to extract from. Can be null.
- /// The extracted long value, or 0 if extraction fails.
- public static long ExtractLong(UntypedNode? node)
- {
- if(node == null) return 0;
-
- try
- {
- if(node is UntypedInteger intNode) return intNode.GetValue();
-
- var stringValue = node.ToString();
-
- if(!string.IsNullOrWhiteSpace(stringValue) && long.TryParse(stringValue, out long result)) return result;
-
- return 0;
- }
- catch
- {
- return 0;
- }
- }
-}
\ No newline at end of file
diff --git a/Marechai.App/Marechai.App.csproj b/Marechai.App/Marechai.App.csproj
index f996c7af..00335748 100644
--- a/Marechai.App/Marechai.App.csproj
+++ b/Marechai.App/Marechai.App.csproj
@@ -40,10 +40,10 @@
-
+
-
+
diff --git a/Marechai.App/Presentation/ViewModels/CompaniesViewModel.cs b/Marechai.App/Presentation/ViewModels/CompaniesViewModel.cs
index 15919399..cf3d147b 100644
--- a/Marechai.App/Presentation/ViewModels/CompaniesViewModel.cs
+++ b/Marechai.App/Presentation/ViewModels/CompaniesViewModel.cs
@@ -7,12 +7,11 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
-using Marechai.App.Helpers;
using Marechai.App.Presentation.Models;
using Marechai.App.Services;
using Marechai.App.Services.Caching;
-using Uno.Extensions.Navigation;
using Microsoft.UI.Xaml.Media.Imaging;
+using Uno.Extensions.Navigation;
namespace Marechai.App.Presentation.ViewModels;
@@ -20,9 +19,9 @@ public partial class CompaniesViewModel : ObservableObject
{
private readonly List _allCompanies = [];
private readonly CompaniesService _companiesService;
- private readonly CompanyLogoCache _logoCache;
private readonly IStringLocalizer _localizer;
private readonly ILogger _logger;
+ private readonly CompanyLogoCache _logoCache;
private readonly INavigator _navigator;
[ObservableProperty]
@@ -49,9 +48,8 @@ public partial class CompaniesViewModel : ObservableObject
[ObservableProperty]
private string _searchQuery = string.Empty;
- public CompaniesViewModel(CompaniesService companiesService, CompanyLogoCache logoCache,
- IStringLocalizer localizer, ILogger logger,
- INavigator navigator)
+ public CompaniesViewModel(CompaniesService companiesService, CompanyLogoCache logoCache, IStringLocalizer localizer,
+ ILogger logger, INavigator navigator)
{
_companiesService = companiesService;
_logoCache = logoCache;
@@ -98,34 +96,36 @@ public partial class CompaniesViewModel : ObservableObject
// Build the full list in memory
foreach(CompanyDto company in companies)
{
- // Extract id from UntypedNode
- int companyId = UntypedNodeExtractor.ExtractInt(company.Id);
+ // Extract id from company
+ int companyId = company.Id ?? 0;
// Convert DateTimeOffset? to DateTime?
DateTime? foundedDate = company.Founded?.DateTime;
// Load logo if available
SvgImageSource? logoSource = null;
+
if(company.LastLogo.HasValue)
{
try
{
- var logoStream = await _logoCache.GetLogoAsync(company.LastLogo.Value);
+ Stream? logoStream = await _logoCache.GetLogoAsync(company.LastLogo.Value);
logoSource = new SvgImageSource();
await logoSource.SetSourceAsync(logoStream.AsRandomAccessStream());
}
catch(Exception ex)
{
_logger.LogWarning("Failed to load logo for company {CompanyId}: {Exception}",
- companyId, ex.Message);
+ companyId,
+ ex.Message);
}
}
_allCompanies.Add(new CompanyListItem
{
- Id = companyId,
- Name = company.Name ?? string.Empty,
- FoundationDate = foundedDate,
+ Id = companyId,
+ Name = company.Name ?? string.Empty,
+ FoundationDate = foundedDate,
LogoImageSource = logoSource
});
}
@@ -210,10 +210,10 @@ public partial class CompaniesViewModel : ObservableObject
///
public class CompanyListItem
{
- public int Id { get; set; }
- public string Name { get; set; } = string.Empty;
- public DateTime? FoundationDate { get; set; }
- public SvgImageSource? LogoImageSource { get; set; }
+ public int Id { get; set; }
+ public string Name { get; set; } = string.Empty;
+ public DateTime? FoundationDate { get; set; }
+ public SvgImageSource? LogoImageSource { get; set; }
public string FoundationDateDisplay =>
FoundationDate.HasValue ? FoundationDate.Value.ToString("MMMM d, yyyy") : string.Empty;
diff --git a/Marechai.App/Presentation/ViewModels/CompanyDetailViewModel.cs b/Marechai.App/Presentation/ViewModels/CompanyDetailViewModel.cs
index 36e433db..4eff8d67 100644
--- a/Marechai.App/Presentation/ViewModels/CompanyDetailViewModel.cs
+++ b/Marechai.App/Presentation/ViewModels/CompanyDetailViewModel.cs
@@ -7,7 +7,6 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
-using Marechai.App.Helpers;
using Marechai.App.Presentation.Models;
using Marechai.App.Services;
using Marechai.App.Services.Caching;
@@ -139,7 +138,7 @@ public partial class CompanyDetailViewModel : ObservableObject
}
partial void OnCompanyLogosChanged(ObservableCollection? oldValue,
- ObservableCollection newValue)
+ ObservableCollection newValue)
{
// Notify that HasMultipleLogos has changed
OnPropertyChanged(nameof(HasMultipleLogos));
@@ -365,7 +364,7 @@ public partial class CompanyDetailViewModel : ObservableObject
{
try
{
- var countryCode = (short)UntypedNodeExtractor.ExtractInt(Company.CountryId);
+ var countryCode = (short)(Company.CountryId ?? 0);
Stream? flagStream = await _flagCache.GetFlagAsync(countryCode);
var flagSource = new SvgImageSource();
@@ -386,7 +385,7 @@ public partial class CompanyDetailViewModel : ObservableObject
if(Company.SoldToId != null)
{
- int soldToId = UntypedNodeExtractor.ExtractInt(Company.SoldToId);
+ int soldToId = Company.SoldToId ?? 0;
if(soldToId > 0) SoldToCompany = await _companyDetailService.GetSoldToCompanyAsync(soldToId);
}
@@ -421,9 +420,7 @@ public partial class CompanyDetailViewModel : ObservableObject
var logosWithYears = logosList.Select(logo => new
{
Logo = logo,
- Year = logo.Year != null
- ? (int?)UntypedNodeExtractor.ExtractInt(logo.Year)
- : null
+ logo.Year
})
.OrderBy(l => l.Year)
.ToList();
@@ -472,7 +469,7 @@ public partial class CompanyDetailViewModel : ObservableObject
foreach(MachineDto machine in machines)
{
- int machineId = UntypedNodeExtractor.ExtractInt(machine.Id);
+ int machineId = machine.Id ?? 0;
var machineItem = new CompanyDetailMachine
{
diff --git a/Marechai.App/Presentation/ViewModels/ComputersListViewModel.cs b/Marechai.App/Presentation/ViewModels/ComputersListViewModel.cs
index 603598ba..1494c818 100644
--- a/Marechai.App/Presentation/ViewModels/ComputersListViewModel.cs
+++ b/Marechai.App/Presentation/ViewModels/ComputersListViewModel.cs
@@ -6,7 +6,6 @@ using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
-using Marechai.App.Helpers;
using Marechai.App.Presentation.Models;
using Marechai.App.Services;
using Uno.Extensions.Navigation;
@@ -186,7 +185,7 @@ public partial class ComputersListViewModel : ObservableObject
foreach(MachineDto computer in computers.OrderBy(c => c.Name))
{
int year = computer.Introduced?.Year ?? 0;
- int id = UntypedNodeExtractor.ExtractInt(computer.Id);
+ int id = computer.Id ?? 0;
_logger.LogInformation("Computer: {Name}, Introduced: {Introduced}, Year: {Year}, Company: {Company}, ID: {Id}",
computer.Name,
diff --git a/Marechai.App/Presentation/ViewModels/ConsolesListViewModel.cs b/Marechai.App/Presentation/ViewModels/ConsolesListViewModel.cs
index 7825decf..ce734848 100644
--- a/Marechai.App/Presentation/ViewModels/ConsolesListViewModel.cs
+++ b/Marechai.App/Presentation/ViewModels/ConsolesListViewModel.cs
@@ -6,7 +6,6 @@ using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Input;
-using Marechai.App.Helpers;
using Marechai.App.Presentation.Models;
using Marechai.App.Services;
using Uno.Extensions.Navigation;
@@ -184,7 +183,7 @@ public partial class ConsolesListViewModel : ObservableObject
foreach(MachineDto console in consoles.OrderBy(c => c.Name))
{
int year = console.Introduced?.Year ?? 0;
- int id = UntypedNodeExtractor.ExtractInt(console.Id);
+ int id = console.Id ?? 0;
_logger.LogInformation("Console: {Name}, Introduced: {Introduced}, Year: {Year}, Company: {Company}, ID: {Id}",
console.Name,
diff --git a/Marechai.App/Presentation/ViewModels/MachineViewViewModel.cs b/Marechai.App/Presentation/ViewModels/MachineViewViewModel.cs
index 9883666c..cb1a6006 100644
--- a/Marechai.App/Presentation/ViewModels/MachineViewViewModel.cs
+++ b/Marechai.App/Presentation/ViewModels/MachineViewViewModel.cs
@@ -32,7 +32,6 @@ using System.IO;
using System.Threading.Tasks;
using Windows.Storage.Streams;
using Humanizer;
-using Marechai.App.Helpers;
using Marechai.App.Presentation.Models;
using Marechai.App.Services;
using Marechai.App.Services.Caching;
@@ -238,9 +237,9 @@ public partial class MachineViewViewModel : ObservableObject
foreach(ProcessorDto processor in machine.Processors)
{
var details = new List();
- int speed = UntypedNodeExtractor.ExtractInt(processor.Speed);
- int gprSize = UntypedNodeExtractor.ExtractInt(processor.GprSize);
- int cores = UntypedNodeExtractor.ExtractInt(processor.Cores);
+ var speed = (int)(processor.Speed ?? 0);
+ int gprSize = processor.GprSize ?? 0;
+ int cores = processor.Cores ?? 0;
if(speed > 0) details.Add($"{speed} MHz");
if(gprSize > 0) details.Add($"{gprSize} bits");
@@ -261,7 +260,7 @@ public partial class MachineViewViewModel : ObservableObject
{
foreach(MemoryDto mem in machine.Memory)
{
- long size = UntypedNodeExtractor.ExtractLong(mem.Size);
+ long size = mem.Size ?? 0;
string sizeStr = size > 0
? size > 1024 ? $"{size} bytes ({size.Bytes().Humanize()})" : $"{size} bytes"
@@ -299,7 +298,7 @@ public partial class MachineViewViewModel : ObservableObject
foreach(SoundSynthDto synth in machine.SoundSynthesizers)
{
var details = new List();
- int voices = UntypedNodeExtractor.ExtractInt(synth.Voices);
+ int voices = synth.Voices ?? 0;
if(voices > 0) details.Add($"{voices} voices");
@@ -317,7 +316,7 @@ public partial class MachineViewViewModel : ObservableObject
{
foreach(StorageDto storage in machine.Storage)
{
- long capacity = UntypedNodeExtractor.ExtractLong(storage.Capacity);
+ long capacity = storage.Capacity ?? 0;
string displayText = capacity > 0
? capacity > 1024
diff --git a/Marechai.App/Presentation/ViewModels/NewsViewModel.cs b/Marechai.App/Presentation/ViewModels/NewsViewModel.cs
index c18f2611..0a561f63 100644
--- a/Marechai.App/Presentation/ViewModels/NewsViewModel.cs
+++ b/Marechai.App/Presentation/ViewModels/NewsViewModel.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
-using Marechai.App.Helpers;
using Marechai.App.Presentation.Models;
using Marechai.App.Services;
using Marechai.Data;
@@ -94,7 +93,7 @@ public partial class NewsViewModel : ObservableObject
// Extract the machine ID from AffectedId
if(news.AffectedId is null) return;
- int machineId = UntypedNodeExtractor.ExtractInt(news.AffectedId);
+ int machineId = news.AffectedId ?? 0;
if(machineId <= 0) return;
diff --git a/Marechai.App/Services/ComputersService.cs b/Marechai.App/Services/ComputersService.cs
index a47c1a10..b9f813ed 100644
--- a/Marechai.App/Services/ComputersService.cs
+++ b/Marechai.App/Services/ComputersService.cs
@@ -2,8 +2,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
-using Marechai.App.Helpers;
-using Microsoft.Kiota.Abstractions.Serialization;
namespace Marechai.App.Services;
@@ -30,11 +28,9 @@ public class ComputersService
try
{
_logger.LogInformation("Fetching computers count from API");
- UntypedNode result = await _apiClient.Computers.Count.GetAsync();
+ int? result = await _apiClient.Computers.Count.GetAsync();
- // Extract integer value from UntypedNode
- // UntypedNode wraps a JsonElement, we need to parse it
- int count = UntypedNodeExtractor.ExtractInt(result);
+ int count = result ?? 0;
_logger.LogInformation("Successfully fetched computers count: {Count}", count);
return count;
@@ -56,10 +52,9 @@ public class ComputersService
try
{
_logger.LogInformation("Fetching minimum year from API");
- UntypedNode result = await _apiClient.Computers.MinimumYear.GetAsync();
+ int? result = await _apiClient.Computers.MinimumYear.GetAsync();
- // Extract integer value from UntypedNode
- int year = UntypedNodeExtractor.ExtractInt(result);
+ int year = result ?? 0;
_logger.LogInformation("Successfully fetched minimum year: {Year}", year);
return year;
@@ -81,10 +76,9 @@ public class ComputersService
try
{
_logger.LogInformation("Fetching maximum year from API");
- UntypedNode result = await _apiClient.Computers.MaximumYear.GetAsync();
+ int? result = await _apiClient.Computers.MaximumYear.GetAsync();
- // Extract integer value from UntypedNode
- int year = UntypedNodeExtractor.ExtractInt(result);
+ int year = result ?? 0;
_logger.LogInformation("Successfully fetched maximum year: {Year}", year);
return year;
diff --git a/Marechai.App/Services/ConsolesService.cs b/Marechai.App/Services/ConsolesService.cs
index 410d7824..e77bfaaa 100644
--- a/Marechai.App/Services/ConsolesService.cs
+++ b/Marechai.App/Services/ConsolesService.cs
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
-using Marechai.App.Helpers;
-using Microsoft.Kiota.Abstractions.Serialization;
namespace Marechai.App.Services;
@@ -29,11 +27,9 @@ public class ConsolesService
try
{
_logger.LogInformation("Fetching consoles count from API");
- UntypedNode result = await _apiClient.Consoles.Count.GetAsync();
+ int? result = await _apiClient.Consoles.Count.GetAsync();
- // Extract integer value from UntypedNode
- // UntypedNode wraps a JsonElement, we need to parse it
- int count = UntypedNodeExtractor.ExtractInt(result);
+ int count = result ?? 0;
_logger.LogInformation("Successfully fetched consoles count: {Count}", count);
return count;
@@ -55,10 +51,9 @@ public class ConsolesService
try
{
_logger.LogInformation("Fetching minimum year from API");
- UntypedNode result = await _apiClient.Consoles.MinimumYear.GetAsync();
+ int? result = await _apiClient.Consoles.MinimumYear.GetAsync();
- // Extract integer value from UntypedNode
- int year = UntypedNodeExtractor.ExtractInt(result);
+ int year = result ?? 0;
_logger.LogInformation("Successfully fetched minimum year: {Year}", year);
return year;
@@ -80,10 +75,9 @@ public class ConsolesService
try
{
_logger.LogInformation("Fetching maximum year from API");
- UntypedNode result = await _apiClient.Consoles.MaximumYear.GetAsync();
+ int? result = await _apiClient.Consoles.MaximumYear.GetAsync();
- // Extract integer value from UntypedNode
- int year = UntypedNodeExtractor.ExtractInt(result);
+ int year = result ?? 0;
_logger.LogInformation("Successfully fetched maximum year: {Year}", year);
return year;