internal void DeadSockets() { Timer Timer = new Timer { Interval = 30000, AutoReset = true }; Timer.Elapsed += (_Sender, _Args) => { List <Device> DeadSockets = new List <Device>(); #if DEBUG Loggers.Log(Utils.Padding(this.GetType().Name, 6) + " : DeadSocket executed at " + DateTime.Now.ToString("T") + ".", true); #endif foreach (Device Device in Devices._Devices.Values.ToList()) { //if (!Device.Connected()) { DeadSockets.Add(Device); } } #if DEBUG Loggers.Log( Utils.Padding(this.GetType().Name, 6) + " : Added " + DeadSockets.Count + " devices to DeadSockets list.", true); #endif foreach (Device Device in DeadSockets) { Devices.Remove(Device.SocketHandle); } #if DEBUG Loggers.Log( Utils.Padding(this.GetType().Name, 6) + " : DeadSocket finished at " + DateTime.Now.ToString("T") + ".", true); #endif }; this.LTimers.Add(2, Timer); }
internal void KeepAlive() { Timer Timer = new Timer { Interval = 60000, AutoReset = true }; Timer.Elapsed += (_Sender, _Args) => { var numDisc = 0; #if DEBUG Loggers.Log( Utils.Padding(this.GetType().Name, 6) + " : KeepAlive executed at " + DateTime.Now.ToString("T") + ".", true); #endif foreach (Device Device in Devices._Devices.Values.ToList()) { if (DateTime.Now > Device.NextKeepAlive) { Devices.Remove(Device.SocketHandle); numDisc++; } } #if DEBUG if (numDisc > 0) { Loggers.Log( Utils.Padding(this.GetType().Name, 6) + $" : KeepAlive dropped {numDisc} clients due to keep alive timeouts at " + DateTime.Now.ToString("T") + ".", true); } #endif Loggers.Log("#" + DateTime.Now.ToString("d") + " ---- Pools ---- " + DateTime.Now.ToString("T") + " #", true); Loggers.Log($"SocketAsyncEventArgs: created -> {Gateway.NumberOfArgsCreated} in-use -> {Gateway.NumberOfArgsInUse} available -> {Gateway.NumberOfArgs}.", true); Loggers.Log($"Buffers: created -> {Gateway.NumberOfBuffersCreated} in-use -> {Gateway.NumberOfBuffersInUse} available -> {Gateway.NumberOfBuffers}.", true); }; this.LTimers.Add(2, Timer); }
internal void Save(Battle _Battle) { try { using (MysqlEntities Database = new MysqlEntities()) { Database.Configuration.AutoDetectChangesEnabled = false; Database.Configuration.ValidateOnSaveEnabled = false; var Data = Database.Battle.Find(_Battle.Battle_ID); if (Data != null) { Data.Data = JsonConvert.SerializeObject(_Battle, this.Settings); Database.Entry(Data).State = EntityState.Modified; } Database.SaveChanges(); } } catch (DbEntityValidationException ex) { Loggers.Log( ex + $" Exception while trying to save a battle {_Battle.Battle_ID} to the database. Check error for more information."); foreach (var entry in ex.EntityValidationErrors) { foreach (var errs in entry.ValidationErrors) { Loggers.Log($"{errs.PropertyName}:{errs.ErrorMessage}"); } } throw; } catch (Exception ex) { Loggers.Log(ex + $" Exception while trying to save a battle {_Battle.Battle_ID} to the database."); throw; } }
internal void Save() { Timer Timer = new Timer { Interval = TimeSpan.FromMinutes(3).TotalMilliseconds, AutoReset = true }; Timer.Elapsed += async(_Sender, _Args) => { #if DEBUG Loggers.Log( Utils.Padding(this.GetType().Name, 6) + " : Save executed at " + DateTime.Now.ToString("T") + ".", true); #endif try { await Task.WhenAll(Players.Save(), Resources.Clans.Save(), Resources.Battles.Save()).ConfigureAwait(false); } catch (Exception ex) { Exceptions.Log(ex, "[: Failed at " + DateTime.Now.ToString("T") + ']' + Environment.NewLine + ex.StackTrace); Loggers.Log( Utils.Padding(ex.GetType().Name, 15) + " : " + ex.Message + ".[: Failed at " + DateTime.Now.ToString("T") + ']' + Environment.NewLine + ex.StackTrace, true, Defcon.ERROR); return; } #if DEBUG Loggers.Log( Utils.Padding(this.GetType().Name, 6) + " : Save finished at " + DateTime.Now.ToString("T") + ".", true); #endif }; this.LTimers.Add(1, Timer); }