/// <summary>创建并返回一个权限,该权限是当前权限和指定权限的交集。</summary> /// <returns>一个新权限,它表示当前权限与指定权限的交集。如果交集为空,则此新权限为 null。</returns> /// <param name="target">与当前权限对象相交的权限。它必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。</exception> public override IPermission Intersect(IPermission target) { if (target == null) { return((IPermission)null); } if (!this.VerifyType(target)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } IsolatedStorageFilePermission storageFilePermission1 = (IsolatedStorageFilePermission)target; if (storageFilePermission1.IsUnrestricted()) { return(this.Copy()); } if (this.IsUnrestricted()) { return(target.Copy()); } IsolatedStorageFilePermission storageFilePermission2 = new IsolatedStorageFilePermission(PermissionState.None); storageFilePermission2.m_userQuota = IsolatedStoragePermission.min(this.m_userQuota, storageFilePermission1.m_userQuota); storageFilePermission2.m_machineQuota = IsolatedStoragePermission.min(this.m_machineQuota, storageFilePermission1.m_machineQuota); storageFilePermission2.m_expirationDays = IsolatedStoragePermission.min(this.m_expirationDays, storageFilePermission1.m_expirationDays); storageFilePermission2.m_permanentData = this.m_permanentData && storageFilePermission1.m_permanentData; storageFilePermission2.m_allowed = (IsolatedStorageContainment)IsolatedStoragePermission.min((long)this.m_allowed, (long)storageFilePermission1.m_allowed); if (storageFilePermission2.m_userQuota == 0L && storageFilePermission2.m_machineQuota == 0L && (storageFilePermission2.m_expirationDays == 0L && !storageFilePermission2.m_permanentData) && storageFilePermission2.m_allowed == IsolatedStorageContainment.None) { return((IPermission)null); } return((IPermission)storageFilePermission2); }
public override bool IsSubsetOf(IPermission target) { if (target == null) { return((m_userQuota == 0) && (m_machineQuota == 0) && (m_expirationDays == 0) && (m_permanentData == false) && (m_allowed == IsolatedStorageContainment.None)); } try { IsolatedStorageFilePermission operand = (IsolatedStorageFilePermission)target; if (operand.IsUnrestricted()) { return(true); } return((operand.m_userQuota >= m_userQuota) && (operand.m_machineQuota >= m_machineQuota) && (operand.m_expirationDays >= m_expirationDays) && (operand.m_permanentData || !m_permanentData) && (operand.m_allowed >= m_allowed)); } catch (InvalidCastException) { throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); } }
/// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary> /// <param name="target">A permission to combine with the current permission. It must be of the same type as the current permission. </param> /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. </exception> // Token: 0x0600252E RID: 9518 RVA: 0x0008758C File Offset: 0x0008578C public override IPermission Union(IPermission target) { if (target == null) { return(this.Copy()); } if (!base.VerifyType(target)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } IsolatedStorageFilePermission isolatedStorageFilePermission = (IsolatedStorageFilePermission)target; if (base.IsUnrestricted() || isolatedStorageFilePermission.IsUnrestricted()) { return(new IsolatedStorageFilePermission(PermissionState.Unrestricted)); } return(new IsolatedStorageFilePermission(PermissionState.None) { m_userQuota = IsolatedStoragePermission.max(this.m_userQuota, isolatedStorageFilePermission.m_userQuota), m_machineQuota = IsolatedStoragePermission.max(this.m_machineQuota, isolatedStorageFilePermission.m_machineQuota), m_expirationDays = IsolatedStoragePermission.max(this.m_expirationDays, isolatedStorageFilePermission.m_expirationDays), m_permanentData = (this.m_permanentData || isolatedStorageFilePermission.m_permanentData), m_allowed = (IsolatedStorageContainment)IsolatedStoragePermission.max((long)this.m_allowed, (long)isolatedStorageFilePermission.m_allowed) }); }
public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } if (!base.VerifyType(target)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } IsolatedStorageFilePermission permission = (IsolatedStorageFilePermission)target; if (permission.IsUnrestricted()) { return(this.Copy()); } if (base.IsUnrestricted()) { return(target.Copy()); } IsolatedStorageFilePermission permission2 = new IsolatedStorageFilePermission(PermissionState.None) { m_userQuota = IsolatedStoragePermission.min(base.m_userQuota, permission.m_userQuota), m_machineQuota = IsolatedStoragePermission.min(base.m_machineQuota, permission.m_machineQuota), m_expirationDays = IsolatedStoragePermission.min(base.m_expirationDays, permission.m_expirationDays), m_permanentData = base.m_permanentData && permission.m_permanentData, m_allowed = (IsolatedStorageContainment)((int)IsolatedStoragePermission.min((long)base.m_allowed, (long)permission.m_allowed)) }; if ((((permission2.m_userQuota == 0L) && (permission2.m_machineQuota == 0L)) && ((permission2.m_expirationDays == 0L) && !permission2.m_permanentData)) && (permission2.m_allowed == IsolatedStorageContainment.None)) { return(null); } return(permission2); }
public override IPermission Intersect(IPermission target) { if (target == null) { return null; } if (!base.VerifyType(target)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } IsolatedStorageFilePermission permission = (IsolatedStorageFilePermission) target; if (permission.IsUnrestricted()) { return this.Copy(); } if (base.IsUnrestricted()) { return target.Copy(); } IsolatedStorageFilePermission permission2 = new IsolatedStorageFilePermission(PermissionState.None) { m_userQuota = IsolatedStoragePermission.min(base.m_userQuota, permission.m_userQuota), m_machineQuota = IsolatedStoragePermission.min(base.m_machineQuota, permission.m_machineQuota), m_expirationDays = IsolatedStoragePermission.min(base.m_expirationDays, permission.m_expirationDays), m_permanentData = base.m_permanentData && permission.m_permanentData, m_allowed = (IsolatedStorageContainment) ((int) IsolatedStoragePermission.min((long) base.m_allowed, (long) permission.m_allowed)) }; if ((((permission2.m_userQuota == 0L) && (permission2.m_machineQuota == 0L)) && ((permission2.m_expirationDays == 0L) && !permission2.m_permanentData)) && (permission2.m_allowed == IsolatedStorageContainment.None)) { return null; } return permission2; }
//------------------------------------------------------ // // IPERMISSION IMPLEMENTATION // //------------------------------------------------------ public override IPermission Union(IPermission target) { if (target == null) { return(this.Copy()); } else if (!VerifyType(target)) { throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); } IsolatedStorageFilePermission operand = (IsolatedStorageFilePermission)target; if (this.IsUnrestricted() || operand.IsUnrestricted()) { return(new IsolatedStorageFilePermission(PermissionState.Unrestricted)); } else { IsolatedStorageFilePermission union; union = new IsolatedStorageFilePermission(PermissionState.None); union.m_userQuota = max(m_userQuota, operand.m_userQuota); union.m_machineQuota = max(m_machineQuota, operand.m_machineQuota); union.m_expirationDays = max(m_expirationDays, operand.m_expirationDays); union.m_permanentData = m_permanentData || operand.m_permanentData; union.m_allowed = (IsolatedStorageContainment)max((long)m_allowed, (long)operand.m_allowed); return(union); } }
/// <summary>创建一个权限,该权限是当前权限与指定权限的并集。</summary> /// <returns>一个新权限,它表示当前权限与指定权限的并集。</returns> /// <param name="target">将与当前权限合并的权限。它必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。</exception> public override IPermission Union(IPermission target) { if (target == null) { return(this.Copy()); } if (!this.VerifyType(target)) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } IsolatedStorageFilePermission storageFilePermission1 = (IsolatedStorageFilePermission)target; if (this.IsUnrestricted() || storageFilePermission1.IsUnrestricted()) { return((IPermission) new IsolatedStorageFilePermission(PermissionState.Unrestricted)); } IsolatedStorageFilePermission storageFilePermission2 = new IsolatedStorageFilePermission(PermissionState.None); long num1 = IsolatedStoragePermission.max(this.m_userQuota, storageFilePermission1.m_userQuota); storageFilePermission2.m_userQuota = num1; long num2 = IsolatedStoragePermission.max(this.m_machineQuota, storageFilePermission1.m_machineQuota); storageFilePermission2.m_machineQuota = num2; long num3 = IsolatedStoragePermission.max(this.m_expirationDays, storageFilePermission1.m_expirationDays); storageFilePermission2.m_expirationDays = num3; int num4 = this.m_permanentData ? 1 : (storageFilePermission1.m_permanentData ? 1 : 0); storageFilePermission2.m_permanentData = num4 != 0; int num5 = (int)IsolatedStoragePermission.max((long)this.m_allowed, (long)storageFilePermission1.m_allowed); storageFilePermission2.m_allowed = (IsolatedStorageContainment)num5; return((IPermission)storageFilePermission2); }
protected override IStackWalk CreateStackWalk() { IsolatedStorageFilePermission permission = new IsolatedStorageFilePermission(PermissionState.Unrestricted); permission.UsageAllowed = attribute.UsageAllowed; permission.UserQuota = attribute.UsageQuota; return permission; }
//------------------------------------------------------ // // IPERMISSION IMPLEMENTATION // //------------------------------------------------------ public override IPermission Union(IPermission target) { if (target == null) { return this.Copy(); } else if (!VerifyType(target)) { throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); } IsolatedStorageFilePermission operand = (IsolatedStorageFilePermission)target; if (this.IsUnrestricted() || operand.IsUnrestricted()) { return new IsolatedStorageFilePermission( PermissionState.Unrestricted ); } else { IsolatedStorageFilePermission union; union = new IsolatedStorageFilePermission( PermissionState.None ); union.m_userQuota = max(m_userQuota,operand.m_userQuota); union.m_machineQuota = max(m_machineQuota,operand.m_machineQuota); union.m_expirationDays = max(m_expirationDays,operand.m_expirationDays); union.m_permanentData = m_permanentData || operand.m_permanentData; union.m_allowed = (IsolatedStorageContainment)max((long)m_allowed,(long)operand.m_allowed); return union; } }
public override bool IsSubsetOf(IPermission target) { IsolatedStorageFilePermission isfp = Cast(target); if (isfp == null) { return(IsEmpty()); } if (isfp.IsUnrestricted()) { return(true); } if (m_userQuota > isfp.m_userQuota) { return(false); } if (m_machineQuota > isfp.m_machineQuota) { return(false); } if (m_expirationDays > isfp.m_expirationDays) { return(false); } if (m_permanentData != isfp.m_permanentData) { return(false); } if (m_allowed > isfp.m_allowed) { return(false); } return(true); }
/// <summary>Determines whether the current permission is a subset of the specified permission.</summary> /// <param name="target">A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission. </param> /// <returns> /// <see langword="true" /> if the current permission is a subset of the specified permission; otherwise, <see langword="false" />.</returns> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not <see langword="null" /> and is not of the same type as the current permission. </exception> // Token: 0x0600252F RID: 9519 RVA: 0x0008766C File Offset: 0x0008586C public override bool IsSubsetOf(IPermission target) { if (target == null) { return(this.m_userQuota == 0L && this.m_machineQuota == 0L && this.m_expirationDays == 0L && !this.m_permanentData && this.m_allowed == IsolatedStorageContainment.None); } bool result; try { IsolatedStorageFilePermission isolatedStorageFilePermission = (IsolatedStorageFilePermission)target; if (isolatedStorageFilePermission.IsUnrestricted()) { result = true; } else { result = (isolatedStorageFilePermission.m_userQuota >= this.m_userQuota && isolatedStorageFilePermission.m_machineQuota >= this.m_machineQuota && isolatedStorageFilePermission.m_expirationDays >= this.m_expirationDays && (isolatedStorageFilePermission.m_permanentData || !this.m_permanentData) && isolatedStorageFilePermission.m_allowed >= this.m_allowed); } } catch (InvalidCastException) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } return(result); }
/// <summary>Determines whether the current permission is a subset of the specified permission.</summary> /// <returns>true if the current permission is a subset of the specified permission; otherwise, false.</returns> /// <param name="target">A permission that is to be tested for the subset relationship. This permission must be of the same type as the current permission. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception> public override bool IsSubsetOf(IPermission target) { IsolatedStorageFilePermission isolatedStorageFilePermission = this.Cast(target); if (isolatedStorageFilePermission == null) { return(base.IsEmpty()); } return(isolatedStorageFilePermission.IsUnrestricted() || (this.m_userQuota <= isolatedStorageFilePermission.m_userQuota && this.m_machineQuota <= isolatedStorageFilePermission.m_machineQuota && this.m_expirationDays <= isolatedStorageFilePermission.m_expirationDays && this.m_permanentData == isolatedStorageFilePermission.m_permanentData && this.m_allowed <= isolatedStorageFilePermission.m_allowed)); }
// Properties // Methods public override IPermission Copy () { IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None); p.m_userQuota = m_userQuota; p.m_machineQuota = m_machineQuota; p.m_expirationDays = m_expirationDays; p.m_permanentData = m_permanentData; p.m_allowed = m_allowed; return p; }
// Properties // Methods public override IPermission Copy() { IsolatedStorageFilePermission p = new IsolatedStorageFilePermission(PermissionState.None); p.m_userQuota = m_userQuota; p.m_machineQuota = m_machineQuota; p.m_expirationDays = m_expirationDays; p.m_permanentData = m_permanentData; p.m_allowed = m_allowed; return(p); }
// Methods public override IPermission CreatePermission () { IsolatedStorageFilePermission perm = null; if (this.Unrestricted) perm = new IsolatedStorageFilePermission (PermissionState.Unrestricted); else { perm = new IsolatedStorageFilePermission (PermissionState.None); perm.UsageAllowed = this.UsageAllowed; perm.UserQuota = this.UserQuota; } return perm; }
public override IPermission Copy() { IsolatedStorageFilePermission permission = new IsolatedStorageFilePermission(PermissionState.Unrestricted); if (!base.IsUnrestricted()) { permission.m_userQuota = base.m_userQuota; permission.m_machineQuota = base.m_machineQuota; permission.m_expirationDays = base.m_expirationDays; permission.m_permanentData = base.m_permanentData; permission.m_allowed = base.m_allowed; } return permission; }
public override IPermission Copy() { IsolatedStorageFilePermission permission = new IsolatedStorageFilePermission(PermissionState.Unrestricted); if (!base.IsUnrestricted()) { permission.m_userQuota = base.m_userQuota; permission.m_machineQuota = base.m_machineQuota; permission.m_expirationDays = base.m_expirationDays; permission.m_permanentData = base.m_permanentData; permission.m_allowed = base.m_allowed; } return(permission); }
/// <summary>创建并返回当前权限的相同副本。</summary> /// <returns>当前权限的副本。</returns> public override IPermission Copy() { IsolatedStorageFilePermission storageFilePermission = new IsolatedStorageFilePermission(PermissionState.Unrestricted); if (!this.IsUnrestricted()) { storageFilePermission.m_userQuota = this.m_userQuota; storageFilePermission.m_machineQuota = this.m_machineQuota; storageFilePermission.m_expirationDays = this.m_expirationDays; storageFilePermission.m_permanentData = this.m_permanentData; storageFilePermission.m_allowed = this.m_allowed; } return((IPermission)storageFilePermission); }
private IsolatedStorageFilePermission Cast(IPermission target) { if (target == null) { return(null); } IsolatedStorageFilePermission isolatedStorageFilePermission = target as IsolatedStorageFilePermission; if (isolatedStorageFilePermission == null) { CodeAccessPermission.ThrowInvalidPermission(target, typeof(IsolatedStorageFilePermission)); } return(isolatedStorageFilePermission); }
public override IPermission Copy() { IsolatedStorageFilePermission copy; copy = new IsolatedStorageFilePermission(PermissionState.Unrestricted); if (!IsUnrestricted()) { copy.m_userQuota = m_userQuota; copy.m_machineQuota = m_machineQuota; copy.m_expirationDays = m_expirationDays; copy.m_permanentData = m_permanentData; copy.m_allowed = m_allowed; } return(copy); }
// Methods public override IPermission CreatePermission() { IsolatedStorageFilePermission perm = null; if (this.Unrestricted) { perm = new IsolatedStorageFilePermission(PermissionState.Unrestricted); } else { perm = new IsolatedStorageFilePermission(PermissionState.None); perm.UsageAllowed = this.UsageAllowed; perm.UserQuota = this.UserQuota; } return(perm); }
// helpers private IsolatedStorageFilePermission Cast(IPermission target) { if (target == null) { return(null); } IsolatedStorageFilePermission isfp = (target as IsolatedStorageFilePermission); if (isfp == null) { ThrowInvalidPermission(target, typeof(IsolatedStorageFilePermission)); } return(isfp); }
public void PermissionStateUnrestricted () { IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.Unrestricted); Assert.AreEqual (IsolatedStorageContainment.UnrestrictedIsolatedStorage, isfp.UsageAllowed, "UsageAllowed"); Assert.AreEqual (Int64.MaxValue, isfp.UserQuota, "UserQuota"); SecurityElement se = isfp.ToXml (); // only class and version are present Assert.AreEqual ("true", se.Attribute ("Unrestricted"), "Xml-Unrestricted"); Assert.IsNull (se.Children, "Xml-Children"); IsolatedStorageFilePermission copy = (IsolatedStorageFilePermission)isfp.Copy (); Assert.IsFalse (Object.ReferenceEquals (isfp, copy), "ReferenceEquals"); Assert.AreEqual (isfp.UsageAllowed, copy.UsageAllowed, "UsageAllowed"); Assert.AreEqual (isfp.UserQuota, copy.UserQuota, "UserQuota"); }
/// <summary>Creates and returns a new <see cref="T:System.Security.Permissions.IsolatedStorageFilePermission" />.</summary> /// <returns>An <see cref="T:System.Security.Permissions.IsolatedStorageFilePermission" /> that corresponds to this attribute.</returns> public override IPermission CreatePermission() { IsolatedStorageFilePermission isolatedStorageFilePermission; if (base.Unrestricted) { isolatedStorageFilePermission = new IsolatedStorageFilePermission(PermissionState.Unrestricted); } else { isolatedStorageFilePermission = new IsolatedStorageFilePermission(PermissionState.None); isolatedStorageFilePermission.UsageAllowed = base.UsageAllowed; isolatedStorageFilePermission.UserQuota = base.UserQuota; } return(isolatedStorageFilePermission); }
/// <summary>创建并返回一个新的 <see cref="T:System.Security.Permissions.IsolatedStorageFilePermission" />。</summary> /// <returns>与此特性对应的 <see cref="T:System.Security.Permissions.IsolatedStorageFilePermission" />。</returns> public override IPermission CreatePermission() { IsolatedStorageFilePermission storageFilePermission; if (this.m_unrestricted) { storageFilePermission = new IsolatedStorageFilePermission(PermissionState.Unrestricted); } else { storageFilePermission = new IsolatedStorageFilePermission(PermissionState.None); storageFilePermission.UserQuota = this.m_userQuota; storageFilePermission.UsageAllowed = this.m_allowed; } return((IPermission)storageFilePermission); }
public override IPermission Intersect (IPermission target) { IsolatedStorageFilePermission isfp = Cast (target); if (isfp == null) return null; if (IsEmpty () && isfp.IsEmpty ()) return null; IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None); p.m_userQuota = (m_userQuota < isfp.m_userQuota) ? m_userQuota : isfp.m_userQuota; p.m_machineQuota = (m_machineQuota < isfp.m_machineQuota) ? m_machineQuota : isfp.m_machineQuota; p.m_expirationDays = (m_expirationDays < isfp.m_expirationDays) ? m_expirationDays : isfp.m_expirationDays; p.m_permanentData = (m_permanentData && isfp.m_permanentData); // UsageAllowed == Unrestricted is a special case handled by the property p.UsageAllowed = (m_allowed < isfp.m_allowed) ? m_allowed : isfp.m_allowed; return p; }
/// <summary>Creates a permission that is the union of the current permission and the specified permission.</summary> /// <returns>A new permission that represents the union of the current permission and the specified permission.</returns> /// <param name="target">A permission to combine with the current permission. It must be of the same type as the current permission. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception> public override IPermission Union(IPermission target) { IsolatedStorageFilePermission isolatedStorageFilePermission = this.Cast(target); if (isolatedStorageFilePermission == null) { return(this.Copy()); } return(new IsolatedStorageFilePermission(PermissionState.None) { m_userQuota = ((this.m_userQuota <= isolatedStorageFilePermission.m_userQuota) ? isolatedStorageFilePermission.m_userQuota : this.m_userQuota), m_machineQuota = ((this.m_machineQuota <= isolatedStorageFilePermission.m_machineQuota) ? isolatedStorageFilePermission.m_machineQuota : this.m_machineQuota), m_expirationDays = ((this.m_expirationDays <= isolatedStorageFilePermission.m_expirationDays) ? isolatedStorageFilePermission.m_expirationDays : this.m_expirationDays), m_permanentData = (this.m_permanentData || isolatedStorageFilePermission.m_permanentData), UsageAllowed = ((this.m_allowed <= isolatedStorageFilePermission.m_allowed) ? isolatedStorageFilePermission.m_allowed : this.m_allowed) }); }
/// <include file='doc\PermissionAttributes.uex' path='docs/doc[@for="IsolatedStorageFilePermissionAttribute.CreatePermission"]/*' /> public override IPermission CreatePermission() { IsolatedStorageFilePermission p; if (m_unrestricted) { p = new IsolatedStorageFilePermission (PermissionState.Unrestricted); } else { p = new IsolatedStorageFilePermission(PermissionState.None); p.UserQuota = m_userQuota; p.UsageAllowed = m_allowed; } return(p); }
public override IPermission Intersect(IPermission target) { if (target == null) { return(null); } else if (!VerifyType(target)) { throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); } IsolatedStorageFilePermission operand = (IsolatedStorageFilePermission)target; if (operand.IsUnrestricted()) { return(Copy()); } else if (IsUnrestricted()) { return(target.Copy()); } IsolatedStorageFilePermission intersection; intersection = new IsolatedStorageFilePermission(PermissionState.None); intersection.m_userQuota = min(m_userQuota, operand.m_userQuota); intersection.m_machineQuota = min(m_machineQuota, operand.m_machineQuota); intersection.m_expirationDays = min(m_expirationDays, operand.m_expirationDays); intersection.m_permanentData = m_permanentData && operand.m_permanentData; intersection.m_allowed = (IsolatedStorageContainment)min((long)m_allowed, (long)operand.m_allowed); if ((intersection.m_userQuota == 0) && (intersection.m_machineQuota == 0) && (intersection.m_expirationDays == 0) && (intersection.m_permanentData == false) && (intersection.m_allowed == IsolatedStorageContainment.None)) { return(null); } return(intersection); }
public override IPermission Intersect(IPermission target) { // Handle the easy cases first. if (target == null) { return(target); } else if (!(target is IsolatedStorageFilePermission)) { throw new ArgumentException(_("Arg_PermissionMismatch")); } else if (((IsolatedStorageFilePermission)target) .IsUnrestricted()) { return(Copy()); } else if (IsUnrestricted()) { return(target.Copy()); } // Get the minimum quota and containment values. long quota = ((IsolatedStorageFilePermission)target).userQuota; if (quota > userQuota) { quota = userQuota; } IsolatedStorageContainment allowed; allowed = ((IsolatedStorageFilePermission)target).usageAllowed; if (((int)allowed) > ((int)usageAllowed)) { allowed = usageAllowed; } // Create a new object and intersect the lists. IsolatedStorageFilePermission perm; perm = new IsolatedStorageFilePermission(PermissionState.None); perm.userQuota = quota; perm.usageAllowed = allowed; return(perm); }
public override IPermission Union(IPermission target) { IsolatedStorageFilePermission isfp = Cast(target); if (isfp == null) { return(Copy()); } IsolatedStorageFilePermission p = new IsolatedStorageFilePermission(PermissionState.None); p.m_userQuota = (m_userQuota > isfp.m_userQuota) ? m_userQuota : isfp.m_userQuota; p.m_machineQuota = (m_machineQuota > isfp.m_machineQuota) ? m_machineQuota : isfp.m_machineQuota; p.m_expirationDays = (m_expirationDays > isfp.m_expirationDays) ? m_expirationDays : isfp.m_expirationDays; p.m_permanentData = (m_permanentData || isfp.m_permanentData); // UsageAllowed == Unrestricted is a special case handled by the property p.UsageAllowed = (m_allowed > isfp.m_allowed) ? m_allowed : isfp.m_allowed; return(p); }
public void Intersect () { IsolatedStorageFilePermission empty = new IsolatedStorageFilePermission (PermissionState.None); IsolatedStorageFilePermission intersect = (IsolatedStorageFilePermission)empty.Intersect (null); Assert.IsNull (intersect, "empty N null"); intersect = (IsolatedStorageFilePermission)empty.Intersect (empty); Assert.IsNull (intersect, "empty N empty"); IsolatedStorageFilePermission unrestricted = new IsolatedStorageFilePermission (PermissionState.Unrestricted); intersect = (IsolatedStorageFilePermission)unrestricted.Intersect (null); Assert.IsNull (intersect, "unrestricted N null"); intersect = (IsolatedStorageFilePermission)unrestricted.Intersect (empty); Assert.IsNotNull (intersect, "unrestricted N empty"); intersect = (IsolatedStorageFilePermission)unrestricted.Intersect (unrestricted); Assert.IsNotNull (intersect, "unrestricted N unrestricted"); }
/// <summary>Creates and returns a permission that is the intersection of the current permission and the specified permission.</summary> /// <returns>A new permission that represents the intersection of the current permission and the specified permission. This new permission is null if the intersection is empty.</returns> /// <param name="target">A permission to intersect with the current permission object. It must be of the same type as the current permission. </param> /// <exception cref="T:System.ArgumentException">The <paramref name="target" /> parameter is not null and is not of the same type as the current permission. </exception> public override IPermission Intersect(IPermission target) { IsolatedStorageFilePermission isolatedStorageFilePermission = this.Cast(target); if (isolatedStorageFilePermission == null) { return(null); } if (base.IsEmpty() && isolatedStorageFilePermission.IsEmpty()) { return(null); } return(new IsolatedStorageFilePermission(PermissionState.None) { m_userQuota = ((this.m_userQuota >= isolatedStorageFilePermission.m_userQuota) ? isolatedStorageFilePermission.m_userQuota : this.m_userQuota), m_machineQuota = ((this.m_machineQuota >= isolatedStorageFilePermission.m_machineQuota) ? isolatedStorageFilePermission.m_machineQuota : this.m_machineQuota), m_expirationDays = ((this.m_expirationDays >= isolatedStorageFilePermission.m_expirationDays) ? isolatedStorageFilePermission.m_expirationDays : this.m_expirationDays), m_permanentData = (this.m_permanentData && isolatedStorageFilePermission.m_permanentData), UsageAllowed = ((this.m_allowed >= isolatedStorageFilePermission.m_allowed) ? isolatedStorageFilePermission.m_allowed : this.m_allowed) }); }
public override IPermission CreatePermission() { IsolatedStorageFilePermission p; if (m_unrestricted) { p = new IsolatedStorageFilePermission (PermissionState.Unrestricted); } else { p = new IsolatedStorageFilePermission(PermissionState.None); p.UserQuota = m_userQuota; p.UsageAllowed = m_allowed; #if false p.PermanentData = m_permanentData; p.MachineQuota = m_machineQuota; p.ExpirationDays = m_expirationDays; #endif } return(p); }
public override bool IsSubsetOf(IPermission target) { bool flag; if (target == null) { return((((base.m_userQuota == 0L) && (base.m_machineQuota == 0L)) && ((base.m_expirationDays == 0L) && !base.m_permanentData)) && (base.m_allowed == IsolatedStorageContainment.None)); } try { IsolatedStorageFilePermission permission = (IsolatedStorageFilePermission)target; if (permission.IsUnrestricted()) { return(true); } flag = ((((permission.m_userQuota >= base.m_userQuota) && (permission.m_machineQuota >= base.m_machineQuota)) && (permission.m_expirationDays >= base.m_expirationDays)) && (permission.m_permanentData || !base.m_permanentData)) && (permission.m_allowed >= base.m_allowed); } catch (InvalidCastException) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", new object[] { base.GetType().FullName })); } return(flag); }
/// <summary>确定当前权限是否为指定权限的子集。</summary> /// <returns>如果当前权限是指定权限的子集,则为 true;否则为 false。</returns> /// <param name="target">将要测试子集关系的权限。此权限必须与当前权限属于同一类型。</param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="target" /> 参数不是 null,而且与当前权限不是同一类型。</exception> public override bool IsSubsetOf(IPermission target) { if (target == null) { if (this.m_userQuota == 0L && this.m_machineQuota == 0L && (this.m_expirationDays == 0L && !this.m_permanentData)) { return(this.m_allowed == IsolatedStorageContainment.None); } return(false); } try { IsolatedStorageFilePermission storageFilePermission = (IsolatedStorageFilePermission)target; if (storageFilePermission.IsUnrestricted()) { return(true); } return(storageFilePermission.m_userQuota >= this.m_userQuota && storageFilePermission.m_machineQuota >= this.m_machineQuota && storageFilePermission.m_expirationDays >= this.m_expirationDays && (storageFilePermission.m_permanentData || !this.m_permanentData) && storageFilePermission.m_allowed >= this.m_allowed); } catch (InvalidCastException ex) { throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", (object)this.GetType().FullName)); } }
public void FromXml_NoVersion () { IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None); SecurityElement se = isfp.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("class", se.Attribute ("class")); isfp.FromXml (w); }
public void FromXml_NoClass () { IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None); SecurityElement se = isfp.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("version", se.Attribute ("version")); isfp.FromXml (w); // doesn't even care of the class attribute presence }
public void FromXml_WrongVersion () { IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None); SecurityElement se = isfp.ToXml (); se.Attributes.Remove ("version"); se.Attributes.Add ("version", "2"); isfp.FromXml (se); }
public void FromXml_WrongTagCase () { IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None); SecurityElement se = isfp.ToXml (); se.Tag = "IPERMISSION"; // instead of IPermission isfp.FromXml (se); }
public void FromXml_WrongClass () { IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None); SecurityElement se = isfp.ToXml (); SecurityElement w = new SecurityElement (se.Tag); w.AddAttribute ("class", "Wrong" + se.Attribute ("class")); w.AddAttribute ("version", se.Attribute ("version")); isfp.FromXml (w); // doesn't care of the class name at that stage // anyway the class has already be created so... }
private static void DemandAdminPermission() { // Ok if more than one instance is created, no need to sync. if (s_PermAdminUser == null) { s_PermAdminUser = new IsolatedStorageFilePermission( IsolatedStorageContainment.AdministerIsolatedStorageByUser, 0, false); } s_PermAdminUser.Demand(); }
public void FromXml_WrongTag () { IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None); SecurityElement se = isfp.ToXml (); se.Tag = "IMono"; isfp.FromXml (se); }
public void Union_DifferentPermissions () { IsolatedStorageFilePermission a = new IsolatedStorageFilePermission (PermissionState.None); SecurityPermission b = new SecurityPermission (PermissionState.None); a.Union (b); }
public void UsageAllowedQuota () { IsolatedStorageFilePermission empty = new IsolatedStorageFilePermission (PermissionState.None); IsolatedStorageFilePermission small = new IsolatedStorageFilePermission (PermissionState.None); small.UsageAllowed = IsolatedStorageContainment.DomainIsolationByUser; small.UserQuota = 1; IsolatedStorageFilePermission union = (IsolatedStorageFilePermission)empty.Union (small); Assert.AreEqual (IsolatedStorageContainment.DomainIsolationByUser, union.UsageAllowed, "DomainIsolationByUser"); Assert.AreEqual (1, union.UserQuota, "1"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-1"); Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-1a"); Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-1b"); Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-1c"); IsolatedStorageFilePermission intersect = (IsolatedStorageFilePermission)union.Intersect (small); Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-1"); Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-1"); small.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser; small.UserQuota = 2; union = (IsolatedStorageFilePermission)union.Union (small); Assert.AreEqual (IsolatedStorageContainment.AssemblyIsolationByUser, union.UsageAllowed, "AssemblyIsolationByUser"); Assert.AreEqual (2, union.UserQuota, "2"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-2"); Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-2a"); Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-2b"); Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-2c"); intersect = (IsolatedStorageFilePermission)union.Intersect (small); Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-2"); Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-2"); small.UsageAllowed = IsolatedStorageContainment.ApplicationIsolationByUser; small.UserQuota = 3; union = (IsolatedStorageFilePermission)union.Union (small); Assert.AreEqual (IsolatedStorageContainment.AssemblyIsolationByUser, union.UsageAllowed, "ApplicationIsolationByUser"); Assert.AreEqual (3, union.UserQuota, "3"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-3"); Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-3a"); Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-3b"); Assert.IsFalse (union.IsSubsetOf (small), "IsSubset-3c"); intersect = (IsolatedStorageFilePermission)union.Intersect (small); Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-3"); Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-3"); small.UsageAllowed = IsolatedStorageContainment.DomainIsolationByMachine; small.UserQuota = 4; union = (IsolatedStorageFilePermission)union.Union (small); Assert.AreEqual (IsolatedStorageContainment.DomainIsolationByMachine, union.UsageAllowed, "DomainIsolationByMachine"); Assert.AreEqual (4, union.UserQuota, "4"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-4"); Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-4a"); Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-4b"); Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-4c"); intersect = (IsolatedStorageFilePermission)union.Intersect (small); Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-4"); Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-4"); small.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByMachine; small.UserQuota = 5; union = (IsolatedStorageFilePermission)union.Union (small); Assert.AreEqual (IsolatedStorageContainment.AssemblyIsolationByMachine, union.UsageAllowed, "AssemblyIsolationByMachine"); Assert.AreEqual (5, union.UserQuota, "5"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-5"); Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-5a"); Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-5b"); Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-5c"); intersect = (IsolatedStorageFilePermission)union.Intersect (small); Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-5"); Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-5"); small.UsageAllowed = IsolatedStorageContainment.ApplicationIsolationByMachine; small.UserQuota = 6; union = (IsolatedStorageFilePermission)union.Union (small); Assert.AreEqual (IsolatedStorageContainment.ApplicationIsolationByMachine, union.UsageAllowed, "ApplicationIsolationByMachine"); Assert.AreEqual (6, union.UserQuota, "6"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-6"); Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-6a"); Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-6b"); Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-6c"); intersect = (IsolatedStorageFilePermission)union.Intersect (small); Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-6"); Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-6"); small.UsageAllowed = IsolatedStorageContainment.DomainIsolationByRoamingUser; small.UserQuota = 7; union = (IsolatedStorageFilePermission)union.Union (small); Assert.AreEqual (IsolatedStorageContainment.DomainIsolationByRoamingUser, union.UsageAllowed, "DomainIsolationByRoamingUser"); Assert.AreEqual (7, union.UserQuota, "7a"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-7a"); Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-7a"); Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-7b"); Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-7c"); intersect = (IsolatedStorageFilePermission)union.Intersect (small); Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-7"); Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-7"); // can't go back ;-) small.UsageAllowed = IsolatedStorageContainment.DomainIsolationByUser; small.UserQuota = 1; union = (IsolatedStorageFilePermission)union.Union (small); Assert.AreEqual (IsolatedStorageContainment.DomainIsolationByRoamingUser, union.UsageAllowed, "DomainIsolationByRoamingUser"); Assert.AreEqual (7, union.UserQuota, "7b"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-7b"); small.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByRoamingUser; small.UserQuota = 7; // no change union = (IsolatedStorageFilePermission)union.Union (small); Assert.AreEqual (IsolatedStorageContainment.AssemblyIsolationByRoamingUser, union.UsageAllowed, "AssemblyIsolationByRoamingUser"); Assert.AreEqual (7, union.UserQuota, "7c"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-7c"); small.UsageAllowed = IsolatedStorageContainment.ApplicationIsolationByRoamingUser; small.UserQuota = 8; union = (IsolatedStorageFilePermission)union.Union (small); Assert.AreEqual (IsolatedStorageContainment.ApplicationIsolationByRoamingUser, union.UsageAllowed, "ApplicationIsolationByRoamingUser"); Assert.AreEqual (8, union.UserQuota, "8"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-8"); Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-8a"); Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-8b"); Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-8c"); intersect = (IsolatedStorageFilePermission)union.Intersect (small); Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-8"); Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-8"); small.UsageAllowed = IsolatedStorageContainment.AdministerIsolatedStorageByUser; small.UserQuota = 9; union = (IsolatedStorageFilePermission)union.Union (small); Assert.AreEqual (IsolatedStorageContainment.AdministerIsolatedStorageByUser, union.UsageAllowed, "AdministerIsolatedStorageByUser"); Assert.AreEqual (9, union.UserQuota, "9"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-9"); Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-9a"); Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-9b"); Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-9c"); intersect = (IsolatedStorageFilePermission)union.Intersect (small); Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-9"); Assert.AreEqual (small.UserQuota, intersect.UserQuota, "Intersect-UserQuota-9"); small.UsageAllowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage; small.UserQuota = 10; union = (IsolatedStorageFilePermission)union.Union (small); Assert.AreEqual (IsolatedStorageContainment.UnrestrictedIsolatedStorage, union.UsageAllowed, "UnrestrictedIsolatedStorage"); Assert.AreEqual (Int64.MaxValue, union.UserQuota, "10"); Assert.IsTrue (union.IsUnrestricted (), "IsUnrestricted-10"); Assert.IsTrue (small.IsSubsetOf (union), "IsSubset-10a"); Assert.IsTrue (empty.IsSubsetOf (union), "IsSubset-10b"); Assert.IsTrue (union.IsSubsetOf (small), "IsSubset-10c"); intersect = (IsolatedStorageFilePermission)union.Intersect (small); Assert.AreEqual (small.UsageAllowed, intersect.UsageAllowed, "Intersect-UsageAllowed-10"); Assert.IsFalse ((small.UserQuota == intersect.UserQuota), "Intersect-UserQuota-10"); }
public void IsSubsetOf_DifferentPermissions () { IsolatedStorageFilePermission a = new IsolatedStorageFilePermission (PermissionState.None); SecurityPermission b = new SecurityPermission (PermissionState.None); a.IsSubsetOf (b); }
public void Union () { IsolatedStorageFilePermission empty = new IsolatedStorageFilePermission (PermissionState.None); IsolatedStorageFilePermission union = (IsolatedStorageFilePermission)empty.Union (null); Assert.IsNotNull (union, "empty U null"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-1"); Assert.IsFalse (Object.ReferenceEquals (empty, union), "ReferenceEquals-1"); union = (IsolatedStorageFilePermission)empty.Union (empty); Assert.IsNotNull (union, "empty U empty"); Assert.IsFalse (union.IsUnrestricted (), "IsUnrestricted-2"); Assert.IsFalse (Object.ReferenceEquals (empty, union), "ReferenceEquals-2"); IsolatedStorageFilePermission unrestricted = new IsolatedStorageFilePermission (PermissionState.Unrestricted); union = (IsolatedStorageFilePermission)unrestricted.Union (null); Assert.IsNotNull (union, "unrestricted U null"); Assert.IsTrue (union.IsUnrestricted (), "IsUnrestricted-3"); Assert.IsFalse (Object.ReferenceEquals (unrestricted, union), "ReferenceEquals-3"); union = (IsolatedStorageFilePermission)unrestricted.Union (empty); Assert.IsNotNull (union, "unrestricted U empty"); Assert.IsTrue (union.IsUnrestricted (), "IsUnrestricted-4"); Assert.IsFalse (Object.ReferenceEquals (unrestricted, union), "ReferenceEquals-4"); union = (IsolatedStorageFilePermission)unrestricted.Union (unrestricted); Assert.IsNotNull (union, "unrestricted U unrestricted"); Assert.IsTrue (union.IsUnrestricted (), "IsUnrestricted-5"); Assert.IsFalse (Object.ReferenceEquals (unrestricted, union), "ReferenceEquals-5"); }
public void IsSubsetOf () { IsolatedStorageFilePermission empty = new IsolatedStorageFilePermission (PermissionState.None); Assert.IsTrue (empty.IsSubsetOf (null), "empty.IsSubsetOf (null)"); IsolatedStorageFilePermission unrestricted = new IsolatedStorageFilePermission (PermissionState.Unrestricted); Assert.IsFalse (unrestricted.IsSubsetOf (null), "unrestricted.IsSubsetOf (null)"); Assert.IsFalse (unrestricted.IsSubsetOf (empty), "unrestricted.IsSubsetOf (empty)"); Assert.IsTrue (empty.IsSubsetOf (unrestricted), "empty.IsSubsetOf (unrestricted)"); }
public void Intersect_DifferentPermissions () { IsolatedStorageFilePermission a = new IsolatedStorageFilePermission (PermissionState.None); SecurityPermission b = new SecurityPermission (PermissionState.None); a.Intersect (b); }
private static NamedPermissionSet BuildInternet () { NamedPermissionSet nps = new NamedPermissionSet (ReservedNames.Internet, PermissionState.None); nps.AddPermission (new FileDialogPermission (FileDialogPermissionAccess.Open)); IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None); isfp.UsageAllowed = IsolatedStorageContainment.DomainIsolationByUser; isfp.UserQuota = 512000; nps.AddPermission (isfp); nps.AddPermission (new SecurityPermission (SecurityPermissionFlag.Execution)); nps.AddPermission (new UIPermission (UIPermissionWindow.SafeTopLevelWindows, UIPermissionClipboard.OwnClipboard)); // PrintingPermission requires stuff outside corlib (System.Drawing) nps.AddPermission (PermissionBuilder.Create (PrintingPermission ("SafePrinting"))); return nps; }
/// <internalonly/> int IBuiltInPermission.GetTokenIndex() { return(IsolatedStorageFilePermission.GetTokenIndex()); }
public void FromXml_Null () { IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None); isfp.FromXml (null); }
public void PermissionStateInvalid () { IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission ((PermissionState)2); }
public override IPermission Copy() { IsolatedStorageFilePermission copy ; copy = new IsolatedStorageFilePermission(PermissionState.Unrestricted); if(!IsUnrestricted()){ copy.m_userQuota = m_userQuota; copy.m_machineQuota = m_machineQuota; copy.m_expirationDays = m_expirationDays; copy.m_permanentData = m_permanentData; copy.m_allowed = m_allowed; } return copy; }
public override IPermission CreatePermission() { IsolatedStorageFilePermission p; if (m_unrestricted) { p = new IsolatedStorageFilePermission (PermissionState.Unrestricted); } else { p = new IsolatedStorageFilePermission(PermissionState.None); p.UserQuota = m_userQuota; p.UsageAllowed = m_allowed; #if false p.PermanentData = m_permanentData; p.MachineQuota = m_machineQuota; p.ExpirationDays = m_expirationDays; #endif } return p; }
private static NamedPermissionSet BuildLocalIntranet () { NamedPermissionSet nps = new NamedPermissionSet (ReservedNames.LocalIntranet, PermissionState.None); nps.AddPermission (new EnvironmentPermission (EnvironmentPermissionAccess.Read, "USERNAME;USER")); nps.AddPermission (new FileDialogPermission (PermissionState.Unrestricted)); IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.None); isfp.UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser; isfp.UserQuota = Int64.MaxValue; nps.AddPermission (isfp); nps.AddPermission (new ReflectionPermission (ReflectionPermissionFlag.ReflectionEmit)); SecurityPermissionFlag spf = SecurityPermissionFlag.Execution | SecurityPermissionFlag.Assertion; nps.AddPermission (new SecurityPermission (spf)); nps.AddPermission (new UIPermission (PermissionState.Unrestricted)); // DnsPermission requires stuff outside corlib (System) nps.AddPermission (PermissionBuilder.Create (DnsPermissionClass, PermissionState.Unrestricted)); // PrintingPermission requires stuff outside corlib (System.Drawing) nps.AddPermission (PermissionBuilder.Create (PrintingPermission ("SafePrinting"))); return nps; }
public void GetPermission_Subclass () { IsolatedStorageFilePermission isfp = new IsolatedStorageFilePermission (PermissionState.Unrestricted); PermissionSet ps = new PermissionSet (PermissionState.None); ps.AddPermission (isfp); Assert.IsNull (ps.GetPermission (typeof (IsolatedStoragePermission)), "Subclass"); }
public override IPermission Intersect(IPermission target) { if (target == null) return null; else if (!VerifyType(target)) { throw new ArgumentException( Environment.GetResourceString("Argument_WrongType", this.GetType().FullName) ); } IsolatedStorageFilePermission operand = (IsolatedStorageFilePermission)target; if(operand.IsUnrestricted()) return Copy(); else if(IsUnrestricted()) return target.Copy(); IsolatedStorageFilePermission intersection; intersection = new IsolatedStorageFilePermission( PermissionState.None ); intersection.m_userQuota = min(m_userQuota,operand.m_userQuota); intersection.m_machineQuota = min(m_machineQuota,operand.m_machineQuota); intersection.m_expirationDays = min(m_expirationDays,operand.m_expirationDays); intersection.m_permanentData = m_permanentData && operand.m_permanentData; intersection.m_allowed = (IsolatedStorageContainment)min((long)m_allowed,(long)operand.m_allowed); if ((intersection.m_userQuota == 0) && (intersection.m_machineQuota == 0) && (intersection.m_expirationDays == 0) && (intersection.m_permanentData == false) && (intersection.m_allowed == IsolatedStorageContainment.None)) return null; return intersection; }