/// <summary> /// Verifica se a permissão informada é um subconjunto da instancia. /// </summary> /// <param name="target"></param> /// <returns></returns> public bool IsSubsetOf(IPermission target) { if (target == null) { return(this.IsEmpty()); } SystemPermission permission = target as SystemPermission; if (permission == null) { throw new ArgumentException(string.Format(Properties.Resources.Argument_WrongType, base.GetType().FullName)); } if (permission.IsUnrestricted()) { return(true); } if (!this.IsUnrestricted() && (((((this._read == null) || this._read.IsSubsetOf(permission._read)) && ((this._write == null) || this._write.IsSubsetOf(permission._write))) && (((this._execute == null) || this._execute.IsSubsetOf(permission._execute)) && ((this._pathDiscovery == null) || this._pathDiscovery.IsSubsetOf(permission._pathDiscovery)))) && ((this._viewAcl == null) || this._viewAcl.IsSubsetOf(permission._viewAcl)))) { if (this._changeAcl != null) { return(this._changeAcl.IsSubsetOf(permission._changeAcl)); } return(true); } return(false); }
/// <summary> /// Recupera a intercessão da instancia com a permissão informada. /// </summary> /// <param name="target"></param> /// <returns></returns> public IPermission Intersect(IPermission target) { if (target == null) { return(null); } SystemPermission permission = target as SystemPermission; if (permission == null) { throw new ArgumentException(string.Format(Properties.Resources.Argument_WrongType, base.GetType().FullName)); } if (this.IsUnrestricted()) { return(target.Copy()); } if (permission.IsUnrestricted()) { return(this.Copy()); } SystemAccess access = (this._read == null) ? null : this._read.Intersect(permission._read); SystemAccess access2 = (this._write == null) ? null : this._write.Intersect(permission._write); SystemAccess access3 = (this._execute == null) ? null : this._execute.Intersect(permission._execute); SystemAccess access4 = (this._pathDiscovery == null) ? null : this._pathDiscovery.Intersect(permission._pathDiscovery); SystemAccess access5 = (this._viewAcl == null) ? null : this._viewAcl.Intersect(permission._viewAcl); SystemAccess access6 = (this._changeAcl == null) ? null : this._changeAcl.Intersect(permission._changeAcl); if (((((access == null) || access.IsEmpty()) && ((access2 == null) || access2.IsEmpty())) && (((access3 == null) || access3.IsEmpty()) && ((access4 == null) || access4.IsEmpty()))) && (((access5 == null) || access5.IsEmpty()) && ((access6 == null) || access6.IsEmpty()))) { return(null); } SystemPermission permission2 = new SystemPermission(PermissionState.None); permission2._unrestricted = false; permission2._read = access; permission2._write = access2; permission2._execute = access3; permission2._pathDiscovery = access4; permission2._viewAcl = access5; permission2._changeAcl = access6; return(permission2); }