You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
51 lines
1.3 KiB
using CoreLibrary.Joueurs;
|
|
using CoreLibrary.Persistance;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace CoreLibrary.Manager
|
|
{
|
|
public class Manager : IDisposable
|
|
{
|
|
private bool estDetruit;
|
|
|
|
private readonly IPersistance persistance;
|
|
|
|
private readonly List<Joueur> joueurs;
|
|
public IReadOnlyCollection<Joueur> Joueurs => joueurs.AsReadOnly();
|
|
|
|
private readonly List<Partie> parties;
|
|
public IReadOnlyCollection<Partie> Parties => parties.AsReadOnly();
|
|
|
|
public Manager(IPersistance persistance)
|
|
{
|
|
this.persistance = persistance ?? throw new ArgumentNullException(nameof(persistance));
|
|
joueurs = this.persistance.ChargerJoueurs() ?? new List<Joueur>();
|
|
parties = this.persistance.ChargerParties() ?? new List<Partie>();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
protected virtual void Dispose(bool detruire)
|
|
{
|
|
if (estDetruit) return;
|
|
|
|
if (detruire)
|
|
{
|
|
persistance.EnregistrerJoueurs(joueurs);
|
|
persistance.EnregistrerParties(parties);
|
|
}
|
|
|
|
estDetruit = true;
|
|
}
|
|
|
|
~Manager()
|
|
{
|
|
Dispose(false);
|
|
}
|
|
}
|
|
}
|