From a8ac2e3c92c807507c67bb7fe173a26d0ee67357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20LAVERGNE?= Date: Sun, 16 Jun 2024 19:23:21 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20IGDBClient=20and=20Settings=20initi?= =?UTF-8?q?alization=20for=20the=20MAUI=20Project=20(binding)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/GameAtlas/GameAtlas/App.xaml.cs | 44 ++++++++++++++++--------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/Sources/GameAtlas/GameAtlas/App.xaml.cs b/Sources/GameAtlas/GameAtlas/App.xaml.cs index a14480e..e2f9904 100644 --- a/Sources/GameAtlas/GameAtlas/App.xaml.cs +++ b/Sources/GameAtlas/GameAtlas/App.xaml.cs @@ -1,7 +1,11 @@ -using Models; +using System.Diagnostics; +using Models; using Stub; using DataContractPersistance; using GameAtlas.Views; +using Microsoft.Extensions.Options; +using Microsoft.VisualBasic.FileIO; +using Models.API; namespace GameAtlas; @@ -23,34 +27,42 @@ public partial class App : Application /// /// Gestionnaire principal de l'application. /// - public Manager MyManager { get; private set; } = new Manager(new Stub.Stub());//new Manager(new DataContractPersistance.DataContractPers()); + public Manager MyManager { get; private set; } + + private readonly IGDBClient _igdbClient; + private readonly IGDBSettings _igdbSettings; /// /// Constructeur de l'application. /// - public App() + public App(IGDBClient igdbClient, IOptions igdbSettings) { - InitializeComponent(); + MyManager = new Manager(new Stub.Stub(), _igdbClient); - if (File.Exists(Path.Combine(FilePath, FileName))) - { - //MyManager = new Manager(new DataContractPersistance.DataContractXML()); - MyManager = new Manager(new DataContractPersistance.DataContractJSON()); - } + InitializeComponent(); MyManager.ChargerDonnees(); MainPage = new AppShell(); + _igdbClient = igdbClient; + _igdbSettings = igdbSettings.Value; + + // For debug purposes, load games when the app starts + LoadGames(); + } - if (!File.Exists(Path.Combine(FilePath, FileName))) + private async void LoadGames() + { + try { - //MyManager.Persistance = new DataContractPersistance.DataContractXML(); - MyManager.Persistance = new DataContractPersistance.DataContractJSON(); + var games = await _igdbClient.GetGamesAsync(); + Debug.WriteLine($"Games: {games}"); } - - - MyManager.SauvegardeDonnees(); - } + catch (HttpRequestException ex) + { + Debug.WriteLine($"Request failed: {ex.Message}"); + } + } }