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 {
38 public sealed class IsolatedStorageFilePermission : IsolatedStoragePermission, IBuiltInPermission {
40 private const int version = 1;
44 public IsolatedStorageFilePermission (PermissionState state)
53 public override IPermission Copy ()
55 IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None);
56 p.m_userQuota = m_userQuota;
57 p.m_machineQuota = m_machineQuota;
58 p.m_expirationDays = m_expirationDays;
59 p.m_permanentData = m_permanentData;
60 p.m_allowed = m_allowed;
64 public override IPermission Intersect (IPermission target)
66 IsolatedStorageFilePermission isfp = Cast (target);
69 if (IsEmpty () && isfp.IsEmpty ())
72 IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None);
73 p.m_userQuota = (m_userQuota < isfp.m_userQuota) ? m_userQuota : isfp.m_userQuota;
74 p.m_machineQuota = (m_machineQuota < isfp.m_machineQuota) ? m_machineQuota : isfp.m_machineQuota;
75 p.m_expirationDays = (m_expirationDays < isfp.m_expirationDays) ? m_expirationDays : isfp.m_expirationDays;
76 p.m_permanentData = (m_permanentData && isfp.m_permanentData);
77 // UsageAllowed == Unrestricted is a special case handled by the property
78 p.UsageAllowed = (m_allowed < isfp.m_allowed) ? m_allowed : isfp.m_allowed;
82 public override bool IsSubsetOf (IPermission target)
84 IsolatedStorageFilePermission isfp = Cast (target);
87 if (isfp.IsUnrestricted ())
90 if (m_userQuota > isfp.m_userQuota)
92 if (m_machineQuota > isfp.m_machineQuota)
94 if (m_expirationDays > isfp.m_expirationDays)
96 if (m_permanentData != isfp.m_permanentData)
98 if (m_allowed > isfp.m_allowed)
103 public override IPermission Union (IPermission target)
105 IsolatedStorageFilePermission isfp = Cast (target);
109 IsolatedStorageFilePermission p = new IsolatedStorageFilePermission (PermissionState.None);
110 p.m_userQuota = (m_userQuota > isfp.m_userQuota) ? m_userQuota : isfp.m_userQuota;
111 p.m_machineQuota = (m_machineQuota > isfp.m_machineQuota) ? m_machineQuota : isfp.m_machineQuota;
112 p.m_expirationDays = (m_expirationDays > isfp.m_expirationDays) ? m_expirationDays : isfp.m_expirationDays;
113 p.m_permanentData = (m_permanentData || isfp.m_permanentData);
114 // UsageAllowed == Unrestricted is a special case handled by the property
115 p.UsageAllowed = (m_allowed > isfp.m_allowed) ? m_allowed : isfp.m_allowed;
120 [MonoTODO ("new override - something must have been added ???")]
122 public override SecurityElement ToXml ()
124 return base.ToXml ();
128 // IBuiltInPermission
129 int IBuiltInPermission.GetTokenIndex ()
131 return (int) BuiltInToken.IsolatedStorageFile;
136 private IsolatedStorageFilePermission Cast (IPermission target)
141 IsolatedStorageFilePermission isfp = (target as IsolatedStorageFilePermission);
143 ThrowInvalidPermission (target, typeof (IsolatedStorageFilePermission));