2 // System.Security.Permissions.IsolatedStoragePermission.cs
4 // Piers Haken <piersh@friskit.com>
6 // (C) 2002 Ximian, Inc. http://www.ximian.com
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Globalization;
34 using System.Security.Permissions;
36 namespace System.Security.Permissions
39 public abstract class IsolatedStoragePermission : CodeAccessPermission, IUnrestrictedPermission
41 internal long m_userQuota;
42 internal long m_machineQuota;
43 internal long m_expirationDays;
44 internal bool m_permanentData;
45 internal IsolatedStorageContainment m_allowed;
47 public IsolatedStoragePermission (PermissionState state)
49 if (state == PermissionState.None)
54 m_permanentData = false;
55 m_allowed = IsolatedStorageContainment.None;
57 else if (state == PermissionState.Unrestricted)
59 m_userQuota = Int64.MaxValue;
60 m_machineQuota = Int64.MaxValue;
61 m_expirationDays = Int64.MaxValue ;
62 m_permanentData = true;
63 m_allowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
67 throw new ArgumentException("Invalid Permission state");
73 set { m_userQuota = value; }
74 get { return m_userQuota; }
78 public IsolatedStorageContainment UsageAllowed
80 set { m_allowed = value; }
81 get { return m_allowed; }
85 public bool IsUnrestricted ()
87 return IsolatedStorageContainment.UnrestrictedIsolatedStorage == m_allowed;
90 public override SecurityElement ToXml ()
92 SecurityElement e = new SecurityElement ("IPermission");
93 e.AddAttribute ("class", GetType ().AssemblyQualifiedName);
94 e.AddAttribute ("version", "1");
96 if (m_allowed == IsolatedStorageContainment.UnrestrictedIsolatedStorage)
97 e.AddAttribute ("Unrestricted", "true");
99 else if (m_allowed == IsolatedStorageContainment.None)
100 e.AddAttribute ("Allowed", "None");
106 public override void FromXml (SecurityElement esd)
109 throw new ArgumentNullException (
110 Locale.GetText ("The argument is null."));
112 if (esd.Attribute ("class") != GetType ().AssemblyQualifiedName)
113 throw new ArgumentException (
114 Locale.GetText ("The argument is not valid"));
116 if (esd.Attribute ("version") != "1")
117 throw new ArgumentException (
118 Locale.GetText ("The argument is not valid"));
120 if (esd.Attribute ("Unrestricted") == "true")
121 m_allowed = IsolatedStorageContainment.UnrestrictedIsolatedStorage;
123 else if (esd.Attribute ("Allowed") == "None")
124 m_allowed = IsolatedStorageContainment.None;