Exemplo n.º 1
0
        /// <summary>
        /// در تركيب ليست ها اولويت به دادن دسترسي است
        /// اين عملگرها قابل جايگذاري هستند يعني اينكه فرقي نميكند ليست اول با دومي اور شود يا ليست دوم با اولي
        /// </summary>
        /// <param name="list"></param>
        public void AND(ResourcePermissionList list)
        {
            if (list.Count != this.Count)
            {
                throw new Exception("ResourcePermissionList.And: ResourcePermissionList should have equal Counts");
            }

            var resourceCodes = this.Keys.ToList();

            foreach (var key in resourceCodes)
            {
                var             item1Permission = this[key];
                var             item2Permission = list[key];
                PermissionsEnum result          = PermissionsEnum.Undecided;

                if (item1Permission == PermissionsEnum.Undecided && item2Permission != PermissionsEnum.Undecided)
                {
                    result = item2Permission;
                }
                if (item2Permission == PermissionsEnum.Undecided && item1Permission != PermissionsEnum.Undecided)
                {
                    result = item1Permission;
                }

                if (result == PermissionsEnum.Undecided)
                {
                    if (item1Permission == PermissionsEnum.DenyForce || item2Permission == PermissionsEnum.DenyForce)
                    {
                        result = PermissionsEnum.DenyForce;
                    }
                }

                if (result == PermissionsEnum.Undecided)
                {
                    if (item1Permission == PermissionsEnum.Deny || item2Permission == PermissionsEnum.Deny)
                    {
                        result = PermissionsEnum.Deny;
                    }
                }

                if (result == PermissionsEnum.Undecided)
                {
                    if (item1Permission == PermissionsEnum.AllowForce || item2Permission == PermissionsEnum.AllowForce)
                    {
                        result = PermissionsEnum.AllowForce;
                    }
                }

                if (result == PermissionsEnum.Undecided)
                {
                    if (item1Permission == PermissionsEnum.Allow || item2Permission == PermissionsEnum.Allow)
                    {
                        result = PermissionsEnum.Allow;
                    }
                }

                if (item1Permission == PermissionsEnum.Undecided || item2Permission == PermissionsEnum.Undecided)
                {
                    throw new Exception("Undecided Items can not be used in And-Or Functions.");
                }

                if (result == PermissionsEnum.Undecided)
                {
                    throw new Exception("Error in calculating AND list. Undecided result happened");
                }

                this[key] = result;
            }
        }
Exemplo n.º 2
0
 public ResourcePermissions(ResourcePermissionList permissionList, string userName)
 {
     this.PermissionList = permissionList;
     this.UserName       = userName;
 }
Exemplo n.º 3
0
        /// <summary>
        /// در تركيب ليست ها اولويت به دادن دسترسي است
        /// در اينجا ليست دومي كه وارد ميشود مهمتر است و دسترسي هاي آن اولويت خواهند داشت
        /// </summary>
        /// <param name="list"></param>
        public void OR_Force(ResourcePermissionList list)
        {
            if (list.Count != this.Count)
            {
                throw new Exception("ResourcePermissionList.OR: ResourcePermissionList should have equal Counts");
            }

            var resourceCodes = this.Keys.ToList();

            foreach (var key in resourceCodes)
            {
                var             item1Permission = this[key];
                var             item2Permission = list[key];
                PermissionsEnum result          = PermissionsEnum.Undecided;

                if (item1Permission == PermissionsEnum.Undecided && item2Permission != PermissionsEnum.Undecided)
                {
                    result = item2Permission;
                }
                if (item2Permission == PermissionsEnum.Undecided && item1Permission != PermissionsEnum.Undecided)
                {
                    result = item1Permission;
                }

                if (result == PermissionsEnum.Undecided)
                {
                    if (item2Permission == PermissionsEnum.AllowForce)
                    {
                        result = PermissionsEnum.AllowForce;
                    }
                }

                if (result == PermissionsEnum.Undecided)
                {
                    if (item2Permission == PermissionsEnum.DenyForce)
                    {
                        result = PermissionsEnum.DenyForce;
                    }
                }

                if (result == PermissionsEnum.Undecided)
                {
                    if (item2Permission == PermissionsEnum.Allow)
                    {
                        result = PermissionsEnum.Allow;
                    }
                }

                if (result == PermissionsEnum.Undecided)
                {
                    if (item1Permission == PermissionsEnum.Deny)
                    {
                        result = PermissionsEnum.Deny;
                    }
                }

                if (result == PermissionsEnum.Undecided)
                {
                    throw new Exception("Error in calculating OR list. Undecided result happened");
                }

                this[key] = result;
            }
        }