using Common.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using WcfServices;
using WcfServices.Contract;
using WcfServices.Services;

namespace Server.Service
{
    internal class WcfServiceHost
    {
        public WcfServiceHost()
        {
        }

        internal static void Start(ILog logger)
        {
            if (serviceHost != null)
            {
                serviceHost.Close();
            }

            serviceHost = new ServiceHost(typeof(ISService));
            serviceHost.Open();
            logger.Info($"IS Service has been hosted. Listening at: {serviceHost.BaseAddresses.FirstOrDefault()?.AbsoluteUri}");

        }

        internal static void Stop(ILog logger)
        {
            if (serviceHost != null)
            {
                serviceHost.Close();
            }

            serviceHost = null;
        }

        static ServiceHost serviceHost = null;

    }
}
