IsolatedStorage.cs 5.7 KB

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