コード例 #1
0
        /// <summary>
        /// 获取指定Page页面中控件域上定义的权限点信息列表。如果没有定义则返回空列表
        /// </summary>
        public IList<PermissionPoint> GetPoints(Page page, Func<PermissionPoint, bool> predicate)
        {
            FieldInfo[] fields = page.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            IList<PermissionPoint> points = new List<PermissionPoint>();
            foreach (FieldInfo info in fields)
            {
                if (info.FieldType.IsSubclassOf(typeof(Control)) && info.GetCustomAttributes(typeof(PermissionPointAttribute), false).Length != 0)
                {
                    //在控件字段上定义了PermissionPointAttribute元特性(目前只支持一个)
                    PermissionPointAttribute pattr = (PermissionPointAttribute)info.GetCustomAttributes(typeof(PermissionPointAttribute), false)[0];
                    if (pattr.Action != null)
                    {
                        string[] action;
                        if (pattr.Action.Contains(","))
                        {
                            //解析以逗号分隔的action列表
                            action = pattr.Action.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        }
                        else
                        {
                            //没有逗号,单独一个point action
                            action = new string[1];
                            action[0] = pattr.Action;
                        }

                        foreach (string act in action)
                        {
                            ControlPermissionPoint point;
                            if (pattr.Type != null)
                            {
                                Type t = Type.GetType(pattr.Type);
                                point = (ControlPermissionPoint)t.GetConstructor(new Type[0]).Invoke(new object[0]);
                            }
                            else
                            {
                                point = new ControlPermissionPoint();
                            }
                            point.Name = pattr.Name.Substring(pattr.Name.LastIndexOf('#') + 1);//控件id
                            point.Resource = page.Request.Path;//权限点资源对应所在页面的虚拟路径
                            point.Action = act;//定义的操作
                            point.Control = ASPNetPageCrystalWallSite.FindControlInContainer(page, pattr.Name);//运行时加入控件实例
                            points.Add(point);
                        }
                    }
                }
            }
            if (predicate != null)
            {
                return points.Where(predicate).ToList();
            }
            else
            {
                return points;
            }
        }
コード例 #2
0
 internal ControlEventContextObject(string fullPath, ControlPermissionPoint point, Control control, string eventName)
 {
     this.fullPath = fullPath;
     this.control = control;
     this.eventName = eventName;
     this.point = point;
 }