internal static void Save() { Timer Timer = new Timer { Interval = TimeSpan.FromMinutes(30).TotalMilliseconds, AutoReset = true }; Timer.Elapsed += async(_Sender, _Args) => { #if DEBUG Logger.SayInfo("Save executed at " + DateTime.Now.ToString("T") + "."); #endif try { await Task.WhenAll(DatabaseManager.Save(ResourcesManager.GetInMemoryLevels())).ConfigureAwait(false); } catch (Exception ex) { ExceptionLogger.Log(ex, "[: Failed at " + DateTime.Now.ToString("T") + ']' + Environment.NewLine + ex.StackTrace); return; } #if DEBUG Logger.SayInfo("Save finished at " + DateTime.Now.ToString("T") + "."); #endif }; LTimers.Add(Logic.Enums.Timer.Save, Timer); }
/*public static Alliance GetAlliance(long allianceId) * { * var alliance = default(Alliance); * * // Try to get alliance from memory first then db. * // Could be improved. * if (ResourcesManager.InMemoryAlliancesContain(allianceId)) * return ResourcesManager.GetInMemoryAlliance(allianceId); * * alliance = DatabaseManager.Instance.GetAlliance(allianceId); * * if (alliance != null) * ResourcesManager.AddAllianceInMemory(alliance); * * return alliance; * } * * public static List<Alliance> GetInMemoryAlliances() * { * return ResourcesManager.GetInMemoryAlliances(); * }*/ public static Avatar GetRandomOnlinePlayer() { var levels = ResourcesManager.GetInMemoryLevels(); int index = s_rand.Next(0, levels.Count); return(levels[index]); }