Add locking to EventWaitHandle.Set/Reset to avoid crashes when another thread dispose...
[mono.git] / mcs / class / corlib / System.IO.IsolatedStorage / IsolatedStorage.cs
1 //
2 // System.IO.IsolatedStorage.cs
3 //
4 // Authors:
5 //      Duncan Mak (duncan@ximian.com)
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // (C) Ximian, Inc. http://www.ximian.com
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 #if !MOONLIGHT
32 using System.Globalization;
33 using System.Reflection;
34 using System.Runtime.InteropServices;
35 using System.Security;
36 using System.Security.Permissions;
37 using System.Security.Policy;
38
39 namespace System.IO.IsolatedStorage {
40
41         [ComVisible (true)]
42         public abstract class IsolatedStorage : MarshalByRefObject {
43
44                 // Constructor
45                 protected IsolatedStorage ()
46                         : base ()
47                 {
48                 }
49
50                 internal IsolatedStorageScope storage_scope;
51                 internal object _assemblyIdentity;
52                 internal object _domainIdentity;
53                 internal object _applicationIdentity;
54
55                 // Properties
56
57                 [MonoTODO ("Does not currently use the manifest support")]
58                 [ComVisible (false)]
59                 public object ApplicationIdentity {
60                         [SecurityPermission (SecurityAction.Demand, ControlPolicy=true)]
61                         get {
62                                 if ((storage_scope & IsolatedStorageScope.Application) == 0) {
63                                         throw new InvalidOperationException (Locale.GetText ("Invalid Isolation Scope.")); 
64                                 }
65                                 if (_applicationIdentity == null)
66                                         throw new InvalidOperationException (Locale.GetText ("Identity unavailable.")); 
67
68                                 throw new NotImplementedException (Locale.GetText ("CAS related")); 
69                         }
70                 }
71
72                 public object AssemblyIdentity {
73                         [SecurityPermission (SecurityAction.Demand, ControlPolicy=true)]
74                         get {
75                                 if ((storage_scope & IsolatedStorageScope.Assembly) == 0) {
76                                         throw new InvalidOperationException (Locale.GetText ("Invalid Isolation Scope.")); 
77                                 }
78                                 if (_assemblyIdentity == null)
79                                         throw new InvalidOperationException (Locale.GetText ("Identity unavailable.")); 
80                                 return _assemblyIdentity;
81                         }
82                 }
83
84                 [CLSCompliant (false)]
85 #if NET_4_0 || MOBILE
86                 [Obsolete]
87 #endif
88                 public virtual ulong CurrentSize {
89                         get {
90                                 throw new InvalidOperationException (
91                                         Locale.GetText ("IsolatedStorage does not have a preset CurrentSize."));
92                         }
93                 }
94
95                 public object DomainIdentity {
96                         [SecurityPermission (SecurityAction.Demand, ControlPolicy=true)]
97                         get {
98                                 if ((storage_scope & IsolatedStorageScope.Domain) == 0) {
99                                         throw new InvalidOperationException (Locale.GetText ("Invalid Isolation Scope.")); 
100                                 }
101                                 if (_domainIdentity == null)
102                                         throw new InvalidOperationException (Locale.GetText ("Identity unavailable.")); 
103                                 return _domainIdentity;
104                         }
105                 }
106
107                 [CLSCompliant (false)]
108 #if NET_4_0 || MOBILE
109                 [Obsolete]
110 #endif
111                 public virtual ulong MaximumSize {
112                         get {
113                                 throw new InvalidOperationException (
114                                         Locale.GetText ("IsolatedStorage does not have a preset MaximumSize."));
115                         }
116                 }
117
118                 public IsolatedStorageScope Scope {
119                         get { return storage_scope; }
120                 }
121
122 #if NET_4_0 || MOBILE
123                 [ComVisible (false)]
124                 public virtual long AvailableFreeSpace {
125                         get {
126                                 throw new InvalidOperationException ("This property is not defined for this store.");
127                         }
128                 }
129
130                 [ComVisible (false)]
131                 public virtual long Quota {
132                         get {
133                                 throw new InvalidOperationException ("This property is not defined for this store.");
134                         }
135                 }
136
137                 [ComVisible (false)]
138                 public virtual long UsedSize {
139                         get {
140                                 throw new InvalidOperationException ("This property is not defined for this store.");
141                         }
142                 }
143 #endif
144
145                 protected virtual char SeparatorExternal {
146                         get { return System.IO.Path.DirectorySeparatorChar; }
147                 }
148
149                 protected virtual char SeparatorInternal {
150                         get { return '.'; }
151                 }
152
153                 // Methods
154                 protected abstract IsolatedStoragePermission GetPermission (PermissionSet ps);
155
156                 protected void InitStore (IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
157                 {
158                         // I know it's useless - but it's tested as such...
159                         switch (scope) {
160                         case (IsolatedStorageScope.Assembly | IsolatedStorageScope.User):
161                         case (IsolatedStorageScope.Assembly | IsolatedStorageScope.User | IsolatedStorageScope.Domain):
162                                 throw new NotImplementedException (scope.ToString ());
163                         default:
164                                 // invalid (incomplete) scope
165                                 throw new ArgumentException (scope.ToString ());
166                         }
167                 }
168
169                 [MonoTODO ("requires manifest support")]
170                 protected void InitStore (IsolatedStorageScope scope, Type appEvidenceType)
171                 {
172 #if !MOBILE
173                         if (AppDomain.CurrentDomain.ApplicationIdentity == null)
174                                 throw new IsolatedStorageException (Locale.GetText ("No ApplicationIdentity available for AppDomain."));
175
176                         if (appEvidenceType == null) {
177                                 // TODO - Choose evidence
178                         }
179 #endif
180
181                         // no exception here because this can work without CAS
182                         storage_scope = scope;
183                 }
184                 public abstract void Remove ();
185
186 #if NET_4_0 || MOBILE
187                 [ComVisible (false)]
188                 public virtual bool IncreaseQuotaTo (long newQuotaSize)
189                 {
190                         return false;
191                 }
192 #endif
193         }
194 }
195 /* MOONLIGHT */
196 #endif