diff --git a/MCTG/ConsoleApp/ConsoleApp.csproj b/MCTG/ConsoleApp/ConsoleApp.csproj index 7e8ef62..dbc5e22 100644 --- a/MCTG/ConsoleApp/ConsoleApp.csproj +++ b/MCTG/ConsoleApp/ConsoleApp.csproj @@ -8,6 +8,7 @@ + diff --git a/MCTG/ConsoleApp/Menu/MainMenu.cs b/MCTG/ConsoleApp/Menu/MainMenu.cs index f26bdf0..8dcbb8b 100644 --- a/MCTG/ConsoleApp/Menu/MainMenu.cs +++ b/MCTG/ConsoleApp/Menu/MainMenu.cs @@ -1,4 +1,5 @@ using Model; +using DataPersistence; using System; using System.Collections.Generic; using System.Linq; @@ -15,7 +16,7 @@ namespace ConsoleApp.Menu public MainMenu(DataManager dataMgr) : base("Main menu", new Selector( - new SearcherRecipe(dataMgr.AllRecipes), "Recipe search"), + new SearcherRecipe(new RecipeCollection("search", dataMgr.Data[nameof(Recipe)].Cast().ToArray())), "Recipe search"), new Selector( new ConnectionMenu(), "Connection")) { } diff --git a/MCTG/ConsoleApp/MenuManager.cs b/MCTG/ConsoleApp/MenuManager.cs index bbbf6d1..20cf567 100644 --- a/MCTG/ConsoleApp/MenuManager.cs +++ b/MCTG/ConsoleApp/MenuManager.cs @@ -1,5 +1,6 @@ using ConsoleApp.Menu; using Model; +using DataPersistence; using System; using System.Collections.Generic; using System.Linq; diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs index a60cdcd..65c6564 100644 --- a/MCTG/ConsoleApp/Program.cs +++ b/MCTG/ConsoleApp/Program.cs @@ -2,23 +2,34 @@ using ConsoleApp; using ConsoleApp.Menu; +using DataPersistence; using Model; - +using System.Linq; using System.Text; Console.WriteLine("Hello, World!\n\n"); // TESTS: +DataManager dataMgr = new DataManager(new Stubs()); +//DataManager dataMgr = new DataManager(new DataContractXML(xmlFolderPath: "../../../../DataPersistence/data")); +//DataManager dataMgr = new DataManager(new DataContractJSON()); + +//dataMgr.Serializer = new DataContractXML(xmlFolderPath: "../../../../DataPersistence/data"); +dataMgr.Serializer = new DataContractJSON(); -List recipeCollections = Stub.LoadRecipeCollection(); -RecipeCollection? allRecipe = recipeCollections.Find(x => x.Description.Equals("All")); -if (allRecipe == null) - throw new ArgumentException("Load AllRecipe in stub: can't find 'All'."); +// /!\ here is an absolute path I put for testing purpose. It will only work on my computer so don't forget to change it whene you test. +//dataMgr.Export(rc[2], "C:\\Users\\alex6\\Downloads\\recipe2.json"); +//dataMgr.Import("C:\\Users\\alex6\\Downloads\\recipe2.json"); -DataManager dataMgr = new DataManager(allRecipe); +RecipeCollection rc = new RecipeCollection("All recipes", dataMgr.Data[nameof(Recipe)].Cast().ToArray()); + +dataMgr.Save(); MenuManager menuMgr = new MenuManager(dataMgr); menuMgr.Loop(); + +// press any key to quit +//Console.ReadKey(); diff --git a/MCTG/ConsoleApp/Stubs/Stub.cs b/MCTG/ConsoleApp/Stubs/Stub.cs deleted file mode 100644 index 689a013..0000000 --- a/MCTG/ConsoleApp/Stubs/Stub.cs +++ /dev/null @@ -1,99 +0,0 @@ -using Model; -using System; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ConsoleApp -{ - internal struct Stub - { - public static List LoadRecipes() - { - List stub = new List(); - stub.AddRange(new[] - { - new Recipe(), - new Recipe( - title: "Cookies"), - new Recipe( - title: "Cookies", id: 23), - new Recipe( - title: "Cookies au chocolat", id: null), - new Recipe( - title: "", id: null), - new Recipe( - title: "", id: 24), - new Recipe( - title: "Cookies", id: 24, - preparationSteps: new[]{ - new PreparationStep(1) - }), - new Recipe( - title: "Cookies", id: 26, - preparationSteps: new[]{ - new PreparationStep(1), - new PreparationStep(2, "Faire cuire.") - }), - new Recipe( - title: "Gateau à la crème", - preparationSteps: new[]{ - new PreparationStep(1, "Ajouter les oeufs."), - new PreparationStep(2, "Ajouter la farine."), - new PreparationStep(3, "Mélanger le tout."), - new PreparationStep(4, "Faire cuire 1h10 au four traditionnel.") - }), - new Recipe( - title: "Gateau au chocolat", - preparationSteps: new[]{ - new PreparationStep(1, "Ajouter les oeufs."), - new PreparationStep(2, "Ajouter la farine."), - new PreparationStep(2, "Ajouter 100g de chocolat fondu."), - new PreparationStep(3, "Mélanger le tout."), - new PreparationStep(4, "Faire cuire 45h au four traditionnel.") - }), - new Recipe( - title: "Gateau aux cerises", - preparationSteps: new[]{ - new PreparationStep(1, "Ajouter les oeufs."), - new PreparationStep(2, "Ajouter la farine."), - new PreparationStep(2, "Ajouter des morceaux de fraises découpées en petits carré"), - new PreparationStep(3, "Mélanger le tout."), - new PreparationStep(4, "Faire cuire 30min au four traditionnel.") - }), - }); - return stub; - } - - public static List LoadRecipeCollection() - { - List stub = new List(); - stub.AddRange(new[] - { - new RecipeCollection("All", LoadRecipes().ToArray()), - new RecipeCollection("Starters", LoadRecipes().FindAll(x => x.Id.Equals(23)).ToArray()), - new RecipeCollection("Dishies", LoadRecipes().FindAll(x => x.Id.Equals(24)).ToArray()), - new RecipeCollection("Desserts", LoadRecipes().FindAll(x => x.Id.Equals(26)).ToArray()), - }); - return stub; - } - - - public static List ConstrucList() - { - List Users = new List(); - - User Roger = new User("Roger", "Rabbit", "carotte@mail.fr"); - User Dylan = new User("d", "r", "dr@mail.fr"); - User Val = new User("V", "entin", "Valentin@mail.fr"); - - Users.Add(Roger); - Users.Add(Dylan); - Users.Add(Val); - - return Users; - } - } -} diff --git a/MCTG/DataPersistence/DataContractJSON.cs b/MCTG/DataPersistence/DataContractJSON.cs new file mode 100644 index 0000000..382a4eb --- /dev/null +++ b/MCTG/DataPersistence/DataContractJSON.cs @@ -0,0 +1,111 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Json; +using System.Text; +using System.Threading.Tasks; +using System.Xml; +using System.Xml.Linq; + +namespace DataPersistence +{ + /// + /// Define a serializer to manage JSON files. + /// + public class DataContractJSON : IDataManager + { + #region Attributes + private string _jsonFolderPath; + private DataContractJsonSerializerSettings _dataContractJsonSerializerSettings; + #endregion + + #region Constructors + /// + /// Constructor of the DataContractJSON serializer. + /// + /// Give the default path where to load and save the data (by default is the current execution dir). + /// Give another set of DataContractJson serializer setting to write file + public DataContractJSON(string jsonFolderPath = "", + DataContractJsonSerializerSettings? dataContractJsonSerializerSettings = null) + { + _jsonFolderPath = jsonFolderPath; + if (dataContractJsonSerializerSettings is null) + _dataContractJsonSerializerSettings = new DataContractJsonSerializerSettings() + { + KnownTypes = new[] { typeof(Recipe) } + }; + else + _dataContractJsonSerializerSettings = dataContractJsonSerializerSettings; + } + #endregion + + #region IDataManager implementation + public void Export(T obj, string pathToExport) + where T : class + { + var jsonSerializer = new DataContractJsonSerializer(typeof(T), _dataContractJsonSerializerSettings); + using (FileStream stream = File.Create(Path.Combine(_jsonFolderPath, pathToExport))) + { + using (var jsonWriter = JsonReaderWriterFactory.CreateJsonWriter( + stream: stream, + encoding: System.Text.Encoding.UTF8, + ownsStream: false, + indent: true)) + { + jsonSerializer.WriteObject(jsonWriter, obj); + } + } + } + + public KeyValuePair Import(string pathToImport) + where T : class + { + T? obj; + var jsonSerializer = new DataContractJsonSerializer(typeof(T), _dataContractJsonSerializerSettings); + using (FileStream stream = File.OpenRead(Path.Combine(_jsonFolderPath, pathToImport))) + { + obj = jsonSerializer.ReadObject(stream) as T; + } + + if (obj is null) + throw new ArgumentNullException("obj"); + + string typeName = typeof(T).Name; + return new KeyValuePair(typeName, obj); + } + + public Dictionary> Load() + { + Dictionary>? elements = new Dictionary>(); + var jsonSerializer = new DataContractJsonSerializer(typeof(Dictionary>), _dataContractJsonSerializerSettings); + using (FileStream stream = File.OpenRead(Path.Combine(_jsonFolderPath, "data.json"))) + { + elements = jsonSerializer.ReadObject(stream) as Dictionary>; + } + + if (elements is null) + throw new ArgumentNullException("elements"); + + return elements; + } + + public void Save(Dictionary> elements) + { + var jsonSerializer = new DataContractJsonSerializer(typeof(Dictionary>), _dataContractJsonSerializerSettings); + using (FileStream stream = File.Create(Path.Combine(_jsonFolderPath, "data.json"))) + { + using (var jsonWriter = JsonReaderWriterFactory.CreateJsonWriter( + stream: stream, + encoding: System.Text.Encoding.UTF8, + ownsStream: false, + indent: true)) + { + jsonSerializer.WriteObject(jsonWriter, elements); + } + } + } + #endregion + } +} diff --git a/MCTG/DataPersistence/DataContractXML.cs b/MCTG/DataPersistence/DataContractXML.cs new file mode 100644 index 0000000..3944c85 --- /dev/null +++ b/MCTG/DataPersistence/DataContractXML.cs @@ -0,0 +1,115 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; +using System.Xml; +using System.Xml.Linq; + +namespace DataPersistence +{ + /// + /// Define a serializer to manage XML files. + /// + public class DataContractXML : IDataManager + { + #region Attributes + private string _xmlFolderPath; + private XmlWriterSettings _xmlWriterSettings; + private DataContractSerializerSettings _dataContractSerializerSettings; + #endregion + + #region Constructors + /// + /// Constructor of a DataContractXML serializer. + /// + /// Give the default path where to load and save the data (by default is the current execution dir). + /// Give another set of XML setting to write file. + /// Give another set of DataContract serializer setting to write file + public DataContractXML(string xmlFolderPath = "", + XmlWriterSettings? xmlWriterSettings = null, + DataContractSerializerSettings? dataContractSerializerSettings = null) + { + _xmlFolderPath = xmlFolderPath; + + if (xmlWriterSettings is null) + _xmlWriterSettings = new XmlWriterSettings() { Indent = true }; + else + _xmlWriterSettings = xmlWriterSettings; + + if (dataContractSerializerSettings is null) + _dataContractSerializerSettings = new DataContractSerializerSettings() + { + KnownTypes = new Type[] { typeof(Recipe) }, + PreserveObjectReferences = true + }; + else + _dataContractSerializerSettings = dataContractSerializerSettings; + } + #endregion + + #region IDataManager implementation + public void Export(T obj, string pathToExport) + where T : class + { + bool restore = _dataContractSerializerSettings.PreserveObjectReferences; + _dataContractSerializerSettings.PreserveObjectReferences = false; + var serializer = new DataContractSerializer(typeof(T), _dataContractSerializerSettings); + using (TextWriter textWriter = File.CreateText(Path.Combine(_xmlFolderPath, pathToExport))) + { + using (XmlWriter xmlWriter = XmlWriter.Create(textWriter, _xmlWriterSettings)) + { + serializer.WriteObject(xmlWriter, obj); + } + } + _dataContractSerializerSettings.PreserveObjectReferences = restore; + } + + public KeyValuePair Import(string pathToImport) + where T : class + { + T? obj; + var serializer = new DataContractSerializer(typeof(T), _dataContractSerializerSettings); + using (Stream s = File.OpenRead(Path.Combine(_xmlFolderPath, pathToImport))) + { + obj = serializer.ReadObject(s) as T; + } + + if (obj is null) + throw new ArgumentNullException("obj"); + + string typeName = typeof(T).Name; + return new KeyValuePair(typeName, obj); + } + + public Dictionary> Load() + { + Dictionary>? elements; + var serializer = new DataContractSerializer(typeof(Dictionary>), _dataContractSerializerSettings); + using (Stream s = File.OpenRead(Path.Combine(_xmlFolderPath, "data.xml"))) + { + elements = serializer.ReadObject(s) as Dictionary>; + } + + if (elements is null) + throw new ArgumentNullException("elements"); + + return elements; + } + + public void Save(Dictionary> elements) + { + var serializer = new DataContractSerializer(typeof(Dictionary>), _dataContractSerializerSettings); + using (TextWriter textWriter = File.CreateText(Path.Combine(_xmlFolderPath, "data.xml"))) + { + using (XmlWriter xmlWriter = XmlWriter.Create(textWriter, _xmlWriterSettings)) + { + serializer.WriteObject(xmlWriter, elements); + } + } + } + #endregion + } +} diff --git a/MCTG/DataPersistence/DataManager.cs b/MCTG/DataPersistence/DataManager.cs new file mode 100644 index 0000000..a06d94d --- /dev/null +++ b/MCTG/DataPersistence/DataManager.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataPersistence +{ + /// + /// 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 + } +} diff --git a/MCTG/DataPersistence/DataPersistence.csproj b/MCTG/DataPersistence/DataPersistence.csproj new file mode 100644 index 0000000..d5050a6 --- /dev/null +++ b/MCTG/DataPersistence/DataPersistence.csproj @@ -0,0 +1,17 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + diff --git a/MCTG/DataPersistence/IDataManager.cs b/MCTG/DataPersistence/IDataManager.cs new file mode 100644 index 0000000..95209d8 --- /dev/null +++ b/MCTG/DataPersistence/IDataManager.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataPersistence +{ + /// + /// Interface that define the methods of a data serializer. + /// + public interface IDataManager + { + /// + /// Save all the data in a file. + /// + /// The data to save. + void Save(Dictionary> elements); + + /// + /// Load all the data from a file. + /// + /// The data loaded. + Dictionary> Load(); + + /// + /// Import an element to the collection of data. + /// + /// The type of the element to impoert + /// The path containing the name of the file. + /// A pair where the key is the entry in the data and the value is the value to add on this entry. + public KeyValuePair Import(string pathToImport) + where T : class; + + /// + /// Export an element from the collection of data. + /// + /// The type of the exported object. + /// The object to export. + /// The path containing the name of the file created. + public void Export(T obj, string pathToExport) + where T : class; + } +} diff --git a/MCTG/DataPersistence/Stubs.cs b/MCTG/DataPersistence/Stubs.cs new file mode 100644 index 0000000..cc09f39 --- /dev/null +++ b/MCTG/DataPersistence/Stubs.cs @@ -0,0 +1,112 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DataPersistence +{ + /// + /// The subs class is a group of prefabricated object that can only be loaded. It only use is for testing. + /// + public class Stubs : IDataManager + { + public Dictionary> Load() + { + Dictionary> data = new Dictionary> + { + { + #region Data: Recipes + nameof(Recipe), + new List(new[] + { + new Recipe( + title: "Cookies classiques", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Faire cuire."), + new PreparationStep(2, "Manger.") + }), + new Recipe( + title: "Cookies au chocolat", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Moulinez la pâte."), + new PreparationStep(2, "Faire cuire pendant une bonne heure."), + new PreparationStep(3, "Sortir du four et mettre dans un plat.") + }), + new Recipe( + title: "Gateau nature", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Achetez les ingrédients."), + new PreparationStep(2, "Préparez le matériel. Ustensiles et tout."), + new PreparationStep(3, "Pleurez.") + }), + new Recipe( + title: "Gateau au pommes", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Achetez les légumes."), + new PreparationStep(2, "Préparez le plat. Ustensiles et préchauffez le four."), + new PreparationStep(3, "Coupez les pommes en morceaux et disposez-les sur le plat."), + new PreparationStep(4, "Mettez enfin le plat au four, puis une fois cuit, dégustez !") + }), + new Recipe( + title: "Gateau au chocolat", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Ajouter les oeufs."), + new PreparationStep(2, "Ajouter la farine."), + new PreparationStep(3, "Ajouter 100g de chocolat fondu."), + new PreparationStep(4, "Mélanger le tout."), + new PreparationStep(5, "Faire cuire 45h au four traditionnel.") + }), + new Recipe( + title: "Dinde au jambon", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Faire une cuisson bien sec de la dinde à la poêle"), + new PreparationStep(2, "Mettre la dinde au frigo."), + new PreparationStep(3, "Mettre le jambon dans le micro-onde."), + new PreparationStep(4, "Faire chauffer 3min."), + new PreparationStep(5, "Présentez sur un plat la dinde et le jambon : Miam !") + }), + new Recipe( + title: "Poulet au curry", id: null, + preparationSteps: new[] + { + new PreparationStep(1, "Trouvez des épices de curry."), + new PreparationStep(2, "Trouvez maintenant du poulet."), + new PreparationStep(3, "Coupez la tête du poulet et posez-la dans un plat."), + new PreparationStep(4, "Parsemez d'épices curry la tête de la poule."), + new PreparationStep(5, "Mettre le tout au four traditionnel 30min."), + new PreparationStep(6, "Dégustez en famille !") + }) + }) + #endregion + } + }; + + return data; + } + + #region Not supported methods + public void Save(Dictionary> elements) + { + throw new NotSupportedException(); + } + + public void Export(T obj, string pathToExport) where T : class + { + throw new NotSupportedException(); + } + + public KeyValuePair Import(string pathToImport) where T : class + { + throw new NotSupportedException(); + } + #endregion + } +} diff --git a/MCTG/DataPersistence/data/data.json b/MCTG/DataPersistence/data/data.json new file mode 100644 index 0000000..8d25dfd --- /dev/null +++ b/MCTG/DataPersistence/data/data.json @@ -0,0 +1,168 @@ +[ + { + "Key": "Recipe", + "Value": [ + { + "__type": "recipe:#Model", + "id": 26700, + "preparation-steps": [ + { + "description": "Faire cuire.", + "order": 1 + }, + { + "description": "Manger.", + "order": 2 + } + ], + "title": "Cookies classiques" + }, + { + "__type": "recipe:#Model", + "id": 16433, + "preparation-steps": [ + { + "description": "Moulinez la pâte.", + "order": 1 + }, + { + "description": "Faire cuire pendant une bonne heure.", + "order": 2 + }, + { + "description": "Sortir du four et mettre dans un plat.", + "order": 3 + } + ], + "title": "Cookies au chocolat" + }, + { + "__type": "recipe:#Model", + "id": 26093, + "preparation-steps": [ + { + "description": "Achetez les ingrédients.", + "order": 1 + }, + { + "description": "Préparez le matériel. Ustensiles et tout.", + "order": 2 + }, + { + "description": "Pleurez.", + "order": 3 + } + ], + "title": "Gateau nature" + }, + { + "__type": "recipe:#Model", + "id": 21481, + "preparation-steps": [ + { + "description": "Achetez les légumes.", + "order": 1 + }, + { + "description": "Préparez le plat. Ustensiles et préchauffez le four.", + "order": 2 + }, + { + "description": "Coupez les pommes en morceaux et disposez-les sur le plat.", + "order": 3 + }, + { + "description": "Mettez enfin le plat au four, puis une fois cuit, dégustez !", + "order": 4 + } + ], + "title": "Gateau au pommes" + }, + { + "__type": "recipe:#Model", + "id": 15049, + "preparation-steps": [ + { + "description": "Ajouter les oeufs.", + "order": 1 + }, + { + "description": "Ajouter la farine.", + "order": 2 + }, + { + "description": "Ajouter 100g de chocolat fondu.", + "order": 3 + }, + { + "description": "Mélanger le tout.", + "order": 4 + }, + { + "description": "Faire cuire 45h au four traditionnel.", + "order": 5 + } + ], + "title": "Gateau au chocolat" + }, + { + "__type": "recipe:#Model", + "id": 28153, + "preparation-steps": [ + { + "description": "Faire une cuisson bien sec de la dinde à la poêle", + "order": 1 + }, + { + "description": "Mettre la dinde au frigo.", + "order": 2 + }, + { + "description": "Mettre le jambon dans le micro-onde.", + "order": 3 + }, + { + "description": "Faire chauffer 3min.", + "order": 4 + }, + { + "description": "Présentez sur un plat la dinde et le jambon : Miam !", + "order": 5 + } + ], + "title": "Dinde au jambon" + }, + { + "__type": "recipe:#Model", + "id": 8053, + "preparation-steps": [ + { + "description": "Trouvez des épices de curry.", + "order": 1 + }, + { + "description": "Trouvez maintenant du poulet.", + "order": 2 + }, + { + "description": "Coupez la tête du poulet et posez-la dans un plat.", + "order": 3 + }, + { + "description": "Parsemez d'épices curry la tête de la poule.", + "order": 4 + }, + { + "description": "Mettre le tout au four traditionnel 30min.", + "order": 5 + }, + { + "description": "Dégustez en famille !", + "order": 6 + } + ], + "title": "Poulet au curry" + } + ] + } +] \ No newline at end of file diff --git a/MCTG/DataPersistence/data/data.xml b/MCTG/DataPersistence/data/data.xml new file mode 100644 index 0000000..bc21b40 --- /dev/null +++ b/MCTG/DataPersistence/data/data.xml @@ -0,0 +1,184 @@ + + + + Recipe + + + 9062 + + + Faire cuire. + 1 + + + Manger. + 2 + + + Cookies classiques + + + 27627 + + + Moulinez la pâte. + 1 + + + Faire cuire pendant une bonne heure. + 2 + + + Sortir du four et mettre dans un plat. + 3 + + + Cookies au chocolat + + + 8517 + + + Achetez les ingrédients. + 1 + + + Préparez le matériel. Ustensiles et tout. + 2 + + + Pleurez. + 3 + + + Gateau nature + + + 6161 + + + Achetez les légumes. + 1 + + + Préparez le plat. Ustensiles et préchauffez le four. + 2 + + + Coupez les pommes en morceaux et disposez-les sur le plat. + 3 + + + Mettez enfin le plat au four, puis une fois cuit, dégustez ! + 4 + + + Gateau au pommes + + + 17869 + + + Ajouter les oeufs. + 1 + + + Ajouter la farine. + 2 + + + Ajouter 100g de chocolat fondu. + 3 + + + Mélanger le tout. + 4 + + + Faire cuire 45h au four traditionnel. + 5 + + + Gateau au chocolat + + + 4810 + + + Faire une cuisson bien sec de la dinde à la poêle + 1 + + + Mettre la dinde au frigo. + 2 + + + Mettre le jambon dans le micro-onde. + 3 + + + Faire chauffer 3min. + 4 + + + Présentez sur un plat la dinde et le jambon : Miam ! + 5 + + + Dinde au jambon + + + 13570 + + + Trouvez des épices de curry. + 1 + + + Trouvez maintenant du poulet. + 2 + + + Coupez la tête du poulet et posez-la dans un plat. + 3 + + + Parsemez d'épices curry la tête de la poule. + 4 + + + Mettre le tout au four traditionnel 30min. + 5 + + + Dégustez en famille ! + 6 + + + Poulet au curry + + + 26918 + + + Achetez les ingrédients. + 1 + + + Préparez le matériel. Ustensiles et tout. + 2 + + + Pleurez. + 3 + + + Aprenez de vos echecs. + 4 + + + Gateau nature v2 + + + + \ No newline at end of file diff --git a/MCTG/Model/Managers/DataManager.cs b/MCTG/Model/Managers/DataManager.cs deleted file mode 100644 index 02768d1..0000000 --- a/MCTG/Model/Managers/DataManager.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Model -{ - /// - /// Manager of the model. Here is stoked all the recipes, the users, etc... - /// - public class DataManager - { - /// - /// A collection of all the recipe loaded in the app. - /// - public RecipeCollection AllRecipes { get; protected set; } - - /// - /// The constructor of the manager. - /// - public DataManager() - { - AllRecipes = new RecipeCollection(description: "All Recipes"); - } - - /// - /// The constructor of the manager. - /// - /// A list of loaded recipes - public DataManager(RecipeCollection allRecipes) - { - AllRecipes = new RecipeCollection( - description: "All Recipes", - recipes: allRecipes.ToArray()); - } - } -} diff --git a/MCTG/Model/Recipes/PreparationStep.cs b/MCTG/Model/Recipes/PreparationStep.cs index 95d15ca..f9d5aa3 100644 --- a/MCTG/Model/Recipes/PreparationStep.cs +++ b/MCTG/Model/Recipes/PreparationStep.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; @@ -9,6 +10,7 @@ namespace Model /// /// Define a step of the preparation of a recipe. /// + [DataContract(Name = "preparation-step")] public class PreparationStep : IEquatable { #region Attributes @@ -19,12 +21,14 @@ namespace Model /// /// The order of this step in the preparation of the meal. /// + [DataMember(Name = "order")] public int Order { get; init; } /// /// The description of the task the user need to do for this step of the preparation.
/// Set to "No description." when the value passed is null, empty or contain white spaces. ///
+ [DataMember(Name = "description")] public string Description { get => _description; diff --git a/MCTG/Model/Recipes/Recipe.cs b/MCTG/Model/Recipes/Recipe.cs index 6048fdf..fa80231 100644 --- a/MCTG/Model/Recipes/Recipe.cs +++ b/MCTG/Model/Recipes/Recipe.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Runtime.CompilerServices; +using System.Runtime.Serialization; using System.Security.Cryptography; using System.Text; @@ -9,9 +10,11 @@ namespace Model /// /// Define a Recipe for the preparation of a meal. /// + [DataContract(Name = "recipe")] public class Recipe : IEquatable { #region Attributes + [DataMember(Name = "title")] private string _title = ""; #endregion @@ -19,6 +22,7 @@ namespace Model /// /// The ID of the recipe - allows you to compare and/or get this item in an easier way. /// + [DataMember(Name = "id")] public int Id { get; init; } /// @@ -40,6 +44,7 @@ namespace Model /// /// The steps of the preparation. See: . /// + [DataMember(Name = "preparation-steps")] public List PreparationSteps { get; set; } #endregion diff --git a/MCTG/SAE-2.01.sln b/MCTG/SAE-2.01.sln index 10c3e93..ef7d0e6 100644 --- a/MCTG/SAE-2.01.sln +++ b/MCTG/SAE-2.01.sln @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model_UnitTests", "Tests\Mo EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{08B80CE8-A01D-4D86-8989-AF225D5DA48C}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataPersistence", "DataPersistence\DataPersistence.csproj", "{432F9D12-B1F7-4A79-8720-4971BB10B831}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -37,6 +39,10 @@ Global {45AB746A-194B-4E43-81EB-83B06F35AA33}.Debug|Any CPU.Build.0 = Debug|Any CPU {45AB746A-194B-4E43-81EB-83B06F35AA33}.Release|Any CPU.ActiveCfg = Release|Any CPU {45AB746A-194B-4E43-81EB-83B06F35AA33}.Release|Any CPU.Build.0 = Release|Any CPU + {432F9D12-B1F7-4A79-8720-4971BB10B831}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {432F9D12-B1F7-4A79-8720-4971BB10B831}.Debug|Any CPU.Build.0 = Debug|Any CPU + {432F9D12-B1F7-4A79-8720-4971BB10B831}.Release|Any CPU.ActiveCfg = Release|Any CPU + {432F9D12-B1F7-4A79-8720-4971BB10B831}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj b/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj index 318f712..2a658d9 100644 --- a/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj +++ b/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj @@ -21,5 +21,6 @@ + \ No newline at end of file