/// <summary> /// 构造方法 /// </summary> /// <param name="parent">TagGroup对象</param> /// <param name="node">SubTagGroup属性的Xml节点</param> /// <param name="eventTagRegister">西门子Tag注册委托</param> public SiemensSubTagGroup( CustomTagGroup parent, XmlNode node, TagRegisterHandler eventTagRegister) : base(parent, node) { _tagRegisterInParentHandler = eventTagRegister; _log = Logger.Get <SiemensSubTagGroup>(); _tags = new SiemensTagCollection(this, OnTagInGroupRegister); if (!(parent is SiemensTagGroup)) { throw new Exception("parent对象必须是SiemensTagGroup对象"); } _log.Trace($"创建[SubTagGroup={Prefix}]"); XmlNode childNode = node.FirstChild; while (childNode != null) { SiemensTagCreator creator = new SiemensTagCreator(); CustomTag tag = creator.CreateProduct(this, childNode); if (tag != null) { _tags.Add(tag); } childNode = childNode.NextSibling; } }
/// <summary> /// 构造方法 /// </summary> /// <param name="parent">TagGroup对象所依赖的Device对象</param> /// <param name="node">TagGroup对象属性的Xml节点</param> /// <param name="eventTagRegister">西门子Tag注册委托</param> public SiemensTagGroup( CustomDevice parent, XmlNode node, TagRegisterHandler eventTagRegister) : base(parent, node) { if (!(parent is SiemensDevice)) { throw new Exception("parent对象必须是SiemensDevice对象"); } if (node.Name.ToUpper() != "TAGGROUP") { throw new Exception($"Xml节点[{node.Name}]不是\"TagGroup\""); } _tagRegisterInParentHandler = eventTagRegister; _log = Logger.Get <SiemensTagGroup>(); _tags = new SiemensTagCollection(this, OnTagInGroupRegister); _groups = new SiemensSubTagGroupCollection(this); _log.Trace($"创建TagGroup[{Name}]"); #region 创建Tag if (node.HasChildNodes) { SiemensTagCreator creator = new SiemensTagCreator(); XmlNode childNode = node.FirstChild; while (childNode != null) { string nodeName = childNode.Name.ToUpper(); switch (nodeName) { case "TAG": CustomTag tag = creator.CreateProduct(this, childNode); if (tag != null) { _tags.Add(tag); } break; case "SUBTAGGROUP": SiemensSubTagGroup subTagGroup = new SiemensSubTagGroup( this, childNode, OnTagInGroupRegister); if (subTagGroup != null) { _groups.Add(subTagGroup); } break; } childNode = childNode.NextSibling; } } #endregion }