Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("API server initializing...");

            config = new XmlDocument();
            config.Load("config.xml");

            var cancel = new CancellationTokenSource();

            var appender = new log4net.Appender.ManagedColoredConsoleAppender();
            appender.Threshold = log4net.Core.Level.All;
            var x = (XmlElement)config.SelectSingleNode("//backend/log4net");
            if (x == null)
            {
                Console.WriteLine("Error: log4net configuration node not found. Check your config.xml");
                Console.ReadKey();
                return;
            }
            XmlConfigurator.Configure(x);

            api = new APIServer();
            auth = new FDOAuthServerCheck();
            iw4m = new Iw4mCheck(auth);
            iw5m = new Iw5mCheck(auth);
            forum = new WebCheck("http://fourdeltaone.net/index.php", 60);
            kmshost = new KmshostCheck();

            auth.TestUsername = config.SelectSingleNode("//backend/auth-username").InnerText;
            auth.TestPassword = config.SelectSingleNode("//backend/auth-password").InnerText;

            BackendName = config.SelectSingleNode("//backend/backend-name").InnerText;

            api.Content.Add("login", auth);
            api.Content.Add("iw4m", iw4m);
            api.Content.Add("iw5m", iw5m);
            api.Content.Add("forum", forum);
            api.Content.Add("kmshost", kmshost);
            api.Content.Add("backend-name", BackendName);
            api.ServerLists.Add("iw4m", iw4m.AccessibleMasterServers[0].ServersListed);
            api.ServerLists.Add("iw5m", iw5m.ListedServers);
            api.StatusIndicators.Add("iw4m", new Iw4mStatusIndicator(ref iw4m));
            api.StatusIndicators.Add("iw5m", new Iw5mStatusIndicator(ref iw5m));
            api.StatusIndicators.Add("login", new LoginStatusIndicator(ref auth));
            api.StatusIndicators.Add("forum", new WebStatusIndicator(ref forum));
            api.StatusIndicators.Add("kmshost", new KmshostStatusIndicator(ref kmshost));

            api.Start();

            Console.WriteLine("API server starting, regular checks are now enabled.");

            while (true)
            {
                var task = Task.Factory.StartNew(() => CheckNow(), cancel.Token);
                Thread.Sleep(30 * 1000);
                task.Wait();
                task.Dispose();
            }
        }
 public Iw5mStatusIndicator(ref Iw5mCheck iw5m)
 {
     this.iw5m = iw5m;
 }