You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.5 KiB
75 lines
2.5 KiB
using Model;
|
|
using FakePersistance;
|
|
using DataPersistence;
|
|
using Managers;
|
|
using System.Diagnostics;
|
|
|
|
namespace Views
|
|
{
|
|
public partial class App : Application
|
|
{
|
|
/// <summary>
|
|
/// Master manager - access to the Model.
|
|
/// </summary>
|
|
public MasterManager Master { get; private set; }
|
|
|
|
public App()
|
|
{
|
|
Debug.WriteLine("Hello, World!\n\n");
|
|
|
|
string path = FileSystem.Current.AppDataDirectory; // - path to the save file
|
|
string strategy = "xml"; // - strategy is 'xml' or 'json' (/!\ this is case sensitive)
|
|
|
|
// Initialize the data serializer
|
|
IDataSerializer dataSerializer = (strategy == "xml") ?
|
|
new DataContractXML(path)
|
|
: new DataContractJSON(path);
|
|
|
|
// Initialize the data manager
|
|
IDataManager dataManager = (!File.Exists(Path.Combine(path, $"data.{strategy}"))) ?
|
|
new DataDefaultManager(new Stubs())
|
|
: new DataDefaultManager(dataSerializer);
|
|
|
|
// Initialize the other managers
|
|
IRecipeManager recipeManager = new RecipeDefaultManager(dataManager);
|
|
IPasswordManager passwordManager = new PasswordSHA256Manager();
|
|
IUserManager userManager = new UserDefaultManager(dataManager, passwordManager);
|
|
|
|
// Initialize the master manager
|
|
Master = new MasterManager(dataManager, recipeManager, userManager);
|
|
Master.Setup();
|
|
|
|
// Change the data serializer if the one in place is 'Stubs'
|
|
if (Master.Data.Serializer.GetType() == typeof(Stubs))
|
|
{
|
|
var data = Master.Data.Data;
|
|
dataManager = new DataDefaultManager(dataSerializer, data);
|
|
Master = new MasterManager(dataManager, recipeManager, userManager);
|
|
}
|
|
|
|
// Save data.
|
|
Debug.Write("[ --SAVE-- ]:\t");
|
|
Master.Data.SaveData();
|
|
Debug.WriteLine("Done.");
|
|
|
|
InitializeComponent();
|
|
|
|
UserAppTheme = AppTheme.Light;
|
|
MainPage = new Home();
|
|
//MainPage = new MyPosts();
|
|
}
|
|
|
|
protected override void OnSleep()
|
|
{
|
|
// Save data.
|
|
Debug.Write("[ --SAVE-- ]:\t");
|
|
Master.Data.SaveData();
|
|
|
|
Debug.WriteLine("Done.");
|
|
Debug.WriteLine(FileSystem.Current.AppDataDirectory);
|
|
|
|
base.OnSleep();
|
|
}
|
|
}
|
|
}
|