Exemple #1
0
        public string DownloadString(Uri url, TimeSpan timeout)
        {
            using (FactoryLease <WebClientEx> webClient =
                       new FactoryLease <WebClientEx>(webClientFactory.CreateInnerWebClient(), webClientFactory))
            {
                ConfigureWebClient(webClient.Obj, timeout);

                try
                {
                    return(webClient.Obj.DownloadString(url));
                }
                catch (WebException ex)
                {
                    Log(
                        true,
                        "DownloadString (url='{0}') failed. Reason : {1}",
                        url,
                        ex);
                    throw;
                }
            }
        }
Exemple #2
0
        public byte[] UploadData(Uri url, string method, byte[] data, TimeSpan timeout)
        {
            using (FactoryLease <WebClientEx> webClient =
                       new FactoryLease <WebClientEx>(webClientFactory.CreateInnerWebClient(), webClientFactory))
            {
                ConfigureWebClient(webClient.Obj, timeout);

                try
                {
                    return(webClient.Obj.UploadData(url, method, data));
                }
                catch (WebException ex)
                {
                    Log(
                        true,
                        "UploadData (url='{0}') failed. Reason : {1}",
                        url,
                        ex);
                    throw;
                }
            }
        }
Exemple #3
0
        public void DownloadFile(Uri url, TimeSpan timeout, string localPath)
        {
            using (FactoryLease <WebClientEx> webClient =
                       new FactoryLease <WebClientEx>(webClientFactory.CreateInnerWebClient(), webClientFactory))
            {
                ConfigureWebClient(webClient.Obj, timeout);

                try
                {
                    fileSystem.EnsureDirectoryExists(Path.GetDirectoryName(localPath));
                    webClient.Obj.DownloadFile(url, localPath);
                }
                catch (WebException ex)
                {
                    Log(
                        true,
                        "DownloadFile (url='{0}') failed. Reason : {1}",
                        url,
                        ex);
                    throw;
                }
            }
        }