IsolatedStorage.cs 4.9 KB

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