2008-08-20 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Wed, 20 Aug 2008 15:40:21 +0000 (15:40 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Wed, 20 Aug 2008 15:40:21 +0000 (15:40 -0000)
* MoonIsolatedStorageFile.cs: Fix API to match SL2 beta2. Start
implementing new feature (while writing unit tests).
* MoonIsolatedStorageFileStream.cs: Add new async methods [Begin|
End][Read|Write] present in b2. Fix endless recursion in WriteByte.

svn path=/trunk/mcs/; revision=111152

mcs/class/corlib/System.IO.IsolatedStorage/ChangeLog
mcs/class/corlib/System.IO.IsolatedStorage/MoonIsolatedStorageFile.cs
mcs/class/corlib/System.IO.IsolatedStorage/MoonIsolatedStorageFileStream.cs

index 3b25384a43342c1bd17d4a40e5340f86bbd56b6c..7da3855f522c36dd2270d264c204a74c24f36eb0 100644 (file)
@@ -1,3 +1,10 @@
+2008-08-20  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * MoonIsolatedStorageFile.cs: Fix API to match SL2 beta2. Start
+       implementing new feature (while writing unit tests).
+       * MoonIsolatedStorageFileStream.cs: Add new async methods [Begin|
+       End][Read|Write] present in b2. Fix endless recursion in WriteByte.
+
 2008-04-18  Sebastien Pouliot  <sebastien@ximian.com>
 
        * IsolatedStorageFile.cs: Fix CreateDirectory to accept multiple 
index 35757cac367fbf2aaaf03a4ec3d38062186eb813..67ba3689cf099e6a77993c5e07067d7c709e315a 100644 (file)
@@ -6,7 +6,7 @@
 // Authors
 //      Miguel de Icaza (miguel@novell.com)
 //
-// Copyright (C) 2007 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2007, 2008 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -50,7 +50,7 @@ namespace System.IO.IsolatedStorage {
                static IsolatedStorageFile ()
                {
                         string xdg_data_home = Environment.GetEnvironmentVariable ("XDG_DATA_HOME");
-                        if (xdg_data_home == null || xdg_data_home == String.Empty){
+                        if (String.IsNullOrEmpty (xdg_data_home)) {
                                 xdg_data_home = Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);
                         }
 
@@ -72,11 +72,22 @@ namespace System.IO.IsolatedStorage {
                        }
                }
 
+
+               private bool removed = false;
+               private bool disposed = false;
+
                internal IsolatedStorageFile (string basedir)
                {
                }
                
-               [SecuritySafeCritical]
+               internal void PreCheck ()
+               {
+                       if (disposed)
+                               throw new ObjectDisposedException ("Storage was disposed");
+                       if (removed)
+                               throw new IsolatedStorageException ("Storage was removed");
+               }
+
                public static IsolatedStorageFile GetUserStoreForApplication ()
                {
                        if (appdir == null)
@@ -85,6 +96,14 @@ namespace System.IO.IsolatedStorage {
                        return new IsolatedStorageFile (appdir);
                }
 
+               public static IsolatedStorageFile GetUserStoreForSite ()
+               {
+                       if (appdir == null)
+                               throw new SecurityException ();
+                       
+                       return new IsolatedStorageFile (appdir);
+               }
+
                internal static string Verify (string path)
                {
                        try {
@@ -97,21 +116,47 @@ namespace System.IO.IsolatedStorage {
                        throw new IsolatedStorageException ();
                }
                
-               [SecuritySafeCritical]
                public void CreateDirectory (string dir)
                {
                        Verify (dir);
                        Directory.CreateDirectory (dir);
-               }    
+               }
+
+               public IsolatedStorageFileStream CreateFile (string path)
+               {
+                       PreCheck ();
+                       if (path == null)
+                               throw new ArgumentNullException ("path");
+
+                       return new IsolatedStorageFileStream (path, FileMode.Create, this);
+               }
                
-               [SecuritySafeCritical]
                public void DeleteDirectory (string dir)
                {
+                       PreCheck ();
                        Verify (dir);
                        Directory.Delete (dir);
                }
 
-               [SecuritySafeCritical]
+               public bool DirectoryExists (string path)
+               {
+                       PreCheck ();
+                       Verify (path);
+                       return Directory.Exists (path);
+               }
+
+               public bool FileExists (string path)
+               {
+                       PreCheck ();
+                       Verify (path);
+                       return File.Exists (path);
+               }
+
+               public string [] GetDirectoryNames ()
+               {
+                       return Directory.GetFiles (appdir);
+               }
+
                public string [] GetDirectoryNames (string searchPattern)
                {
                        if (searchPattern.IndexOf ('/') != -1)
@@ -120,43 +165,82 @@ namespace System.IO.IsolatedStorage {
                        return Directory.GetDirectories (appdir, searchPattern);
                }
 
-               [SecuritySafeCritical]
+               public string [] GetFileNames ()
+               {
+                       return Directory.GetFiles (appdir);
+               }
+
                public string [] GetFileNames (string searchPattern)
                {
                        if (searchPattern.IndexOf ('/') != -1)
                                throw new IsolatedStorageException ();
                        
-                       return Directory.GetDirectories (appdir, searchPattern);
+                       return Directory.GetFiles (appdir, searchPattern);
                }
 
-               [SecuritySafeCritical]
                public void DeleteFile (string file)
                {
                        Verify (file);
+                       File.Delete (file);
                }
                
                public void Dispose ()
                {
+                       disposed = true;
+               }
+
+               public IsolatedStorageFileStream OpenFile (string path, FileMode mode)
+               {
+                       return OpenFile (path, mode, FileAccess.ReadWrite, FileShare.None);
+               }
+
+               public IsolatedStorageFileStream OpenFile (string path, FileMode mode, FileAccess access)
+               {
+                       return OpenFile (path, mode, access, FileShare.None);
                }
 
-               [SecuritySafeCritical]
-               public void Close ()
+               public IsolatedStorageFileStream OpenFile (string path, FileMode mode, FileAccess access, FileShare share)
                {
+                       PreCheck ();
+                       if (path == null)
+                               throw new ArgumentNullException ("path");
+
+                       return new IsolatedStorageFileStream (path, mode, access, share, this);
+               }
+
+               public void Remove ()
+               {
+                       PreCheck ();
+                       try {
+                               // TODO - try to clean out everything
+                       }
+                       finally {
+                               removed = true;
+                       }
                }
 
-               [CLSCompliant(false)]
-               public ulong CurrentSize {
+               public long AvailableFreeSpace {
                        get {
-                               return 0;
+                               PreCheck ();
+                               return 1024*1024;
                        }
                }
 
-               [CLSCompliant(false)]
-               public ulong MaximumSize {
+               public long Quota {
                        get {
+                               PreCheck ();
                                return 1024*1024;
                        }
                }
+
+               public bool IncreaseQuotaTo (long newQuotaSize)
+               {
+                       PreCheck ();
+                       if (newQuotaSize <= Quota)
+                               throw new ArgumentException ("newQuotaSize", "Only increase is possible");
+
+                       return true;
+               }
        }
 }
-#endif
\ No newline at end of file
+#endif
index fe222b0830582929ddda7f06d816abaa27bad69f..0d80d2ceb8eb2fba40e3e04eefb40fa48a965584 100644 (file)
@@ -91,7 +91,7 @@ namespace System.IO.IsolatedStorage {
 
                public override void WriteByte (byte value)
                {
-                       WriteByte (value);
+                       base.WriteByte (value);
                }
 
                public override bool CanRead {
@@ -133,6 +133,26 @@ namespace System.IO.IsolatedStorage {
                                base.Position = value;
                        }
                }
+
+               public override IAsyncResult BeginRead (byte[] buffer, int offset, int numBytes, AsyncCallback userCallback, object stateObject)
+               {
+                       return base.BeginRead (buffer, offset, numBytes, userCallback, stateObject);
+               }
+
+               public override IAsyncResult BeginWrite (byte[] buffer, int offset, int numBytes, AsyncCallback userCallback, object stateObject)
+               {
+                       return base.BeginWrite (buffer, offset, numBytes, userCallback, stateObject);
+               }
+
+               public override int EndRead (IAsyncResult asyncResult)
+               {
+                       return base.EndRead (asyncResult);
+               }
+
+               public override void EndWrite (IAsyncResult asyncResult)
+               {
+                       base.EndWrite (asyncResult);
+               }
        }
 }
-#endif
\ No newline at end of file
+#endif