public async Task <bool> RemoveAlliance(long id) { try { if (!ContainsKey(id)) { return(true); } var alliance = this[id]; alliance.Timer.Stop(); if (Redis.IsConnected) { await Redis.CacheAlliance(alliance); } await AllianceDb.Save(alliance); return(TryRemove(id, out var value)); } catch (Exception exception) { Logger.Log(exception, Enums.LogType.Error); return(false); } }
public async void SaveCallback(object state, ElapsedEventArgs args) { if (Redis.IsConnected) { await Redis.CacheAlliance(this); } await AllianceDb.Save(this); }
/// <summary> /// Saves the specified alliance in the specified database. /// </summary> internal static void Save(Alliance alliance, DBMS database = Settings.Database) { if (alliance != null) { switch (database) { case DBMS.Mongo: { AllianceDb.Save(alliance).GetAwaiter().GetResult(); break; } case DBMS.File: { new FileInfo($"{Directory.GetCurrentDirectory()}/Saves/Alliances/{alliance}.json").WriteAllText(JsonConvert.SerializeObject(alliance, AllianceDb.JsonSettings)); break; } } } }