/// <summary> /// Creates the specified entity. /// </summary> /// <param name="Entity">The entity.</param> /// <param name="Store">Whether it has to be stored.</param> public static async Task <BattleLog> Create(BattleLog Entity = null, bool Store = true) { if (Entity == null) { Entity = new BattleLog(); } Entity.HighId = Battles.HighSeed; Entity.LowId = Interlocked.Increment(ref Battles.LowSeed); await BattleDb.Create(Entity); if (Store) { Battles.Add(Entity); } return(Entity); }
/// <summary> /// Gets the entity using the specified identifiers. /// </summary> /// <param name="HighId">The high identifier.</param> /// <param name="LowId">The low identifier.</param> /// <param name="Store">Whether it has to be stored.</param> public static async Task <BattleLog> Get(int HighId, int LowId, bool Store = true) { Logging.Warning(typeof(Battles), "Get(" + HighId + ", " + LowId + ") has been called."); long BattleId = (long)HighId << 32 | (uint)LowId; BattleDb BattleDb = await BattleDb.Load(HighId, LowId); BattleLog BattleLog = null; if (Battles.Entities.TryGetValue(BattleId, out BattleLog)) { return(BattleLog); } else { if (BattleDb != null) { if (BattleDb.Deserialize(out BattleLog)) { if (Store) { Battles.Add(BattleLog); } return(BattleLog); } else { Logging.Error(typeof(Battles), "BattleDb.Deserialize(out BattleLog) != true at Get(" + HighId + ", " + LowId + ")."); } } else { Logging.Warning(typeof(Battles), "BattleDb == null at Get(HighId, LowId)."); } } return(BattleLog); }
/// <summary> /// Removes the specified entity. /// </summary> /// <param name="Entity">The entity.</param> public static async Task Remove(BattleLog Entity) { await Battles.Save(Entity); }