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)
MasterManager masterMgr;
IDataManager dataManager = (strategy == "xml") ?
IDataSerializer dataManager = (strategy == "xml") ?
new DataContractXML(path)
: new DataContractJSON(path);

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

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

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

@ -16,9 +16,9 @@ namespace Model
/// <summary>
/// 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/>See: <see cref="IDataManager"/>
/// <br/>See: <see cref="IDataSerializer"/>
/// </summary>
public IDataManager Serializer { get; set; }
public IDataSerializer Serializer { get; set; }
/// <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.
@ -31,7 +31,7 @@ namespace Model
/// Constructor of the DataManager class. Take a IDataManager that will provide methods for the serialisation of the data.
/// </summary>
/// <param name="dataMgr">The data manager that know how to serialize a file.</param>
public DataManager(IDataManager dataMgr)
public DataManager(IDataSerializer dataMgr)
{
Serializer = dataMgr;
Data = Serializer.Load();
@ -41,21 +41,21 @@ namespace Model
#region Methods
/// <summary>
/// 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>
public void Reload()
=> Data = Serializer.Load();
/// <summary>
/// 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>
public void Save()
=> Serializer.Save(Data);
/// <summary>
/// Import data from a file.
/// <br/>See: <see cref="IDataManager.Import{T}(string)"/>
/// <br/>See: <see cref="IDataSerializer.Import{T}(string)"/>
/// </summary>
/// <typeparam name="T">The type of data to import.</typeparam>
/// <param name="pathOfTheFile">The path containing the name of the file created.</param>
@ -68,7 +68,7 @@ namespace Model
/// <summary>
/// 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>
/// <typeparam name="T">The type of data to export</typeparam>
/// <param name="obj">The object to export</param>

@ -4,41 +4,14 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
namespace Model.Managers
{
/// <summary>
/// Interface that define the methods of a data serializer.
/// </summary>
public interface IDataManager
{
/// <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;
void LoadData();
void ReloadData();
void SaveData();
void Import<T>(string pathOfTheFile) where T : class;
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.
/// </summary>
/// <param name="dataManager">The serializer for the data.</param>
public MasterManager(IDataManager dataManager)
public MasterManager(IDataSerializer dataManager)
{
DataMgr = new DataManager(dataManager);
CurrentConnectedUser = null;

Loading…
Cancel
Save