* HttpListener2Test.cs: Added test for bug #513849.
[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 !NET_2_1
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 #if NET_2_0
42         [ComVisible (true)]
43 #endif
44         public abstract class IsolatedStorage : MarshalByRefObject {
45
46                 // Constructor
47                 protected IsolatedStorage ()
48                         : base ()
49                 {
50                 }
51
52                 internal IsolatedStorageScope storage_scope;
53                 internal object _assemblyIdentity;
54                 internal object _domainIdentity;
55                 internal object _applicationIdentity;
56
57                 // Properties
58
59 #if NET_2_0
60                 [MonoTODO ("requires manifest support")]
61                 [ComVisible (false)]
62                 public object ApplicationIdentity {
63                         [SecurityPermission (SecurityAction.Demand, ControlPolicy=true)]
64                         get {
65                                 if ((storage_scope & IsolatedStorageScope.Application) == 0) {
66                                         throw new InvalidOperationException (Locale.GetText ("Invalid Isolation Scope.")); 
67                                 }
68                                 if (_applicationIdentity == null)
69                                         throw new InvalidOperationException (Locale.GetText ("Identity unavailable.")); 
70
71                                 throw new NotImplementedException (Locale.GetText ("CAS related")); 
72                         }
73                 }
74 #endif
75
76                 public object AssemblyIdentity {
77                         [SecurityPermission (SecurityAction.Demand, ControlPolicy=true)]
78                         get {
79 #if NET_2_0
80                                 if ((storage_scope & IsolatedStorageScope.Assembly) == 0) {
81                                         throw new InvalidOperationException (Locale.GetText ("Invalid Isolation Scope.")); 
82                                 }
83                                 if (_assemblyIdentity == null)
84                                         throw new InvalidOperationException (Locale.GetText ("Identity unavailable.")); 
85 #endif
86                                 return _assemblyIdentity;
87                         }
88                 }
89
90                 [CLSCompliant (false)]
91                 public virtual ulong CurrentSize {
92                         get {
93                                 throw new InvalidOperationException (
94                                         Locale.GetText ("IsolatedStorage does not have a preset CurrentSize."));
95                         }
96                 }
97
98                 public object DomainIdentity {
99                         [SecurityPermission (SecurityAction.Demand, ControlPolicy=true)]
100                         get {
101                                 if ((storage_scope & IsolatedStorageScope.Domain) == 0) {
102                                         throw new InvalidOperationException (Locale.GetText ("Invalid Isolation Scope.")); 
103                                 }
104                                 if (_domainIdentity == null)
105                                         throw new InvalidOperationException (Locale.GetText ("Identity unavailable.")); 
106                                 return _domainIdentity;
107                         }
108                 }
109
110                 [CLSCompliant (false)]
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                 protected virtual char SeparatorExternal {
123                         get { return System.IO.Path.DirectorySeparatorChar; }
124                 }
125
126                 protected virtual char SeparatorInternal {
127                         get { return '.'; }
128                 }
129
130                 // Methods
131                 protected abstract IsolatedStoragePermission GetPermission (PermissionSet ps);
132
133                 protected void InitStore (IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
134                 {
135                         // I know it's useless - but it's tested as such...
136                         switch (scope) {
137                         case (IsolatedStorageScope.Assembly | IsolatedStorageScope.User):
138                         case (IsolatedStorageScope.Assembly | IsolatedStorageScope.User | IsolatedStorageScope.Domain):
139                                 throw new NotImplementedException (scope.ToString ());
140                         default:
141                                 // invalid (incomplete) scope
142                                 throw new ArgumentException (scope.ToString ());
143                         }
144                 }
145 #if NET_2_0
146                 [MonoTODO ("requires manifest support")]
147                 protected void InitStore (IsolatedStorageScope scope, Type appEvidenceType)
148                 {
149                         if (AppDomain.CurrentDomain.ApplicationIdentity == null)
150                                 throw new IsolatedStorageException (Locale.GetText ("No ApplicationIdentity available for AppDomain."));
151
152                         if (appEvidenceType == null) {
153                                 // TODO - Choose evidence
154                         }
155
156                         // no exception here because this can work without CAS
157                         storage_scope = scope;
158                 }
159 #endif
160                 public abstract void Remove ();
161         }
162 }
163 /* NET_2_1 */
164 #endif