using Model;
namespace Managers
{
///
/// Define the manager of the data. This is where all the data are put, and where we call the loading and the saving of them.
///
public class DataDefaultManager : IDataManager
{
#region Attributes & Properties
public IDataSerializer Serializer { get; set; }
public Dictionary> Data { get; private set; }
#endregion
#region Constructors
///
/// Constructor of the DataDefaultManager class. Take a IDataManager that will provide methods for the serialisation of the data.
///
/// The data manager that know how to serialize a file.
/// The data set of the application.
public DataDefaultManager(IDataSerializer dataManager,
Dictionary>? data = null)
{
Serializer = dataManager;
if (data is null)
Data = new Dictionary>();
else
Data = data;
}
#endregion
#region Methods
public void LoadData()
=> Data = Serializer.Load();
public void SaveData()
=> Serializer.Save(Data);
public void Import(string pathOfTheFile)
where T : class
{
KeyValuePair import = Serializer.Import(pathOfTheFile);
Data[import.Key].Add(import.Value);
}
public void Export(T obj, string pathToExport)
where T : class
=> Serializer.Export(obj, pathToExport);
public ICollection GetFromData() where T : class
=> new List(Data[typeof(T).Name].Cast());
#endregion
}
}