using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Model { /// /// 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 DataManager { #region Attributes & Properties /// /// The data manager injected that know how to serialize the data. ///
The setter is actually public for testing purpose. It will be private after. ///
See: ///
public IDataManager Serializer { get; set; } /// /// The collection of all data. Each line of this dictionary has the type of the data as it key and the data for values. /// public Dictionary> Data { get; private set; } #endregion #region Constructors /// /// Constructor of the DataManager class. Take a IDataManager that will provide methods for the serialisation of the data. /// /// The data manager that know how to serialize a file. public DataManager(IDataManager dataMgr) { Serializer = dataMgr; Data = Serializer.Load(); } #endregion #region Methods /// /// Reload the data. Useful to update new data written in the save file. ///
See: ///
public void Reload() => Data = Serializer.Load(); /// /// Save the data. Call the Save method of the serializer. ///
See: ///
public void Save() => Serializer.Save(Data); /// /// Import data from a file. ///
See: ///
/// The type of data to import. /// The path containing the name of the file created. public void Import(string pathOfTheFile) where T : class { KeyValuePair import = Serializer.Import(pathOfTheFile); Data[import.Key].Add(import.Value); } /// /// Export the data from the collection of data. ///
See: ///
/// The type of data to export /// The object to export /// The path containing the name of the file created. public void Export(T obj, string pathToExport) where T : class => Serializer.Export(obj, pathToExport); #endregion } }