2 // System.IO.IsolatedStorage.cs
5 // Duncan Mak (duncan@ximian.com)
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // (C) Ximian, Inc. http://www.ximian.com
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Globalization;
32 using System.Reflection;
33 using System.Runtime.InteropServices;
34 using System.Security;
35 using System.Security.Permissions;
36 using System.Security.Policy;
38 namespace System.IO.IsolatedStorage {
41 public abstract class IsolatedStorage : MarshalByRefObject {
44 protected IsolatedStorage ()
49 internal IsolatedStorageScope storage_scope;
50 internal object _assemblyIdentity;
51 internal object _domainIdentity;
52 internal object _applicationIdentity;
56 [MonoTODO ("Does not currently use the manifest support")]
58 public object ApplicationIdentity {
59 [SecurityPermission (SecurityAction.Demand, ControlPolicy=true)]
61 if ((storage_scope & IsolatedStorageScope.Application) == 0) {
62 throw new InvalidOperationException (Locale.GetText ("Invalid Isolation Scope."));
64 if (_applicationIdentity == null)
65 throw new InvalidOperationException (Locale.GetText ("Identity unavailable."));
67 throw new NotImplementedException (Locale.GetText ("CAS related"));
71 public object AssemblyIdentity {
72 [SecurityPermission (SecurityAction.Demand, ControlPolicy=true)]
74 if ((storage_scope & IsolatedStorageScope.Assembly) == 0) {
75 throw new InvalidOperationException (Locale.GetText ("Invalid Isolation Scope."));
77 if (_assemblyIdentity == null)
78 throw new InvalidOperationException (Locale.GetText ("Identity unavailable."));
79 return _assemblyIdentity;
83 [CLSCompliant (false)]
87 public virtual ulong CurrentSize {
89 throw new InvalidOperationException (
90 Locale.GetText ("IsolatedStorage does not have a preset CurrentSize."));
94 public object DomainIdentity {
95 [SecurityPermission (SecurityAction.Demand, ControlPolicy=true)]
97 if ((storage_scope & IsolatedStorageScope.Domain) == 0) {
98 throw new InvalidOperationException (Locale.GetText ("Invalid Isolation Scope."));
100 if (_domainIdentity == null)
101 throw new InvalidOperationException (Locale.GetText ("Identity unavailable."));
102 return _domainIdentity;
106 [CLSCompliant (false)]
107 #if NET_4_0 || MOBILE
110 public virtual ulong MaximumSize {
112 throw new InvalidOperationException (
113 Locale.GetText ("IsolatedStorage does not have a preset MaximumSize."));
117 public IsolatedStorageScope Scope {
118 get { return storage_scope; }
121 #if NET_4_0 || MOBILE
123 public virtual long AvailableFreeSpace {
125 throw new InvalidOperationException ("This property is not defined for this store.");
130 public virtual long Quota {
132 throw new InvalidOperationException ("This property is not defined for this store.");
137 public virtual long UsedSize {
139 throw new InvalidOperationException ("This property is not defined for this store.");
144 protected virtual char SeparatorExternal {
145 get { return System.IO.Path.DirectorySeparatorChar; }
148 protected virtual char SeparatorInternal {
153 protected abstract IsolatedStoragePermission GetPermission (PermissionSet ps);
155 protected void InitStore (IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
157 // I know it's useless - but it's tested as such...
159 case (IsolatedStorageScope.Assembly | IsolatedStorageScope.User):
160 case (IsolatedStorageScope.Assembly | IsolatedStorageScope.User | IsolatedStorageScope.Domain):
161 throw new NotImplementedException (scope.ToString ());
163 // invalid (incomplete) scope
164 throw new ArgumentException (scope.ToString ());
168 [MonoTODO ("requires manifest support")]
169 protected void InitStore (IsolatedStorageScope scope, Type appEvidenceType)
172 if (AppDomain.CurrentDomain.ApplicationIdentity == null)
173 throw new IsolatedStorageException (Locale.GetText ("No ApplicationIdentity available for AppDomain."));
175 if (appEvidenceType == null) {
176 // TODO - Choose evidence
180 // no exception here because this can work without CAS
181 storage_scope = scope;
183 public abstract void Remove ();
185 #if NET_4_0 || MOBILE
187 public virtual bool IncreaseQuotaTo (long newQuotaSize)