using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Transactions; using BlueWest.Collections; using BlueWest.Data; using PerformanceSolution.Tools; namespace PerformanceSolution.Data { public static class MemoryData { public static UserList UserList = new UserList(new FastDictionary()); private const string SavePathName = "userData"; private static bool DEBUG = true; static MemoryData() { if (DEBUG) { UserList = GenerateMockData(); //SaveUserList(); } //LoadUsers(); } public static void SaveUserList(UserList userList) { //UserList = userList; //SaveLoadManager.Save(UserList, SavePathName); } public static void LoadUsers() { UserList = SaveLoadManager.Load(SavePathName); UserList ??= new UserList(new FastDictionary()); } public static DataQueryResult GetTransactionById(int userId, int transactionId) => UserList.GetTransactionById(userId, transactionId); private static void SaveUserList() => SaveUserList(UserList); public static User AddOrModifyUser(UserUpdateDto userUpdateDto, int userId = -1) { return UserList.AddUser(userId, userUpdateDto); } private static UserList GenerateMockData() { var transactions = new FastDictionary(); var financeTransaction = new FinanceTransaction(0, 1, FinanceTransactionType.Buy, FinanceSymbol.BTC_EUR, 0, 0, 0.1, DateTime.Now); transactions.Add(1, financeTransaction); var u = new User(1, "Rui Sousa", "Sagres", "NOADD", "NOADD", 0, 0, transactions); var list = new FastDictionary(10); list.Add(0, u); return new UserList(list); } public static DataQueryResult GetUserById(int userId) { return UserList.GetUserById(userId); } public static ImmutableArray GetUserTransactions(int userId) { return UserList.GetUserTransactions(userId); } } }