mscorlib(4.0.0.0) API with additions
IsolatedStoragePermission.cs
3 using System.Security.Util;
4 
6 {
9  [ComVisible(true)]
10  [SecurityPermission(SecurityAction.InheritanceDemand, ControlEvidence = true, ControlPolicy = true)]
12  {
13  internal long m_userQuota;
14 
15  internal long m_machineQuota;
16 
17  internal long m_expirationDays;
18 
19  internal bool m_permanentData;
20 
21  internal IsolatedStorageContainment m_allowed;
22 
23  private const string _strUserQuota = "UserQuota";
24 
25  private const string _strMachineQuota = "MachineQuota";
26 
27  private const string _strExpiry = "Expiry";
28 
29  private const string _strPermDat = "Permanent";
30 
33  public long UserQuota
34  {
35  get
36  {
37  return m_userQuota;
38  }
39  set
40  {
41  m_userQuota = value;
42  }
43  }
44 
48  {
49  get
50  {
51  return m_allowed;
52  }
53  set
54  {
55  m_allowed = value;
56  }
57  }
58 
63  {
64  switch (state)
65  {
66  case PermissionState.Unrestricted:
67  m_userQuota = long.MaxValue;
68  m_machineQuota = long.MaxValue;
69  m_expirationDays = long.MaxValue;
70  m_permanentData = true;
71  m_allowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
72  break;
73  case PermissionState.None:
74  m_userQuota = 0L;
75  m_machineQuota = 0L;
76  m_expirationDays = 0L;
77  m_permanentData = false;
78  m_allowed = IsolatedStorageContainment.None;
79  break;
80  default:
81  throw new ArgumentException(Environment.GetResourceString("Argument_InvalidPermissionState"));
82  }
83  }
84 
85  internal IsolatedStoragePermission(IsolatedStorageContainment UsageAllowed, long ExpirationDays, bool PermanentData)
86  {
87  m_userQuota = 0L;
88  m_machineQuota = 0L;
89  m_expirationDays = ExpirationDays;
90  m_permanentData = PermanentData;
91  m_allowed = UsageAllowed;
92  }
93 
94  internal IsolatedStoragePermission(IsolatedStorageContainment UsageAllowed, long ExpirationDays, bool PermanentData, long UserQuota)
95  {
96  m_machineQuota = 0L;
97  m_userQuota = UserQuota;
98  m_expirationDays = ExpirationDays;
99  m_permanentData = PermanentData;
100  m_allowed = UsageAllowed;
101  }
102 
106  public bool IsUnrestricted()
107  {
108  return m_allowed == IsolatedStorageContainment.UnrestrictedIsolatedStorage;
109  }
110 
111  internal static long min(long x, long y)
112  {
113  if (x <= y)
114  {
115  return x;
116  }
117  return y;
118  }
119 
120  internal static long max(long x, long y)
121  {
122  if (x >= y)
123  {
124  return x;
125  }
126  return y;
127  }
128 
131  public override SecurityElement ToXml()
132  {
133  return ToXml(GetType().FullName);
134  }
135 
136  internal SecurityElement ToXml(string permName)
137  {
138  SecurityElement securityElement = CodeAccessPermission.CreatePermissionElement(this, permName);
139  if (!IsUnrestricted())
140  {
141  securityElement.AddAttribute("Allowed", Enum.GetName(typeof(IsolatedStorageContainment), m_allowed));
142  if (m_userQuota > 0)
143  {
144  securityElement.AddAttribute("UserQuota", m_userQuota.ToString(CultureInfo.InvariantCulture));
145  }
146  if (m_machineQuota > 0)
147  {
148  securityElement.AddAttribute("MachineQuota", m_machineQuota.ToString(CultureInfo.InvariantCulture));
149  }
150  if (m_expirationDays > 0)
151  {
152  securityElement.AddAttribute("Expiry", m_expirationDays.ToString(CultureInfo.InvariantCulture));
153  }
154  if (m_permanentData)
155  {
156  securityElement.AddAttribute("Permanent", m_permanentData.ToString());
157  }
158  }
159  else
160  {
161  securityElement.AddAttribute("Unrestricted", "true");
162  }
163  return securityElement;
164  }
165 
170  public override void FromXml(SecurityElement esd)
171  {
172  CodeAccessPermission.ValidateElement(esd, this);
173  m_allowed = IsolatedStorageContainment.None;
174  if (XMLUtil.IsUnrestricted(esd))
175  {
176  m_allowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
177  }
178  else
179  {
180  string text = esd.Attribute("Allowed");
181  if (text != null)
182  {
184  }
185  }
186  if (m_allowed == IsolatedStorageContainment.UnrestrictedIsolatedStorage)
187  {
188  m_userQuota = long.MaxValue;
189  m_machineQuota = long.MaxValue;
190  m_expirationDays = long.MaxValue;
191  m_permanentData = true;
192  return;
193  }
194  string text2 = esd.Attribute("UserQuota");
195  m_userQuota = ((text2 != null) ? long.Parse(text2, CultureInfo.InvariantCulture) : 0);
196  text2 = esd.Attribute("MachineQuota");
197  m_machineQuota = ((text2 != null) ? long.Parse(text2, CultureInfo.InvariantCulture) : 0);
198  text2 = esd.Attribute("Expiry");
199  m_expirationDays = ((text2 != null) ? long.Parse(text2, CultureInfo.InvariantCulture) : 0);
200  text2 = esd.Attribute("Permanent");
201  m_permanentData = (text2 != null && bool.Parse(text2));
202  }
203  }
204 }
static string GetName(Type enumType, object value)
Retrieves the name of the constant in the specified enumeration that has the specified value.
Definition: Enum.cs:482
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
override SecurityElement ToXml()
Creates an XML encoding of the permission and its current state.
Allows a permission to expose an unrestricted state.
bool IsUnrestricted()
Returns a value indicating whether the current permission is unrestricted.
Definition: __Canon.cs:3
override void FromXml(SecurityElement esd)
Reconstructs a permission with a specified state from an XML encoding.
static object Parse(Type enumType, string value)
Converts the string representation of the name or numeric value of one or more enumerated constants t...
Definition: Enum.cs:298
IsolatedStorageContainment
Specifies the permitted use of isolated storage.
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Provides the base class for enumerations.
Definition: Enum.cs:14
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.
IsolatedStoragePermission(PermissionState state)
Initializes a new instance of the T:System.Security.Permissions.IsolatedStoragePermission class with ...
Defines the underlying structure of all code access permissions.
long UserQuota
Gets or sets the quota on the overall size of each user's total store.
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.
void AddAttribute(string name, string value)
Adds a name/value attribute to an XML element.
Specifies that the class can be serialized.
Represents access to generic isolated storage capabilities.
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16