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 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;
37 
38 namespace System.IO.IsolatedStorage {
39 
40 	[ComVisible (true)]
41 	public abstract class IsolatedStorage : MarshalByRefObject {
42 
43 		// Constructor
IsolatedStorage()44 		protected IsolatedStorage ()
45 			: base ()
46 		{
47 		}
48 
49                 internal IsolatedStorageScope storage_scope;
50 		internal object _assemblyIdentity;
51 		internal object _domainIdentity;
52 		internal object _applicationIdentity;
53 
54 		// Properties
55 
56 		[MonoTODO ("Does not currently use the manifest support")]
57 		[ComVisible (false)]
58 		public object ApplicationIdentity {
59 			[SecurityPermission (SecurityAction.Demand, ControlPolicy=true)]
60 			get {
61 				if ((storage_scope & IsolatedStorageScope.Application) == 0) {
62 					throw new InvalidOperationException (Locale.GetText ("Invalid Isolation Scope."));
63 				}
64 				if (_applicationIdentity == null)
65 					throw new InvalidOperationException (Locale.GetText ("Identity unavailable."));
66 
67 				throw new NotImplementedException (Locale.GetText ("CAS related"));
68 			}
69 		}
70 
71 		public object AssemblyIdentity {
72 			[SecurityPermission (SecurityAction.Demand, ControlPolicy=true)]
73 			get {
74 				if ((storage_scope & IsolatedStorageScope.Assembly) == 0) {
75 					throw new InvalidOperationException (Locale.GetText ("Invalid Isolation Scope."));
76 				}
77 				if (_assemblyIdentity == null)
78 					throw new InvalidOperationException (Locale.GetText ("Identity unavailable."));
79 				return _assemblyIdentity;
80 			}
81 		}
82 
83 		[CLSCompliant (false)]
84 		[Obsolete]
85 		public virtual ulong CurrentSize {
86 			get {
87 				throw new InvalidOperationException (
88 					Locale.GetText ("IsolatedStorage does not have a preset CurrentSize."));
89 			}
90 		}
91 
92 		public object DomainIdentity {
93 			[SecurityPermission (SecurityAction.Demand, ControlPolicy=true)]
94 			get {
95 				if ((storage_scope & IsolatedStorageScope.Domain) == 0) {
96 					throw new InvalidOperationException (Locale.GetText ("Invalid Isolation Scope."));
97 				}
98 				if (_domainIdentity == null)
99 					throw new InvalidOperationException (Locale.GetText ("Identity unavailable."));
100 				return _domainIdentity;
101 			}
102 		}
103 
104 		[CLSCompliant (false)]
105 		[Obsolete]
106 		public virtual ulong MaximumSize {
107 			get {
108 				throw new InvalidOperationException (
109 					Locale.GetText ("IsolatedStorage does not have a preset MaximumSize."));
110 			}
111 		}
112 
113 		public IsolatedStorageScope Scope {
114 			get { return storage_scope; }
115 		}
116 
117 		[ComVisible (false)]
118 		public virtual long AvailableFreeSpace {
119 			get {
120 				throw new InvalidOperationException ("This property is not defined for this store.");
121 			}
122 		}
123 
124 		[ComVisible (false)]
125 		public virtual long Quota {
126 			get {
127 				throw new InvalidOperationException ("This property is not defined for this store.");
128 			}
129 		}
130 
131 		[ComVisible (false)]
132 		public virtual long UsedSize {
133 			get {
134 				throw new InvalidOperationException ("This property is not defined for this store.");
135 			}
136 		}
137 
138 		protected virtual char SeparatorExternal {
139 			get { return System.IO.Path.DirectorySeparatorChar; }
140 		}
141 
142 		protected virtual char SeparatorInternal {
143 			get { return '.'; }
144 		}
145 
146 		// Methods
GetPermission(PermissionSet ps)147 		protected abstract IsolatedStoragePermission GetPermission (PermissionSet ps);
148 
InitStore(IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)149 		protected void InitStore (IsolatedStorageScope scope, Type domainEvidenceType, Type assemblyEvidenceType)
150 		{
151 			// I know it's useless - but it's tested as such...
152 			switch (scope) {
153 			case (IsolatedStorageScope.Assembly | IsolatedStorageScope.User):
154 			case (IsolatedStorageScope.Assembly | IsolatedStorageScope.User | IsolatedStorageScope.Domain):
155 				throw new NotImplementedException (scope.ToString ());
156 			default:
157 				// invalid (incomplete) scope
158 				throw new ArgumentException (scope.ToString ());
159 			}
160 		}
161 
162 		[MonoTODO ("requires manifest support")]
InitStore(IsolatedStorageScope scope, Type appEvidenceType)163 		protected void InitStore (IsolatedStorageScope scope, Type appEvidenceType)
164 		{
165 #if !MOBILE
166 			if (AppDomain.CurrentDomain.ApplicationIdentity == null)
167 				throw new IsolatedStorageException (Locale.GetText ("No ApplicationIdentity available for AppDomain."));
168 
169 			if (appEvidenceType == null) {
170 				// TODO - Choose evidence
171 			}
172 #endif
173 
174 			// no exception here because this can work without CAS
175 			storage_scope = scope;
176 		}
Remove()177 		public abstract void Remove ();
178 
179 		[ComVisible (false)]
IncreaseQuotaTo(long newQuotaSize)180 		public virtual bool IncreaseQuotaTo (long newQuotaSize)
181 		{
182 			return false;
183 		}
184 	}
185 }
186