in e2etest/GuestProxyAgentTest/Utilities/TestCommonUtilities.cs [68:101]
public static bool DownloadFile(string url, string filePath, Action<string> logger = null!, int retryCnt = 5)
{
if (null == url || url.Length == 0)
{
return false;
}
int cnt = 0;
while (cnt < retryCnt)
{
cnt++;
try
{
if (File.Exists(filePath))
{
File.Delete(filePath);
}
using var client = new HttpClient();
var res = client.GetAsync(url).Result;
res.EnsureSuccessStatusCode();
using var fileStream = File.Create(filePath);
res.Content.CopyToAsync(fileStream).Wait();
return true;
}
catch (Exception ex)
{
var errMessage = string.Format("Download file failed, attempted: {0} times, exception: {1}", cnt, ex.ToString());
logger?.Invoke(errMessage);
}
}
return false;
}