Example #1
0
        public async Task <AsyncDownloaderOutput <byte[]> > GetData(string url, Action <DownloadProgressChangedEventArgs> report = null)
        {
            try
            {
                using (var webClient = new WebClient())
                {
                    webClient.DownloadProgressChanged += (s, e) => report?.Invoke(e);

                    var data = await webClient.DownloadDataTaskAsync(new Uri(url));

                    var output = new AsyncDownloaderOutput <byte[]>(data);
                    return(output);
                }
            }
            catch (Exception ex)
            {
                return(new AsyncDownloaderOutput <byte[]>(ex));
            }
        }
Example #2
0
        /// <summary>
        /// stazeni pouze casti zdrojoveho souboru (musi podporovat server na druhe strane)
        /// </summary>
        public async Task <AsyncDownloaderOutput <Stream> > GetDataRange(string url, long?rangeFrom, long?rangeTo)
        {
            try
            {
                using (var client = new HttpClient())
                {
                    client.DefaultRequestHeaders.Range = new RangeHeaderValue(rangeFrom, rangeTo);

                    var response = await client.GetAsync(url);

                    response.EnsureSuccessStatusCode();
                    var responseStream = await response.Content.ReadAsStreamAsync();

                    var output = new AsyncDownloaderOutput <Stream>(responseStream);
                    return(output);
                }
            }
            catch (Exception ex)
            {
                return(new AsyncDownloaderOutput <Stream>(ex));
            }
        }