IsolatedStorage.cs 5.0 KB

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