Exemplo n.º 1
0
        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 Resources.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)
                {
                    Resources.Gateway.Disconnect(Device.Token.Args);
                }


#if DEBUG
                Loggers.Log(
                    Utils.Padding(this.GetType().Name, 6) + " : DeadSocket finished at " + DateTime.Now.ToString("T") +
                    ".", true);
#endif
            };

            this.LTimers.Add(Timer);
        }
Exemplo n.º 2
0
        internal Classes()
        {
            this.MFactory = new MessageFactory();
            this.CFactory = new CommandFactory();
            this.Loggers  = new Loggers();
            this.CSV      = new CSV();
            this.Home     = new Home();
            switch (Constants.Database)
            {
            case DBMS.Redis:
                throw new UnintentionalCodeFirstException();

            case DBMS.Both:
                this.Redis = new Redis();
                break;
            }
            this.Checker = new Timers();
#if DEBUG
            Console.WriteLine("We loaded " + MessageFactory.Messages.Count + " messages, " + CommandFactory.Commands.Count + " commands, and 0 debug commands.\n");
#endif
            //this.Test = new Test();
        }
Exemplo n.º 3
0
        internal void Save()
        {
            Timer Timer = new Timer
            {
                Interval  = 60000,
                AutoReset = true
            };

            Timer.Elapsed += (_Sender, _Args) =>
            {
#if DEBUG
                Loggers.Log(
                    Utils.Padding(this.GetType().Name, 6) + " : Save executed at " + DateTime.Now.ToString("T") + ".",
                    true);
#endif
                try
                {
                    lock (Resources.Players.Gate)
                    {
                        if (Resources.Players.Count > 0)
                        {
                            List <Level> Players = Resources.Players.Values.ToList();

                            Parallel.ForEach(Players, (_Player) =>
                            {
                                if (_Player != null)
                                {
                                    _Player.Tick();
                                    Resources.Players.Save(_Player);
                                }
                            });
                        }
                    }

                    /* lock (Resources.Clans.Gate)
                     * {
                     *   if (Resources.Clans.Count > 0)
                     *   {
                     *       List<Clan> Clans = Resources.Clans.Values.ToList();
                     *
                     *       foreach (Clan _Clan in Clans)
                     *       {
                     *           if (_Clan != null)
                     *           {
                     *               Resources.Clans.Save(_Clan, Constants.Database);
                     *           }
                     *       }
                     *   }
                     * }*/
                }
                catch (Exception ex)
                {
                    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(Timer);
        }