|
|
|
@ -9,26 +9,18 @@ using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Text.Json.Serialization;
|
|
|
|
|
|
|
|
|
|
namespace Notus_Persistance
|
|
|
|
|
{
|
|
|
|
|
public class ToJSON : IManager
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
private const string DefaultThemePath = "";
|
|
|
|
|
private const string DefaultLogoPath = "";
|
|
|
|
|
private static readonly DataContractJsonSerializer DatabasejsonSerializer = new(typeof(Database));
|
|
|
|
|
|
|
|
|
|
public void SaveDatabaseData(List<User> UserList, Dictionary<User, List<Theme>> AddedThemeFromUser)
|
|
|
|
|
{
|
|
|
|
|
using (FileStream fileStream = File.Create(DatabaseDataFilePath))
|
|
|
|
|
{
|
|
|
|
@ -38,7 +30,8 @@ namespace Notus_Persistance
|
|
|
|
|
false,
|
|
|
|
|
true))//<- this boolean says that we sant indentation
|
|
|
|
|
{
|
|
|
|
|
DatabasejsonSerializer.WriteObject(writer, database);
|
|
|
|
|
DatabasejsonSerializer.WriteObject(writer, UserList);
|
|
|
|
|
DatabasejsonSerializer.WriteObject(writer, AddedThemeFromUser);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -65,5 +58,50 @@ namespace Notus_Persistance
|
|
|
|
|
throw new FileException("No data file found.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Theme> LoadDefaultTheme()
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(DefaultThemePath))
|
|
|
|
|
{
|
|
|
|
|
using (FileStream fileStream = File.OpenRead(DefaultThemePath))
|
|
|
|
|
{
|
|
|
|
|
List<Theme>? DefaultThemeList = (List<Theme>?)DatabasejsonSerializer.ReadObject(fileStream);
|
|
|
|
|
if (DefaultThemeList == null)
|
|
|
|
|
{
|
|
|
|
|
throw new FileException("Failed to Default Theme. The loaded object is null.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return DefaultThemeList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new FileException("No data file found.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public List<Logo> LoadDefaultLogo()
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(DefaultLogoPath))
|
|
|
|
|
{
|
|
|
|
|
using (FileStream fileStream = File.OpenRead(DefaultLogoPath))
|
|
|
|
|
{
|
|
|
|
|
List<Logo>? DefaultLogoList = (List<Logo>?)DatabasejsonSerializer.ReadObject(fileStream);
|
|
|
|
|
if (DefaultLogoList == null)
|
|
|
|
|
{
|
|
|
|
|
throw new FileException("Failed to Default Logo. The loaded object is null.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return DefaultLogoList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new FileException("No data file found.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|