Example #1
0
        /// <summary>
        /// 初始化控件
        /// </summary>
        private void InitControls()
        {
            var nodes = Document.DocumentNode.DescendantNodes();

            foreach (var node in nodes)
            {
                if (node.NodeType == HtmlNodeType.Element)
                {
                    //节点类型
                    if (node.Name.ToLower().StartsWith(WeControlTagprifix))
                    {
                        //We7控件
                        WeControl control = new WeControl();
                        control.ID      = node.Id;
                        control.TagName = node.Name.Remove(0, 4).Replace('_', '.');//替换

                        if (node.Attributes.Contains("cssclass"))
                        {
                            control.Style = node.Attributes["cssclass"].Value;
                        }
                        //添加
                        if (!Controls.Contains(control))
                        {
                            Controls.Add(control);
                        }
                    }
                    else if (node.Name.ToLower().StartsWith(SubControlTagprfix))
                    {
                        //子模板
                        string subName = node.Name.Remove(0, 4).Replace("_", ".");

                        if (!SubTemplates.Contains(subName))
                        {
                            SubTemplates.Add(subName);
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// When SubTemplates are available return the most suitable amongst them for the entity specified
        /// </summary>
        /// <param name="entity">an entity whose type is used to determine the most suitable ConceptTemplate match</param>
        /// <returns>the most suitable ConceptTemplate match</returns>
        public ConceptTemplate GetSpecificConceptTemplateFor(IPersistEntity entity)
        {
            if (SubTemplates == null)
            {
                return(this);
            }
            // try to use the lowest valid subtemplate
            var currType     = entity.GetType();
            var currTypeName = currType.Name;

            // while stepping up the inheritance tree has not reached the concepTemplate's own applicable scope
            //
            while (!ApplicableIs(currTypeName))
            {
                // look for a matching subtemplate use that
                var firstValidSub = SubTemplates.FirstOrDefault(subTemplate =>
                                                                subTemplate.Rules != null &&
                                                                subTemplate.ApplicableIs(currTypeName)
                                                                );
                // if found, return
                if (firstValidSub != null)
                {
                    // useRules = firstValidSub.Rules;
                    return(firstValidSub);
                }
                // otherwise look one level up
                if (currType.BaseType == null)
                {
                    break;
                }
                currType     = currType.BaseType;
                currTypeName = currType.Name;
            }
            // if nothing then return the top level
            return(this);
        }