‼️ Ajout du nécessaire pour implémenter la persistance et son management au sein de toute les autres vues

pull/97/head
Rémi LAVERGNE 11 months ago
parent c4cbcf282f
commit 39fb86e881
No known key found for this signature in database
GPG Key ID: 7BCBAE9031E39160

@ -1,28 +1,58 @@
using DataContractPersistence;
using System.Diagnostics;
using System.Runtime.Serialization.DataContracts;
using DataContractPersistence;
using Models.Game;
using Models.Interfaces;
namespace Trek_12
{
public partial class App : Application
{
public string FileName { get; set; } = "data.json";
public string FilePath { get; set; } = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
public string FilePath { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Trek_12");
public Game Manager { get; private set; }
public App()
{
InitializeComponent();
if(File.Exists(Path.Combine(FilePath, FileName)))
Manager = new Game(new DataContractJson());
if (!Directory.Exists(FilePath))
{
Directory.CreateDirectory(FilePath);
}
//File.Delete(Path.Combine(FilePath, FileName));
string fullPath = Path.Combine(FilePath, FileName);
if (File.Exists(fullPath))
{
Manager = new Game(new DataContractJson());
Debug.WriteLine("Data loaded from " + fullPath);
Manager.LoadData();
}
Manager.LoadData();
MainPage = new AppShell();
// If the MainPage is closed, we save the data
MainPage.Disappearing += (sender, e) =>
{
Debug.WriteLine("Saving data...");
Manager.SaveData();
};
}
/// <summary>
/// Save the data when the app is in background
/// </summary>
protected override void OnSleep()
{
Debug.WriteLine("Zzz Secure save...");
Manager.SaveData();
}
}
}

Loading…
Cancel
Save