IsolatedStorage.cs 5.6 KB

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