|
|
|
@ -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<Note> IManager.LoadNote()
|
|
|
|
|
{
|
|
|
|
|
List<Note> notes = new List<Note>();
|
|
|
|
|
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<Theme> IManager.LoadTheme()
|
|
|
|
|
{
|
|
|
|
|
List<Theme> themes = new List<Theme>();
|
|
|
|
|
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<Logo> IManager.LoadLogo()
|
|
|
|
|
{
|
|
|
|
|
List<Logo> logos = new List<Logo>();
|
|
|
|
|
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<Tags> IManager.LoadTags()
|
|
|
|
|
{
|
|
|
|
|
List<Tags> tags = new List<Tags>();
|
|
|
|
|
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<NoteImage> IManager.LoadNoteImage()
|
|
|
|
|
{
|
|
|
|
|
List<NoteImage> noteImages = new List<NoteImage>();
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|