using System;
using System.Linq;
using System.Timers;
using System.ServiceProcess;
using System.Collections.Generic;
using System.Diagnostics;

namespace ServerFix
{
    public partial class Main : ServiceBase
    {
        public Main()
        {
            InitializeComponent();
        }

        protected override void OnStart(String[] Args)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

            HandleListener Zone1 = new HandleListener();
            Zone1.Bind_IP = Program.Bind_IP;
            Zone1.Bind_Port = 9120;
            Zone1.Connect_IP = Program.Connect_IP;
            Zone1.Connect_Port = 9220;
            Zone1.Start();

            HandleListener Zone2 = new HandleListener();
            Zone2.Bind_IP = Program.Bind_IP;
            Zone2.Bind_Port = 9122;
            Zone2.Connect_IP = Program.Connect_IP;
            Zone2.Connect_Port = 9222;
            Zone2.Start();

            HandleListener Zone3 = new HandleListener();
            Zone3.Bind_IP = Program.Bind_IP;
            Zone3.Bind_Port = 9124;
            Zone3.Connect_IP = Program.Connect_IP;
            Zone3.Connect_Port = 9224;
            Zone3.Start();

            HandleListener Zone4 = new HandleListener();
            Zone4.Bind_IP = Program.Bind_IP;
            Zone4.Bind_Port = 9126;
            Zone4.Connect_IP = Program.Connect_IP;
            Zone4.Connect_Port = 9226;
            Zone4.Start();
        }

        private void CurrentDomain_UnhandledException(Object Sender, UnhandledExceptionEventArgs Args)
        {
            Exception Error = Args.ExceptionObject as Exception;
            Program.System.WriteException(Error.Message);
        }

        protected override void OnStop()
        {
        }
    }
}
