using parkMonitor.DB;
using parkMonitor.entity;
using parkMonitor.model;
using parkMonitor.server;
using parkMonitor.server.CoreThread;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;

namespace parkMonitor.bll
{
    /// <summary>主业务逻辑</summary>
    public class MainBll
    {
        public void init()
        {
            //中控状态监控服务
            PcStatusServer.ins.start();
            //监控线程
            //PLCMonitorServer.ins.Start();
            var monitorThread = EquipmentSimpleFactory.ins.CreateEquipment(EquipmentName.Monitor);
            if (monitorThread != null)
            {
                monitorThread.Start();
            }
            //核心线程
            var coreThread = EquipmentSimpleFactory.ins.CreateEquipment(EquipmentName.Core);
            if (coreThread != null)
            {
                coreThread.Start();
                Task.Factory.StartNew(() =>
                {
                    (coreThread as ICoreThreadDoWorking).BeginWorking();
                });
            }

            //主窗口关闭事件
            CmdServer.ins.listen(CmdType.MainWinClosed, () =>
            {
                coreThread.Stop();
                monitorThread.Stop();
            });
        }
    }
}
