/// <summary> /// 构造方法 /// </summary> /// <param name="parent">隶属的CustomDevice对象</param> public SiemensTagGroupCollection(CustomDevice parent) : base(parent) { if (!(parent is SiemensDevice)) { throw new Exception("parent对象必须是SiemensDevice对象"); } }
/// <summary> /// 构造方法 /// </summary> /// <param name="parent">TagGroup集合隶属的CustomDevice对象</param> public CustomTagGroupCollection(CustomDevice parent) { _parent = parent ?? throw new Exception( "传入的parent对象是null,TagGroupCollection必须依赖于Device对象"); }
/// <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 }
/// <summary> /// 创建一个西门子TagGroup对象 /// </summary> /// <param name="parent">TagGroup对象所依赖的Device对象</param> /// <param name="node">TagGroup对象属性的Xml节点</param> /// <param name="registerHandler">Tag对象注册用事件</param> public override CustomTagGroup CreateProuct( CustomDevice parent, XmlNode node, TagRegisterHandler registerHandler) { if (node.Name.ToUpper() != "TAGGROUP") { return(null); } return(new SiemensTagGroup(parent, node, registerHandler)); }
/// <summary> /// 构造方法 /// </summary> /// <param name="parent">TagGroup对象所依赖的Device对象</param> /// <param name="node">TagGroup对象属性的Xml节点</param> public CustomTagGroup(CustomDevice parent, XmlNode node) { if (node.Name.ToUpper() != "TAGGROUP") { throw new Exception( $"传入的Xml节点不是[TagGroup],当前收到的Xml节点是:[{node.Name}]"); } _parent = parent ?? throw new Exception( "传入的Device对象是null,TagGroup必须依赖于Device对象"); if (node.Attributes["Name"] == null) { throw new Exception("传入的Xml节点没有[Name]属性,请注意大小写"); } Name = node.Attributes["Name"].Value; }
/// <summary> /// 创建一个TagGroup对象 /// </summary> /// <param name="parent">TagGroup对象所依赖的Device对象</param> /// <param name="node">TagGroup对象属性的Xml节点</param> /// <param name="registerHandler">Tag对象注册用事件</param> public abstract CustomTagGroup CreateProuct(CustomDevice parent, XmlNode node, TagRegisterHandler registerHandler);