示例#1
0
        public async virtual Task <FileInfo> DownloadFileTaskAsync(string url, string fileName = "")
        {
            var ticker = _setting.GetTickerFromUrl(url);

            fileName = fileName == string.Empty ? _setting.GetFileName(ticker.TrimStart(new char[] { '^' })) : fileName;
            var request       = new HttpRequestMessage(HttpMethod.Get, url);
            var contentStream = await(await _httpClient.Value.SendAsync(request)).Content.ReadAsStreamAsync();

            using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None, 4096, true))
            {
                await contentStream.CopyToAsync(fileStream);
            }
            return(new FileInfo(fileName));
        }