using System;
using System.Threading;
using System.ServiceProcess;

using FilterAPI;

using FilterBot.LocalHandlers;
using FilterBot.LocalNetworking;

using FilterBot.LoginHandlers;

using FilterBot.ManagerHandlers;

using FilterBot.ZoneHandlers;

namespace FilterBot
{
    public partial class Service : ServiceBase
    {
        public Service() { }

        protected override void OnStart(String[] Args)
        {
            Program.Auth = new Authentication();
            Program.SQL = new Database(Program.Auth);

            Program.LocalHandlers = new LocalHandlerLoader();
            Program.LocalClient = new LocalClient();

            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            Program.LoginHandlers = new LoginHandlerLoader();

            Program.ManagerHandlers = new ManagerHandlerLoader();

            Program.ZoneHandlers = new ZoneHandlerLoader();

            Program.LoadSHNs();

            for (UInt16 Counter = 0; Counter < 10000; Counter++)
            {
                Program.CreateBot(String.Concat("Bot", Counter.ToString("0000")));

                Thread.Sleep(1000);
            }
        }

        private void CurrentDomain_UnhandledException(Object Sender, UnhandledExceptionEventArgs Args) { Program.SendConsoleText(ConsoleColor.Red, ((Exception)Args.ExceptionObject).ToString()); }

        protected override void OnStop() { }
    }
}
