本文整理汇总了C#中Package.Download方法的典型用法代码示例。如果您正苦于以下问题:C# Package.Download方法的具体用法?C# Package.Download怎么用?C# Package.Download使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Package
的用法示例。
在下文中一共展示了Package.Download方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DownloadPackage
private static void DownloadPackage(Package package, int index, int count)
{
var http_response = package.Download ();
if (http_response == null) {
throw new IOException ();
}
Directory.CreateDirectory (Path.GetDirectoryName (package.RelativeLocation));
File.Delete (package.RelativeLocation);
var xfer_stats = new RepoTransferStatistics () {
Label = package.Name,
Index = index,
Count = count,
TotalSize = http_response.ContentLength
};
using (var http_stream = http_response.GetResponseStream ()) {
using (var file_stream = File.OpenWrite (package.RelativeLocation)) {
http_stream.TransferTo (file_stream,
(total_read, final_block, block, block_size) =>
xfer_stats.CommitNewBlock (block, block_size, final_block));
}
File.SetCreationTime (package.RelativeLocation, package.FileTime);
File.SetLastWriteTime (package.RelativeLocation, package.FileTime);
File.SetLastAccessTime (package.RelativeLocation, package.FileTime);
}
}