public static System.IO.Stream FileDownload(System.Uri location, System.Net.NetworkCredential credential = null)
        {
            if (false == location.Scheme.StartsWith(System.Uri.UriSchemeFile, System.StringComparison.InvariantCultureIgnoreCase))
            {
                throw new System.ArgumentException("Must start with System.Uri.UriSchemeFile", "location.Scheme");
            }

            using (DownloadAdapter d = DownloadAdapter.WebClientDownload(location, credential))
                return(d.ResponseOutputStream);
        }
Exemple #2
0
        public void MapperShouldFillAllNonOptionalValues()
        {
            var adapter = new DownloadAdapter();
            var mapper  = new Mapper();
            var config  = new Configuration();

            config[$"{adapter.Id.ToString().ToLower()}.in.url"] = "http://www.google.com";
            mapper.SetValues(adapter, config);

            Assert.Equal(adapter.Url, "http://www.google.com");
        }
Exemple #3
0
        public async Task DownloadGoogleComShouldWork()
        {
            var dlAdapter = new DownloadAdapter();

            dlAdapter.Url = "http://www.google.com";
            var adapterTask = dlAdapter.Start();

            await adapterTask;

            Assert.True(dlAdapter.Finished);

            var result = await dlAdapter.GetResult();

            Assert.True(File.Exists(result));
        }
            public static DownloadAdapter WebClientDownload(System.Uri location, System.Net.NetworkCredential credential = null)
            {
                if (location == null)
                {
                    throw new System.ArgumentNullException("location");
                }

                using (WebClientEx webClient = new WebClientEx(location))
                {
                    if (credential != null)
                    {
                        webClient.Credentials = credential;
                    }

                    using (var d = new DownloadAdapter(location)
                    {
                        Request = webClient,
                        ResponseOutputStream = webClient.ResponseStream
                    })
                    {
                        if (webClient.ResponseHeaders != null)
                        {
                            string contentLength = webClient.ResponseHeaders["Content-Length"];

                            if (false == string.IsNullOrWhiteSpace(contentLength))
                            {
                                long.TryParse(contentLength, out d.MaximumLength);
                            }

                            contentLength = null;
                        }

                        return(d);
                    }
                }
            }
        //Useful for Ftp and other types not supported by HttpClient.

        public static System.IO.Stream WebClientDownload(System.Uri location, System.Net.NetworkCredential credential = null)
        {
            using (DownloadAdapter d = DownloadAdapter.WebClientDownload(location, credential))
                return(d.ResponseOutputStream);
        }