diff --git a/notus/Biblioteque_de_Class/IManager.cs b/notus/Biblioteque_de_Class/IManager.cs index 8b3b056..4da721f 100644 --- a/notus/Biblioteque_de_Class/IManager.cs +++ b/notus/Biblioteque_de_Class/IManager.cs @@ -16,6 +16,25 @@ namespace Biblioteque_de_Class public List LoadUserData(); - //public List LoadNote(); + public List LoadNote(); + + public void SaveNote(Note note); + + public List LoadTheme(); + + public void SaveTheme(Theme theme); + + public List LoadLogo(); + + public void SaveLogo(Logo logo); + + public List LoadTags(); + + public void SaveTags(Tags tag); + + public List LoadNoteImage(); + + public void SaveNoteImage(NoteImage noteImage); + } } diff --git a/notus/Biblioteque_de_Class/Note.cs b/notus/Biblioteque_de_Class/Note.cs index efd1dba..8ab6306 100644 --- a/notus/Biblioteque_de_Class/Note.cs +++ b/notus/Biblioteque_de_Class/Note.cs @@ -9,18 +9,18 @@ namespace Biblioteque_de_Class public class Note { private string name; - private string Name + public string Name { get { return name; } - set { if (value == null) { name = "Unnamed Note"; } else { name = value; } } + private set { if (value == null) { name = "Unnamed Note"; } else { name = value; } } } ///private string Text { get; set; } Attribut pour le texte de la note private string logoPath; - private string LogoPath + public string LogoPath { get { return logoPath; } - set { if (value == null) { logoPath = "PATH TO DEFAULT LOGO"; } else { logoPath = value; } } + private set { if (value == null) { logoPath = "PATH TO DEFAULT LOGO"; } else { logoPath = value; } } } private DateOnly CreationDate { get; } diff --git a/notus/Biblioteque_de_Class/PersistenceManager.cs b/notus/Biblioteque_de_Class/PersistenceManager.cs index 5adffaf..8fd95d2 100644 --- a/notus/Biblioteque_de_Class/PersistenceManager.cs +++ b/notus/Biblioteque_de_Class/PersistenceManager.cs @@ -30,5 +30,44 @@ namespace Biblioteque_de_Class { return persistence.LoadUserData(); } + + public void SaveNote(Note note) + { + persistence.SaveNote(note); + } + + public List LoadNote() + { + return persistence.LoadNote(); + } + + public List LoadLogo() + { + return persistence.LoadLogo(); + } + + public void SaveLogo(Logo logo) + { + persistence.SaveLogo(logo); + } + + public List LoadTags() + { + return persistence.LoadTags(); + } + + public void SaveTags(Tags tag) + { + persistence.SaveTags(tag); + } + + public List LoadNoteImage() + { + return persistence.LoadNoteImage(); + } + public void SaveNoteImage(NoteImage noteImage) + { + persistence.SaveNoteImage(noteImage); + } } } diff --git a/notus/Notus_Console/Program.cs b/notus/Notus_Console/Program.cs index 1f099dc..53574ec 100644 --- a/notus/Notus_Console/Program.cs +++ b/notus/Notus_Console/Program.cs @@ -31,21 +31,23 @@ Database db = new Database(); User u = new User(Upseudo, Umail, Upassword); Note n = new Note(nomNote, logoPath, u); Tags t = new Tags(NomTag, color); +PersistenceManager managerPers = new PersistenceManager(new Stub()); List NewColorList = new List { }; List listCouleurs = new List { }; List _searchedNotes; -List NoteListe; +List NoteListe = managerPers.LoadNote(); List _searchedTags; -List UserListe; // = IManager.LoadUserData(); /// Essai de load via Imanager +List UserListe = managerPers.LoadUserData(); -foreach (User us in UserListe) /// Test du stub +/*foreach (Note no in NoteListe) /// Test du stub { - Console.WriteLine("Coucou"); + Console.WriteLine(no.GetName()); } -return; +return;*/ + int boucle = 0; while (boucle == 0) { diff --git a/notus/Notus_Persistence/Stub.cs b/notus/Notus_Persistence/Stub.cs index 02562d6..bacfd14 100644 --- a/notus/Notus_Persistence/Stub.cs +++ b/notus/Notus_Persistence/Stub.cs @@ -8,13 +8,15 @@ using System.Threading.Tasks; namespace Notus_Persistance { - internal class Stub : IManager + public class Stub : IManager { - void IManager.SaveDatabaseData(Database database) + void errorMess() { - throw new NotImplementedException(); + Console.WriteLine("Pas d'enregistrement de données dans le stub."); + return; } + //Loaders Database IManager.LoadDatabaseData() { Database database = new Database(); @@ -25,12 +27,7 @@ namespace Notus_Persistance return database; } - void IManager.SaveUserData(User user) - { - throw new NotImplementedException(); - } - - List IManager.LoadUserData() + List IManager.LoadUserData() { List users = new List(); users.Add(new User("Nicolas", "leHeros@gmail.com", "Feur")); @@ -40,16 +37,90 @@ namespace Notus_Persistance return users; } - /*List IManager.LoadNote() + List IManager.LoadNote() { - List notes = new List(); - notes.Add(new Note("Note_1", "Logo_1",new User("Liam","Liam@gmail.com","Oui"))); + List notes = new List(); + notes.Add(new Note("Note_1", "Logo_1", new User("Liam", "Liam@gmail.com", "Oui"))); notes.Add(new Note("Note_2", "Logo_3", new User("Liam", "Liam@gmail.com", "Oui"))); notes.Add(new Note("Note_3", "Logo_5", new User("Liam", "Liam@gmail.com", "Oui"))); notes.Add(new Note("Note_4", "Logo_7", new User("Liam", "Liam@gmail.com", "Oui"))); notes.Add(new Note("Note_5", "Logo_9", new User("Liam", "Liam@gmail.com", "Oui"))); return notes; - }*/ + } + + List IManager.LoadTheme() + { + List themes = new List(); + themes.Add(new Theme("Tropiques", new List { })); + themes.Add(new Theme("Savane", new List { })); + themes.Add(new Theme("Nuit", new List { })); + return themes; + } + + List IManager.LoadLogo() + { + List logos = new List(); + logos.Add(new Logo("pinguin", "pinguin.png")); + logos.Add(new Logo("ours", "ours.png")); + logos.Add(new Logo("caddie", "caddie.png")); + logos.Add(new Logo("croix", "croix.png")); + return logos; + } + + List IManager.LoadTags() + { + List tags = new List(); + tags.Add(new Tags("courses", "vert")); + tags.Add(new Tags("urgent", "rouge")); + tags.Add(new Tags("enfants", "bleu")); + return tags; + } + + List IManager.LoadNoteImage() + { + List noteImages = new List(); + noteImages.Add(new NoteImage(1, "soupe.png", "2.4")); + noteImages.Add(new NoteImage(2, "baguette.png", "5.2")); + noteImages.Add(new NoteImage(3, "cailloux.png", "3.10")); + return noteImages; + } + + //Savers + void IManager.SaveNote(Note note) + { + errorMess(); + } + + void IManager.SaveDatabaseData(Database database) + { + errorMess(); + } + + void IManager.SaveUserData(User user) + { + errorMess(); + } + + void IManager.SaveTheme(Theme theme) + { + errorMess(); + } + + void IManager.SaveLogo(Logo logo) + { + errorMess(); + } + + void IManager.SaveTags(Tags tag) + { + errorMess(); + } + + void IManager.SaveNoteImage(NoteImage noteImage) + { + errorMess(); + } + } } diff --git a/notus/Notus_Persistence/ToJSON.cs b/notus/Notus_Persistence/ToJSON.cs index 6233590..64074e0 100644 --- a/notus/Notus_Persistence/ToJSON.cs +++ b/notus/Notus_Persistence/ToJSON.cs @@ -16,8 +16,18 @@ namespace Notus_Persistance { private const string DatabaseDataFilePath = "data.json"; private const string UserDataFilePath = "userdata.json"; + private const string NoteDataFilePath = "notedata.json"; + private const string ThemeDataFilePath = "themedata.json"; + private const string LogoDataFilePath = "logodata.json"; + private const string TagsDataFilePath = "tagsdata.json"; + private const string NoteImageDataFilePath = "noteImagedata.json"; private static DataContractJsonSerializer DatabasejsonSerializer = new DataContractJsonSerializer(typeof(Database)); private static DataContractJsonSerializer UserjsonSerializer = new DataContractJsonSerializer(typeof(User)); + private static DataContractJsonSerializer NotejsonSerializer = new DataContractJsonSerializer(typeof(Note)); + private static DataContractJsonSerializer ThemejsonSerializer = new DataContractJsonSerializer(typeof(Theme)); + private static DataContractJsonSerializer LogojsonSerializer = new DataContractJsonSerializer(typeof(Logo)); + private static DataContractJsonSerializer TagsjsonSerializer = new DataContractJsonSerializer(typeof(Tags)); + private static DataContractJsonSerializer NoteImagejsonSerializer = new DataContractJsonSerializer(typeof(NoteImage)); public void SaveDatabaseData(Database database) { using (FileStream fileStream = File.Create(DatabaseDataFilePath)) @@ -97,5 +107,215 @@ namespace Notus_Persistance throw new FileException("No userfile find"); } } + + List IManager.LoadNote() + { + List notes = new List(); + if (File.Exists(NoteDataFilePath)) + { + Note note; + using (FileStream fileStream = File.OpenRead(UserDataFilePath)) + { + Note? note1 = (Note?)NotejsonSerializer.ReadObject(fileStream); + if (note1 == null) + { + throw new FileException("Failed to load database. The loaded object is null."); + } + else + { + note = note1; + notes.Add(note); + return notes; + } + } + } + else + { + throw new FileException("No notefile find"); + } + } + + public void SaveNote(Note note) + { + using (FileStream fileStream = File.Create(NoteDataFilePath)) + { + using (var writer = JsonReaderWriterFactory.CreateJsonWriter( + fileStream, + System.Text.Encoding.UTF8, + false, + true))//<- this boolean says that we sant indentation + { + NotejsonSerializer.WriteObject(writer, note); + } + } + } + + List IManager.LoadTheme() + { + List themes = new List(); + if (File.Exists(ThemeDataFilePath)) + { + Theme theme; + using (FileStream fileStream = File.OpenRead(UserDataFilePath)) + { + Theme? theme1 = (Theme?)ThemejsonSerializer.ReadObject(fileStream); + if (theme1 == null) + { + throw new FileException("Failed to load database. The loaded object is null."); + } + else + { + theme = theme1; + themes.Add(theme); + return themes; + } + } + } + else + { + throw new FileException("No themefile find"); + } + } + + public void SaveTheme(Theme theme) + { + using (FileStream fileStream = File.Create(ThemeDataFilePath)) + { + using (var writer = JsonReaderWriterFactory.CreateJsonWriter( + fileStream, + System.Text.Encoding.UTF8, + false, + true))//<- this boolean says that we sant indentation + { + ThemejsonSerializer.WriteObject(writer, theme); + } + } + } + + List IManager.LoadLogo() + { + List logos = new List(); + if (File.Exists(LogoDataFilePath)) + { + Logo logo; + using (FileStream fileStream = File.OpenRead(UserDataFilePath)) + { + Logo? logo1 = (Logo?)LogojsonSerializer.ReadObject(fileStream); + if (logo1 == null) + { + throw new FileException("Failed to load database. The loaded object is null."); + } + else + { + logo = logo1; + logos.Add(logo); + return logos; + } + } + } + else + { + throw new FileException("No notefile find"); + } + } + + public void SaveLogo(Logo logo) + { + using (FileStream fileStream = File.Create(LogoDataFilePath)) + { + using (var writer = JsonReaderWriterFactory.CreateJsonWriter( + fileStream, + System.Text.Encoding.UTF8, + false, + true))//<- this boolean says that we sant indentation + { + LogojsonSerializer.WriteObject(writer, logo); + } + } + } + + List IManager.LoadTags() + { + List tags = new List(); + if (File.Exists(TagsDataFilePath)) + { + Tags tag; + using (FileStream fileStream = File.OpenRead(TagsDataFilePath)) + { + Tags? tag1 = (Tags?)TagsjsonSerializer.ReadObject(fileStream); + if (tag1 == null) + { + throw new FileException("Failed to load database. The loaded object is null."); + } + else + { + tag = tag1; + tags.Add(tag); + return tags; + } + } + } + else + { + throw new FileException("No tagfile find"); + } + } + + public void SaveTags(Tags tag) + { + using (FileStream fileStream = File.Create(TagsDataFilePath)) + { + using (var writer = JsonReaderWriterFactory.CreateJsonWriter( + fileStream, + System.Text.Encoding.UTF8, + false, + true))//<- this boolean says that we sant indentation + { + TagsjsonSerializer.WriteObject(writer, tag); + } + } + } + + List IManager.LoadNoteImage() + { + List noteImages = new List(); + if (File.Exists(NoteImageDataFilePath)) + { + NoteImage noteImage; + using (FileStream fileStream = File.OpenRead(NoteImageDataFilePath)) + { + NoteImage? noteImage1 = (NoteImage?)NoteImagejsonSerializer.ReadObject(fileStream); + if (noteImage1 == null) + { + throw new FileException("Failed to load database. The loaded object is null."); + } + else + { + noteImage = noteImage1; + noteImages.Add(noteImage); + return noteImages; + } + } + } + else + { + throw new FileException("No noteImagefile find"); + } + } + + public void SaveNoteImage(NoteImage noteImage) + { + using (FileStream fileStream = File.Create(NoteImageDataFilePath)) + { + using (var writer = JsonReaderWriterFactory.CreateJsonWriter( + fileStream, + System.Text.Encoding.UTF8, + false, + true))//<- this boolean says that we sant indentation + { + NoteImagejsonSerializer.WriteObject(writer, noteImage); + } + } + } } } diff --git a/notus/Notus_Persistence/ToXML.cs b/notus/Notus_Persistence/ToXML.cs index 4303a01..cb2c46d 100644 --- a/notus/Notus_Persistence/ToXML.cs +++ b/notus/Notus_Persistence/ToXML.cs @@ -34,5 +34,52 @@ namespace Notus_Persistance { throw new NotImplementedException(); } + List IManager.LoadNote() + { + throw new NotImplementedException(); + } + + public void SaveNote(Note note) + { + throw new NotImplementedException(); + } + + List IManager.LoadTheme() + { + throw new NotImplementedException(); + } + public void SaveTheme(Theme theme) + { + throw new NotImplementedException(); + } + + List IManager.LoadLogo() + { + throw new NotImplementedException(); + } + public void SaveLogo(Logo logo) + { + throw new NotImplementedException(); + } + + List IManager.LoadTags() + { + throw new NotImplementedException(); + } + + public void SaveTags(Tags tag) + { + throw new NotImplementedException(); + } + + List IManager.LoadNoteImage() + { + throw new NotImplementedException(); + } + + public void SaveNoteImage(NoteImage noteImage) + { + throw new NotImplementedException(); + } } }