using System;
using System.ServiceProcess;
using Microsoft.Owin.Hosting;

namespace RaceLapTimer
{
    public partial class RaceLapTimer : ServiceBase
    {
        private IDisposable _webService;
        private readonly string _url = "http://*:8800";

        public RaceLapTimer()
        {
            InitializeComponent();
        }

        public void Start()
        {
            OnStart(null);    
        }

        public void StopService()
        {
            OnStop();
        }

        protected override void OnStart(string[] args)
        {
            _webService = WebApp.Start<Startup>(_url);
            Console.WriteLine("Web Server is running on " + _url);
        }

        protected override void OnStop()
        {
            _webService.Dispose();
        }
    }
}
