new manager interfaces

pull/55/head
Alexandre AGOSTINHO 2 years ago
parent 99c04979b9
commit e3bf8f503a

@ -9,7 +9,7 @@ string path = ""; // - path to the save file
string strategy = "xml"; // - strategy is 'xml' or 'json' (/!\ this is case sensitive) string strategy = "xml"; // - strategy is 'xml' or 'json' (/!\ this is case sensitive)
MasterManager masterMgr; MasterManager masterMgr;
IDataManager dataManager = (strategy == "xml") ? IDataSerializer dataManager = (strategy == "xml") ?
new DataContractXML(path) new DataContractXML(path)
: new DataContractJSON(path); : new DataContractJSON(path);

@ -14,7 +14,7 @@ namespace DataPersistence
/// <summary> /// <summary>
/// Define a serializer to manage JSON files. /// Define a serializer to manage JSON files.
/// </summary> /// </summary>
public class DataContractJSON : IDataManager public class DataContractJSON : IDataSerializer
{ {
#region Attributes #region Attributes
private string _jsonFolderPath; private string _jsonFolderPath;

@ -13,7 +13,7 @@ namespace DataPersistence
/// <summary> /// <summary>
/// Define a serializer to manage XML files. /// Define a serializer to manage XML files.
/// </summary> /// </summary>
public class DataContractXML : IDataManager public class DataContractXML : IDataSerializer
{ {
#region Attributes #region Attributes
private string _xmlFolderPath; private string _xmlFolderPath;

@ -10,7 +10,7 @@ namespace DataPersistence
/// <summary> /// <summary>
/// The subs class is a group of prefabricated object that can only be loaded. It only use is for testing. /// The subs class is a group of prefabricated object that can only be loaded. It only use is for testing.
/// </summary> /// </summary>
public class Stubs : IDataManager public class Stubs : IDataSerializer
{ {
public Dictionary<string, List<object>> Load() public Dictionary<string, List<object>> Load()
{ {

@ -16,9 +16,9 @@ namespace Model
/// <summary> /// <summary>
/// The data manager injected that know how to serialize the data. /// The data manager injected that know how to serialize the data.
/// <br/><remarks><i>The setter is actually public for testing purpose. It will be private after.</i></remarks> /// <br/><remarks><i>The setter is actually public for testing purpose. It will be private after.</i></remarks>
/// <br/>See: <see cref="IDataManager"/> /// <br/>See: <see cref="IDataSerializer"/>
/// </summary> /// </summary>
public IDataManager Serializer { get; set; } public IDataSerializer Serializer { get; set; }
/// <summary> /// <summary>
/// The collection of all data. Each line of this dictionary has the type of the data as it key and the data for values. /// The collection of all data. Each line of this dictionary has the type of the data as it key and the data for values.
@ -31,7 +31,7 @@ namespace Model
/// Constructor of the DataManager class. Take a IDataManager that will provide methods for the serialisation of the data. /// Constructor of the DataManager class. Take a IDataManager that will provide methods for the serialisation of the data.
/// </summary> /// </summary>
/// <param name="dataMgr">The data manager that know how to serialize a file.</param> /// <param name="dataMgr">The data manager that know how to serialize a file.</param>
public DataManager(IDataManager dataMgr) public DataManager(IDataSerializer dataMgr)
{ {
Serializer = dataMgr; Serializer = dataMgr;
Data = Serializer.Load(); Data = Serializer.Load();
@ -41,21 +41,21 @@ namespace Model
#region Methods #region Methods
/// <summary> /// <summary>
/// Reload the data. Useful to update new data written in the save file. /// Reload the data. Useful to update new data written in the save file.
/// <br/>See: <see cref="IDataManager.Load"/> /// <br/>See: <see cref="IDataSerializer.Load"/>
/// </summary> /// </summary>
public void Reload() public void Reload()
=> Data = Serializer.Load(); => Data = Serializer.Load();
/// <summary> /// <summary>
/// Save the data. Call the Save method of the serializer. /// Save the data. Call the Save method of the serializer.
/// <br/>See: <see cref="IDataManager.Save(Dictionary{string, List{object}})"/> /// <br/>See: <see cref="IDataSerializer.Save(Dictionary{string, List{object}})"/>
/// </summary> /// </summary>
public void Save() public void Save()
=> Serializer.Save(Data); => Serializer.Save(Data);
/// <summary> /// <summary>
/// Import data from a file. /// Import data from a file.
/// <br/>See: <see cref="IDataManager.Import{T}(string)"/> /// <br/>See: <see cref="IDataSerializer.Import{T}(string)"/>
/// </summary> /// </summary>
/// <typeparam name="T">The type of data to import.</typeparam> /// <typeparam name="T">The type of data to import.</typeparam>
/// <param name="pathOfTheFile">The path containing the name of the file created.</param> /// <param name="pathOfTheFile">The path containing the name of the file created.</param>
@ -68,7 +68,7 @@ namespace Model
/// <summary> /// <summary>
/// Export the data from the collection of data. /// Export the data from the collection of data.
/// <br/>See: <see cref="IDataManager.Export{T}(T, string)"/> /// <br/>See: <see cref="IDataSerializer.Export{T}(T, string)"/>
/// </summary> /// </summary>
/// <typeparam name="T">The type of data to export</typeparam> /// <typeparam name="T">The type of data to export</typeparam>
/// <param name="obj">The object to export</param> /// <param name="obj">The object to export</param>

@ -1,44 +1,17 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Model namespace Model.Managers
{ {
/// <summary> public interface IDataManager
/// Interface that define the methods of a data serializer. {
/// </summary> void LoadData();
public interface IDataManager void ReloadData();
{ void SaveData();
/// <summary> void Import<T>(string pathOfTheFile) where T : class;
/// Save all the data in a file. void Export<T>(T obj, string pathToExport) where T : class;
/// </summary> }
/// <param name="elements">The data to save.</param> }
void Save(Dictionary<string, List<object>> elements);
/// <summary>
/// Load all the data from a file.
/// </summary>
/// <returns>The data loaded.</returns>
Dictionary<string, List<object>> Load();
/// <summary>
/// Import an element to the collection of data.
/// </summary>
/// <typeparam name="T">The type of the element to impoert</typeparam>
/// <param name="pathToImport">The path containing the name of the file.</param>
/// <returns>A pair where the key is the entry in the data and the value is the value to add on this entry.</returns>
public KeyValuePair<string, T> Import<T>(string pathToImport)
where T : class;
/// <summary>
/// Export an element from the collection of data.
/// </summary>
/// <typeparam name="T">The type of the exported object.</typeparam>
/// <param name="obj">The object to export.</param>
/// <param name="pathToExport">The path containing the name of the file created.</param>
public void Export<T>(T obj, string pathToExport)
where T : class;
}
}

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
/// <summary>
/// Interface that define the methods of a data serializer.
/// </summary>
public interface IDataSerializer
{
/// <summary>
/// Save all the data in a file.
/// </summary>
/// <param name="elements">The data to save.</param>
void Save(Dictionary<string, List<object>> elements);
/// <summary>
/// Load all the data from a file.
/// </summary>
/// <returns>The data loaded.</returns>
Dictionary<string, List<object>> Load();
/// <summary>
/// Import an element to the collection of data.
/// </summary>
/// <typeparam name="T">The type of the element to impoert</typeparam>
/// <param name="pathToImport">The path containing the name of the file.</param>
/// <returns>A pair where the key is the entry in the data and the value is the value to add on this entry.</returns>
public KeyValuePair<string, T> Import<T>(string pathToImport)
where T : class;
/// <summary>
/// Export an element from the collection of data.
/// </summary>
/// <typeparam name="T">The type of the exported object.</typeparam>
/// <param name="obj">The object to export.</param>
/// <param name="pathToExport">The path containing the name of the file created.</param>
public void Export<T>(T obj, string pathToExport)
where T : class;
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Managers
{
public interface IRecipeManager
{
RecipeCollection GetAllRecipes();
Recipe GetRecipeFromId(int id);
RecipeCollection GetRecipeByTitle(string title);
RecipeCollection GetRecipeByAuthor(string authorMail);
RecipeCollection GetRecipesByPriorityOrder(Priority priority);
bool AddRecipeToData(Recipe recipe);
bool ModifyRecipeInData(Recipe recipe);
}
}

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model.Managers
{
public interface IUserManager
{
ICollection<User> GetAllUsers();
User GetUserFromMail(string mail);
bool AddUserToData(User user);
bool ModifyUserInData(User user);
bool LogIn(string mail, string password);
bool LogOut();
}
}

@ -41,7 +41,7 @@ namespace Model.Managers
/// Constructor of the MasterManager. /// Constructor of the MasterManager.
/// </summary> /// </summary>
/// <param name="dataManager">The serializer for the data.</param> /// <param name="dataManager">The serializer for the data.</param>
public MasterManager(IDataManager dataManager) public MasterManager(IDataSerializer dataManager)
{ {
DataMgr = new DataManager(dataManager); DataMgr = new DataManager(dataManager);
CurrentConnectedUser = null; CurrentConnectedUser = null;

Loading…
Cancel
Save