protected byte[] DownloadCacheFile(IFileInfo target, IDocument remoteDocument, Transmission transmission, IFileSystemInfoFactory fsFactory) {
if (!this.LoadCacheFile(target, remoteDocument, fsFactory)) {
if (target.Exists) {
target.Delete();
}
}
using (var hashAlg = new SHA1Reuse()) {
using (var filestream = target.Open(FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
using (var downloader = ContentTaskUtils.CreateDownloader()) {
try {
downloader.DownloadFile(remoteDocument, filestream, transmission, hashAlg, (byte[] checksumUpdate, long length) => this.SaveCacheFile(target, remoteDocument, checksumUpdate, length, transmission));
if (this.TransmissionStorage != null) {
this.TransmissionStorage.RemoveObjectByRemoteObjectId(remoteDocument.Id);
}
} catch (Exception ex) {
transmission.FailedException = ex;
throw;
}
}
target.Refresh();
return hashAlg.Hash;
}
}