/// <summary> /// Create a new <see cref="AvatarAccount"/> instance. /// </summary> internal static AvatarAccount CreatePartyAccount(LogicLong homeId) { AvatarAccount avatarAccount = new AvatarAccount(homeId); AvatarAccountManager._accounts.Add(homeId, avatarAccount); DatabaseManager.Insert(0, homeId, LogicJSONParser.CreateJSONString(avatarAccount.Save())); return(avatarAccount); }
/// <summary> /// Loads all accounts from database. /// </summary> internal static void LoadAccounts() { for (int i = 0; i < DatabaseManager.GetDatabaseCount(0); i++) { CouchbaseDatabase database = DatabaseManager.GetDatabaseAt(0, i); if (database != null) { int highId = i; int maxLowId = database.GetHigherId(); object locker = new object(); Parallel.For(1, maxLowId + 1, new ParallelOptions { MaxDegreeOfParallelism = 4 }, id => { if (NetManager.GetDocumentOwnerId(ServiceCore.ServiceNodeType, id) == ServiceCore.ServiceNodeId) { string json = database.GetDocument(new LogicLong(highId, id)); if (json != null) { AvatarAccount avatarAccount = new AvatarAccount(); avatarAccount.Load(json); lock (locker) { AvatarAccountManager._accounts.Add(avatarAccount.Id, avatarAccount); } } } }); } else { Logging.Warning("AvatarAccountManager::loadAccounts pDatabase->NULL"); } } }
/// <summary> /// Tries to get the instance of the specified <see cref="AvatarAccount"/> id. /// </summary> internal static bool TryGet(LogicLong accountId, out AvatarAccount home) { return(AvatarAccountManager._accounts.TryGetValue(accountId, out home)); }