2 // System.Security.Permissions.IsolatedStorageFilePermission.cs
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2003 Motus Technologies. http://www.motus.com
8 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Runtime.InteropServices;
32 namespace System.Security.Permissions {
36 public sealed class IsolatedStorageFilePermission : IsolatedStoragePermission, IBuiltInPermission {
40 public IsolatedStorageFilePermission (PermissionState state)
49 public override IPermission Copy ()
51 IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None);
52 p.m_userQuota = m_userQuota;
53 p.m_machineQuota = m_machineQuota;
54 p.m_expirationDays = m_expirationDays;
55 p.m_permanentData = m_permanentData;
56 p.m_allowed = m_allowed;
60 public override IPermission Intersect (IPermission target)
62 IsolatedStorageFilePermission isfp = Cast (target);
65 if (IsEmpty () && isfp.IsEmpty ())
68 IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None);
69 p.m_userQuota = (m_userQuota < isfp.m_userQuota) ? m_userQuota : isfp.m_userQuota;
70 p.m_machineQuota = (m_machineQuota < isfp.m_machineQuota) ? m_machineQuota : isfp.m_machineQuota;
71 p.m_expirationDays = (m_expirationDays < isfp.m_expirationDays) ? m_expirationDays : isfp.m_expirationDays;
72 p.m_permanentData = (m_permanentData && isfp.m_permanentData);
73 // UsageAllowed == Unrestricted is a special case handled by the property
74 p.UsageAllowed = (m_allowed < isfp.m_allowed) ? m_allowed : isfp.m_allowed;
78 public override bool IsSubsetOf (IPermission target)
80 IsolatedStorageFilePermission isfp = Cast (target);
83 if (isfp.IsUnrestricted ())
86 if (m_userQuota > isfp.m_userQuota)
88 if (m_machineQuota > isfp.m_machineQuota)
90 if (m_expirationDays > isfp.m_expirationDays)
92 if (m_permanentData != isfp.m_permanentData)
94 if (m_allowed > isfp.m_allowed)
99 public override IPermission Union (IPermission target)
101 IsolatedStorageFilePermission isfp = Cast (target);
105 IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None);
106 p.m_userQuota = (m_userQuota > isfp.m_userQuota) ? m_userQuota : isfp.m_userQuota;
107 p.m_machineQuota = (m_machineQuota > isfp.m_machineQuota) ? m_machineQuota : isfp.m_machineQuota;
108 p.m_expirationDays = (m_expirationDays > isfp.m_expirationDays) ? m_expirationDays : isfp.m_expirationDays;
109 p.m_permanentData = (m_permanentData || isfp.m_permanentData);
110 // UsageAllowed == Unrestricted is a special case handled by the property
111 p.UsageAllowed = (m_allowed > isfp.m_allowed) ? m_allowed : isfp.m_allowed;
115 [MonoTODO ("(2.0) new override - something must have been added ???")]
117 public override SecurityElement ToXml ()
119 return base.ToXml ();
122 // IBuiltInPermission
123 int IBuiltInPermission.GetTokenIndex ()
125 return (int) BuiltInToken.IsolatedStorageFile;
130 private IsolatedStorageFilePermission Cast (IPermission target)
135 IsolatedStorageFilePermission isfp = (target as IsolatedStorageFilePermission);
137 ThrowInvalidPermission (target, typeof (IsolatedStorageFilePermission));