protected override void Dispose(bool disposing) { if (tempStream != null) lock (this) { tempStream.Dispose(); tempStream = null; try { System.IO.File.Delete(tempFile); } catch { } tempFile = null; } if (disposing) { if (hash != null) ((IDisposable)hash).Dispose(); hash = null; connection = null; //cryptBuffer = null; } base.Dispose(disposing); }
public FileSystemCasBlobWriter(FileSystemCasConnection connection) { if (connection == null) throw new ArgumentNullException("connection"); this.connection = connection; hash = connection.hashName == null ? new SHA1CryptoServiceProvider() : HashAlgorithm.Create(connection.hashName); if (hash == null) throw new Exception("Missing hash algorithm: " + connection.hashName); Random r = new Random(); string temp; int i = 0; do { if (i > 100) throw new Exception("Unable to find a random temporary filename for writing."); temp = Path.Combine(connection.path, FileSystemCasConnection.TEMPFILEBASE + r.Next().ToString("x")); i++; } while (File.Exists(temp)); tempStream = new FileStream(temp, FileMode.Create, FileAccess.Write, FileShare.None); tempFile = temp; }