using APT.Infrastructure.Core;
using APT.BaseData.Domain.IServices.EX;
using System;
using APT.BaseData.Domain.IServices.Platform;
using APT.BaseData.Services.Services.EX;
using APT.Infrastructure.Api;
using System.Collections.Generic;

namespace APT.PF.WebApi.Utils
{
    public static class WebSokectHelper
    {
        public static List<WebSocketClientInfo> WebSocketClientInfos = new List<WebSocketClientInfo>();
        public static void Init()
        {

            //var webSocketService = APT.Infrastructure.Api.ServiceLocator.Instance.GetService<IWebSocketService>();
            //var versionService = APT.Infrastructure.Api.ServiceLocator.Instance.GetService<IPFLastVersionService>();
            var webSocketPort = LibUtils.ToInt(
                ConfigurationManager.AppSettings["WebSocketPort"]);
            try
            {
                WebSocketServiceHelper.InitService(webSocketPort,
                    (clientInfo) =>
                    {
                        return WebSocketService.OnOpenWebSocket(clientInfo, WebSocketClientInfos);
                    },
                    (clientInfo, requestInfo) =>
                    {
                        return WebSocketService.OnMessageWebSocket(clientInfo, requestInfo, WebSocketClientInfos);
                    },
                    (userId, clientInfo) =>
                    {
                        WebSocketService.OnCloseWebSocket(userId, clientInfo, WebSocketClientInfos);
                    });
            }
            catch (Exception ex)
            {
                LoggerManager.GetLogger("Application").Error("WebSocket初始化错误：" + ex.Message);
            }
        }
    }
}