using Admin.Core.Common;
using Admin.Core.Socket;
using log4net;
using Microsoft.AspNetCore.Builder;
using System;

namespace Admin.Core.Extensions
{
    public static class TouchSocketMildd
    {
        private static readonly log4net.ILog log = LogManager.GetLogger(typeof(TouchSocketMildd));
        public static void UseTouchSocketMildd(this IApplicationBuilder app, ITouchSocketService touchSocketService)
        {
            if (app == null) throw new ArgumentNullException(nameof(app));

            try
            {
                if (Appsettings.app("Middleware", "TouchSocket", "Enabled").ObjToBool())
                {
                    //服务器
                    touchSocketService.AddTouchSocketAsync();
                   
                }
                else
                {
                    Console.WriteLine("Socket 配置未启用,请启用!");
                }
            }
            catch (Exception e)
            {
                log.Error($"An error was reported when starting the job service.\n{e.Message}");
                //throw;
            }
        }
    }
}