mscorlib(4.0.0.0) API with additions
IsolatedStorageFilePermission.cs
2 
4 {
7  [ComVisible(true)]
8  public sealed class IsolatedStorageFilePermission : IsolatedStoragePermission, IBuiltInPermission
9  {
14  : base(state)
15  {
16  }
17 
18  internal IsolatedStorageFilePermission(IsolatedStorageContainment UsageAllowed, long ExpirationDays, bool PermanentData)
19  : base(UsageAllowed, ExpirationDays, PermanentData)
20  {
21  }
22 
27  public override IPermission Union(IPermission target)
28  {
29  if (target == null)
30  {
31  return Copy();
32  }
33  if (!VerifyType(target))
34  {
35  throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", GetType().FullName));
36  }
37  IsolatedStorageFilePermission isolatedStorageFilePermission = (IsolatedStorageFilePermission)target;
38  if (IsUnrestricted() || isolatedStorageFilePermission.IsUnrestricted())
39  {
40  return new IsolatedStorageFilePermission(PermissionState.Unrestricted);
41  }
42  IsolatedStorageFilePermission isolatedStorageFilePermission2 = new IsolatedStorageFilePermission(PermissionState.None);
43  isolatedStorageFilePermission2.m_userQuota = IsolatedStoragePermission.max(m_userQuota, isolatedStorageFilePermission.m_userQuota);
44  isolatedStorageFilePermission2.m_machineQuota = IsolatedStoragePermission.max(m_machineQuota, isolatedStorageFilePermission.m_machineQuota);
45  isolatedStorageFilePermission2.m_expirationDays = IsolatedStoragePermission.max(m_expirationDays, isolatedStorageFilePermission.m_expirationDays);
46  isolatedStorageFilePermission2.m_permanentData = (m_permanentData || isolatedStorageFilePermission.m_permanentData);
47  isolatedStorageFilePermission2.m_allowed = (IsolatedStorageContainment)IsolatedStoragePermission.max((long)m_allowed, (long)isolatedStorageFilePermission.m_allowed);
48  return isolatedStorageFilePermission2;
49  }
50 
56  public override bool IsSubsetOf(IPermission target)
57  {
58  if (target == null)
59  {
60  if (m_userQuota == 0L && m_machineQuota == 0L && m_expirationDays == 0L && !m_permanentData)
61  {
62  return m_allowed == IsolatedStorageContainment.None;
63  }
64  return false;
65  }
66  try
67  {
68  IsolatedStorageFilePermission isolatedStorageFilePermission = (IsolatedStorageFilePermission)target;
69  if (isolatedStorageFilePermission.IsUnrestricted())
70  {
71  return true;
72  }
73  return isolatedStorageFilePermission.m_userQuota >= m_userQuota && isolatedStorageFilePermission.m_machineQuota >= m_machineQuota && isolatedStorageFilePermission.m_expirationDays >= m_expirationDays && (isolatedStorageFilePermission.m_permanentData || !m_permanentData) && isolatedStorageFilePermission.m_allowed >= m_allowed;
74  }
75  catch (InvalidCastException)
76  {
77  throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", GetType().FullName));
78  }
79  }
80 
85  public override IPermission Intersect(IPermission target)
86  {
87  if (target == null)
88  {
89  return null;
90  }
91  if (!VerifyType(target))
92  {
93  throw new ArgumentException(Environment.GetResourceString("Argument_WrongType", GetType().FullName));
94  }
95  IsolatedStorageFilePermission isolatedStorageFilePermission = (IsolatedStorageFilePermission)target;
96  if (isolatedStorageFilePermission.IsUnrestricted())
97  {
98  return Copy();
99  }
100  if (IsUnrestricted())
101  {
102  return target.Copy();
103  }
104  IsolatedStorageFilePermission isolatedStorageFilePermission2 = new IsolatedStorageFilePermission(PermissionState.None);
105  isolatedStorageFilePermission2.m_userQuota = IsolatedStoragePermission.min(m_userQuota, isolatedStorageFilePermission.m_userQuota);
106  isolatedStorageFilePermission2.m_machineQuota = IsolatedStoragePermission.min(m_machineQuota, isolatedStorageFilePermission.m_machineQuota);
107  isolatedStorageFilePermission2.m_expirationDays = IsolatedStoragePermission.min(m_expirationDays, isolatedStorageFilePermission.m_expirationDays);
108  isolatedStorageFilePermission2.m_permanentData = (m_permanentData && isolatedStorageFilePermission.m_permanentData);
109  isolatedStorageFilePermission2.m_allowed = (IsolatedStorageContainment)IsolatedStoragePermission.min((long)m_allowed, (long)isolatedStorageFilePermission.m_allowed);
110  if (isolatedStorageFilePermission2.m_userQuota == 0L && isolatedStorageFilePermission2.m_machineQuota == 0L && isolatedStorageFilePermission2.m_expirationDays == 0L && !isolatedStorageFilePermission2.m_permanentData && isolatedStorageFilePermission2.m_allowed == IsolatedStorageContainment.None)
111  {
112  return null;
113  }
114  return isolatedStorageFilePermission2;
115  }
116 
119  public override IPermission Copy()
120  {
121  IsolatedStorageFilePermission isolatedStorageFilePermission = new IsolatedStorageFilePermission(PermissionState.Unrestricted);
122  if (!IsUnrestricted())
123  {
124  isolatedStorageFilePermission.m_userQuota = m_userQuota;
125  isolatedStorageFilePermission.m_machineQuota = m_machineQuota;
126  isolatedStorageFilePermission.m_expirationDays = m_expirationDays;
127  isolatedStorageFilePermission.m_permanentData = m_permanentData;
128  isolatedStorageFilePermission.m_allowed = m_allowed;
129  }
130  return isolatedStorageFilePermission;
131  }
132 
133  int IBuiltInPermission.GetTokenIndex()
134  {
135  return GetTokenIndex();
136  }
137 
138  internal static int GetTokenIndex()
139  {
140  return 3;
141  }
142 
145  [ComVisible(false)]
146  public override SecurityElement ToXml()
147  {
148  return ToXml("System.Security.Permissions.IsolatedStorageFilePermission");
149  }
150  }
151 }
bool IsUnrestricted()
Returns a value indicating whether the current permission is unrestricted.
Definition: __Canon.cs:3
The exception that is thrown for invalid casting or explicit conversion.
override bool IsSubsetOf(IPermission target)
Determines whether the current permission is a subset of the specified permission.
IPermission Copy()
Creates and returns an identical copy of the current permission.
IsolatedStorageContainment
Specifies the permitted use of isolated storage.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
IsolatedStorageContainment UsageAllowed
Gets or sets the type of isolated storage containment allowed.
Represents the XML object model for encoding security objects. This class cannot be inherited.
Specifies the allowed usage of a private virtual file system. This class cannot be inherited.
IsolatedStorageFilePermission(PermissionState state)
Initializes a new instance of the T:System.Security.Permissions.IsolatedStorageFilePermission class w...
Defines methods implemented by permission types.
Definition: IPermission.cs:7
override IPermission Union(IPermission target)
Creates a permission that is the union of the current permission and the specified permission.
The exception that is thrown when one of the arguments provided to a method is not valid.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
Specifies that the class can be serialized.
Represents access to generic isolated storage capabilities.
override SecurityElement ToXml()
Creates an XML encoding of the permission and its current state.
override IPermission Intersect(IPermission target)
Creates and returns a permission that is the intersection of the current permission and the specified...
override IPermission Copy()
Creates and returns an identical copy of the current permission.