﻿using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;

namespace Panza
{
    class MainClass
    {
        private static bool _keepRunning = true;

        public static void Main(string[] args)
        {
            MongoService ms = new MongoService();
            WebApiService ws = new WebApiService();

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
            {
                _keepRunning = false;
            };

            ms.OnServiceStart += delegate(object msSender)
            {
                    Console.WriteLine("MongoDB has started.");
            };

            ws.OnServiceStart += delegate(object wsSender)
            {
                    Console.WriteLine("Panza service has started.");
                Console.WriteLine("\nHit control-c to exit.");
            };

            Task.Factory.StartNew(new Action(ms.Start));
            Thread.Sleep(500);
            Task.Factory.StartNew(new Action(ws.Start));

            while (_keepRunning)
            {
                Thread.Sleep(500);
            }

            ws.Stop();
            ms.Stop();
        }
    }
}
