using Aitex.Core.RT.IOCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;

namespace MECF.Framework.Simulator.Core
{
    public class SimulatorIoDO_DI : SimulatorIoValve
    {
        public SimulatorIoDO_DI(string module, XmlElement node, string ioModule) : base(module, node, ioModule)
        {

        }

        /// <summary>
        /// 根据XML配置创建气阀控制对象
        /// </summary>
        /// <param name="node"></param>
        protected override void InitializeIValve(XmlElement node)
        {
            XmlNodeList valveNodes = node.GetElementsByTagName("DO_DI");
            foreach (XmlElement xmlElement in valveNodes)
            {
                string diName = xmlElement.GetAttribute("di");
                string doName = xmlElement.GetAttribute("do");
                if (!DI_DOList.ContainsKey(diName) && !DI_DOList.ContainsKey(doName))
                    DI_DOList.Add(diName, doName);

                var isDefaultOpen = xmlElement.GetAttribute("doDefault");
                if (!String.IsNullOrWhiteSpace(isDefaultOpen))
                    IO.DO[$"{Module}.{doName}"].Value = Convert.ToBoolean(isDefaultOpen);
            }
        }

    }
}
