using parkMonitor.entity;
using parkMonitor.model;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using parkMonitor.LOG;
using parkMonitor.server.WebThread;
using System.Windows;

namespace parkMonitor.server.CoreThread {
	/// <summary></summary>
	public class CoreThread : IEquipments ,ICoreThreadDoWorking{
		public static CoreThread ins = new CoreThread();
        string[] equipNames = new string[] { EquipmentName.PLC, EquipmentName.NumMachine, EquipmentName.Web,EquipmentName.Queue };

        public void Start() {

			for(int i = 0; i < equipNames.Length; ++i) {
				IEquipments equip = EquipmentSimpleFactory.ins.CreateEquipment(equipNames[i]);
				if(equip != null) {
					equip.Start();
				}
			}

      
            
            //监听总状态改变消息
			//由监控线程发出
			AsyncCmdServer.ins.listen(AsyncCmdType.TotalStatusChanged, (AlarmStatus type) => {
				if(type != AlarmStatus.Normal) {
					hangUp();
				}
			});

		}

        public void BeginWorking()
        {
            //Func<AbstractMessage> func1 = new Func<AbstractMessage>(GetNumberPlateFromWeb);

            //MessageBox.Show(func1.ToString());

        }



        #region MyRegion
        public AbstractMessage GetMessage()
        {
            return null;
        }

        public void SetMessage(AbstractMessage message)
        {

        }
        
        #endregion
      

        public void Stop() {
            for (int i = 0; i < equipNames.Length; ++i)
            {
                IEquipments equip = EquipmentSimpleFactory.ins.FindEquipment(equipNames[i]);
                if (equip != null)
                {
                    equip.Stop();
                }
            }
        }

		/// <summary>挂起</summary>
		public void hangUp() {

		}

        private AbstractMessage GetNumberPlateFromWeb()
        {
            IEquipments equip = EquipmentSimpleFactory.ins.FindEquipment("EquipmentName.Web");
            AbstractMessage message = equip.GetMessage();
            return message;

        }

	}
}
