本文整理汇总了C#中IHttpClient.DownloadData方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpClient.DownloadData方法的具体用法?C# IHttpClient.DownloadData怎么用?C# IHttpClient.DownloadData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpClient
的用法示例。
在下文中一共展示了IHttpClient.DownloadData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DownloadPackage
public void DownloadPackage(IHttpClient downloadClient, IPackageName package, Stream targetStream)
{
if (downloadClient == null)
{
throw new ArgumentNullException("downloadClient");
}
if (targetStream == null)
{
throw new ArgumentNullException("targetStream");
}
// Get the operation display text
string operation = String.Format(CultureInfo.CurrentCulture, NuGetResources.DownloadProgressStatus, package.Id, package.Version);
CurrentDownloadPackageId = package.Id;
EventHandler<ProgressEventArgs> progressAvailableHandler = (sender, e) =>
{
OnPackageDownloadProgress(new ProgressEventArgs(operation, e.PercentComplete));
};
try
{
downloadClient.ProgressAvailable += progressAvailableHandler;
downloadClient.SendingRequest += OnSendingRequest;
downloadClient.DownloadData(targetStream);
}
finally
{
downloadClient.ProgressAvailable -= progressAvailableHandler;
downloadClient.SendingRequest -= OnSendingRequest;
CurrentDownloadPackageId = null;
}
}
示例2: DownloadPackage
public IPackage DownloadPackage(IHttpClient downloadClient, IPackageMetadata package)
{
if (downloadClient == null)
{
throw new ArgumentNullException("downloadClient");
}
if (package == null)
{
throw new ArgumentNullException("package");
}
// Get the operation display text
string operation = String.Format(CultureInfo.CurrentCulture, NuGetResources.DownloadProgressStatus, package.Id, package.Version);
EventHandler<ProgressEventArgs> progressAvailableHandler = (sender, e) =>
{
OnPackageDownloadProgress(new ProgressEventArgs(operation, e.PercentComplete));
};
EventHandler<WebRequestEventArgs> beforeSendingRequesthandler = (sender, e) =>
{
OnSendingRequest(e.Request);
};
try
{
downloadClient.ProgressAvailable += progressAvailableHandler;
downloadClient.SendingRequest += beforeSendingRequesthandler;
// TODO: This gets held onto in memory which we want to get rid of eventually
byte[] buffer = downloadClient.DownloadData();
Func<Stream> streamFactory = () => new MemoryStream(buffer, writable: false);
return new ZipPackage(streamFactory, enableCaching: true);
}
finally
{
downloadClient.ProgressAvailable -= progressAvailableHandler;
downloadClient.SendingRequest -= beforeSendingRequesthandler;
}
}
示例3: DownloadPackage
public IPackage DownloadPackage(IHttpClient downloadClient, byte[] packageHash, IPackageMetadata package)
{
if (downloadClient == null)
{
throw new ArgumentNullException("downloadClient");
}
if (packageHash == null)
{
throw new ArgumentNullException("packageHash");
}
if (package == null)
{
throw new ArgumentNullException("package");
}
// Get the operation display text
string operation = String.Format(CultureInfo.CurrentCulture, NuGetResources.DownloadProgressStatus, package.Id, package.Version);
EventHandler<ProgressEventArgs> progressAvailableHandler = (sender, e) =>
{
OnPackageDownloadProgress(new ProgressEventArgs(operation, e.PercentComplete));
};
EventHandler<WebRequestEventArgs> beforeSendingRequesthandler = (sender, e) =>
{
OnSendingRequest(e.Request);
};
try
{
downloadClient.ProgressAvailable += progressAvailableHandler;
downloadClient.SendingRequest += beforeSendingRequesthandler;
// TODO: This gets held onto in memory which we want to get rid of eventually
byte[] buffer = downloadClient.DownloadData();
if (!_hashProvider.VerifyHash(buffer, packageHash))
{
throw new InvalidDataException(NuGetResources.PackageContentsVerifyError);
}
return _packageFactory.CreatePackage(() =>
{
return new MemoryStream(buffer);
});
}
finally
{
downloadClient.ProgressAvailable -= progressAvailableHandler;
downloadClient.SendingRequest -= beforeSendingRequesthandler;
}
}