void BytesReceived(object sender, SecureTransfer.BytesReceivedEventArgs e) { string path = GetPath(e.TransferId, e.Location); using(Stream io = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) { byte[] bytes = e.BytesReceived; Check.Assert<InvalidDataException>(io.Length >= e.WriteOffset + bytes.Length); io.Position = e.WriteOffset; io.Write(bytes, 0, bytes.Length); } }
void CompleteTransfer(object sender, SecureTransfer.CompleteTransferEventArgs e) { string path = GetPath(e.TransferId, e.Location); using (Stream io = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None)) { Hash uploaded = Hash.FromBytes(e.ContentHash.CreateAlgorithm().ComputeHash(io)); Check.Assert<InvalidDataException>(e.ContentHash.Equals(uploaded)); } int ix = 1; string pathname = Path.Combine(_content.StoragePath, FileUtils.MakeValidFileName(Path.GetFileNameWithoutExtension(e.Location))); string originalPath = pathname; while (Directory.Exists(pathname)) { pathname = String.Format("{0}({1})", originalPath, ix++); } string filename = GetPath(e.TransferId, e.Location); using (ZipFile zip = new ZipFile(filename)) zip.ExtractAll(pathname); File.WriteAllText(Path.Combine(_content.StoragePath, "version"), Path.GetFileName(pathname)); _content.ChangeStorage(new ContentStorage(pathname, true)); }
void BeginTransfer(object sender, SecureTransfer.BeginTransferEventArgs e) { string path = GetPath(e.TransferId, e.Location); using (Stream io = new FileStream(path, FileMode.CreateNew, FileAccess.Write, FileShare.ReadWrite)) { io.SetLength(e.TotalSize); } }