public BeginWrite ( byte buffer, int offset, int numBytes, System userCallback, object stateObject ) : System.IAsyncResult | ||
buffer | byte | |
offset | int | |
numBytes | int | |
userCallback | System | |
stateObject | object | |
return | System.IAsyncResult |
public void ReadOnly () { IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication (); try { using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream ("read-only", FileMode.Create, FileAccess.Write, isf)) { fs.WriteByte (0); } // now we open it read-only using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream ("read-only", FileMode.Open, FileAccess.Read, isf)) { Assert.Throws (delegate { fs.WriteByte (0); }, typeof (NotSupportedException), "WriteByte"); Assert.Throws (delegate { fs.Write (new byte [0], 0, 0); }, typeof (NotSupportedException), "Write"); Assert.Throws (delegate { fs.BeginWrite (new byte [0], 0, 0, null, null); }, typeof (NotSupportedException), "BeginWrite"); } } finally { isf.DeleteFile ("read-only"); } }
public void AsyncEndWrite_Disposed () { IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication (); using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream ("moon", FileMode.Create, isf)) { byte [] data = new byte [2]; KeyValuePair<IsolatedStorageFile, IsolatedStorageFileStream> kvp = new KeyValuePair<IsolatedStorageFile, IsolatedStorageFileStream> (isf, fs); IAsyncResult result = fs.BeginWrite (data, 0, 2, new AsyncCallback (EndWriteDisposed), kvp); result.AsyncWaitHandle.WaitOne (); } }
public void AsyncWrite () { IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication (); using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream ("moon", FileMode.Create, isf)) { byte[] data = new byte [2]; IAsyncResult result = fs.BeginWrite (data, 0, 2, new AsyncCallback (EndWrite), fs); result.AsyncWaitHandle.WaitOne (); isf.Remove (); // this removed everything Assert.Throws (delegate { fs.BeginWrite (data, 0, 2, new AsyncCallback (EndWrite), fs); }, typeof (IsolatedStorageException), "Remove/Write"); // Fails in Silverlight 3 isf.Dispose (); Assert.Throws (delegate { fs.BeginWrite (data, 0, 2, new AsyncCallback (EndWrite), fs); }, typeof (ObjectDisposedException), "Dispose/Write"); } isf = IsolatedStorageFile.GetUserStoreForApplication (); Assert.AreEqual (0, isf.GetFileNames ().Length, "Empty"); }
public void AsyncEndWrite_Removed () { IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication (); isf.Remove (); isf = IsolatedStorageFile.GetUserStoreForApplication (); Assert.AreEqual (0, isf.GetFileNames ().Length, "pre-check"); using (IsolatedStorageFileStream fs = new IsolatedStorageFileStream ("moon", FileMode.Create, isf)) { byte [] data = new byte [2]; KeyValuePair<IsolatedStorageFile, IsolatedStorageFileStream> kvp = new KeyValuePair<IsolatedStorageFile, IsolatedStorageFileStream> (isf, fs); IAsyncResult result = fs.BeginWrite (data, 0, 2, new AsyncCallback (EndWriteRemoved), kvp); result.AsyncWaitHandle.WaitOne (); } }
public void AsyncWrite () { IsolatedStorageFileStream isfs = new IsolatedStorageFileStream ("cas-AsyncWrite", FileMode.Create); message = "AsyncWrite"; reset.Reset (); IAsyncResult r = isfs.BeginWrite (new byte[0], 0, 0, new AsyncCallback (WriteCallback), isfs); Assert.IsNotNull (r, "IAsyncResult"); if (!reset.WaitOne (timeout, true)) Assert.Ignore ("Timeout"); Assert.IsNull (message, message); isfs.Close (); }