Exemplo n.º 1
0
        /// <summary>
        /// Downloads the object.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns><c>DownloadResponse</c> response.</returns>
        /// <exception cref="StorageException">if file downloading failed.</exception>
        public DownloadResponse DownloadObject(Uri uri)
        {
            CheckUri(uri);

            try
            {
                var ftpRequest = CreateFtpRequest(uri.ToString());
                ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;

                var response         = ftpRequest.GetResponse();
                var downloadResponse = new DownloadResponse {
                    Uri = uri
                };

                using (var responseStream = response.GetResponseStream())
                {
                    downloadResponse.ResponseStream = new MemoryStream();
                    responseStream.CopyTo(downloadResponse.ResponseStream);
                }

                return(downloadResponse);
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to download object from {0}.", uri), e);
            }
        }
Exemplo n.º 2
0
        public DownloadResponse DownloadObject(Uri uri)
        {
            CheckUri(uri);

            try
            {
                var request = (HttpWebRequest)WebRequest.Create(uri);
                var response = request.GetResponse();
                var downloadResponse = new DownloadResponse();
                downloadResponse.Uri = uri;

                using (var responseStream = response.GetResponseStream())
                {
                    downloadResponse.ResponseStream = new MemoryStream();
                    if (responseStream != null)
                    {
                        responseStream.CopyTo(downloadResponse.ResponseStream);
                    }
                }

                return downloadResponse;
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to download object from {0}.", uri), e);
            }
        }
Exemplo n.º 3
0
        public DownloadResponse DownloadObject(Uri uri)
        {
            CheckUri(uri);

            DownloadResponse downloadResponse = new DownloadResponse();
            downloadResponse.Uri = uri;

            using (FileStream writeStream = new FileStream(uri.LocalPath, FileMode.Open, FileAccess.Read))
            {
                downloadResponse.ResponseStream = new MemoryStream();
                writeStream.CopyTo(downloadResponse.ResponseStream);
                downloadResponse.ResponseStream.Seek(0, SeekOrigin.Begin);

                writeStream.Flush();
                writeStream.Close();
            }

            return downloadResponse;
        }
Exemplo n.º 4
0
        public DownloadResponse DownloadObject(Uri uri)
        {
            CheckUri(uri);

            var downloadResponse = new DownloadResponse();

            downloadResponse.Uri = uri;

            using (FileStream writeStream = new FileStream(uri.LocalPath, FileMode.Open, FileAccess.Read))
            {
                downloadResponse.ResponseStream = new MemoryStream();
                writeStream.CopyTo(downloadResponse.ResponseStream);
                downloadResponse.ResponseStream.Seek(0, SeekOrigin.Begin);

                writeStream.Flush();
                writeStream.Close();
            }

            return(downloadResponse);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Downloads the object.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns><c>DownloadResponse</c> response.</returns>
        /// <exception cref="StorageException">if file downloading failed.</exception>
        public DownloadResponse DownloadObject(Uri uri)
        {
            CheckUri(uri);

            try
            {
                var ftpRequest = CreateFtpRequest(uri.ToString());
                ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;

                var response = ftpRequest.GetResponse();
                var downloadResponse = new DownloadResponse { Uri = uri };

                using (var responseStream = response.GetResponseStream())
                {
                    downloadResponse.ResponseStream = new MemoryStream();
                    responseStream.CopyTo(downloadResponse.ResponseStream);
                }

                return downloadResponse;
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to download object from {0}.", uri), e);
            }
        }
        public DownloadResponse DownloadObject(Uri uri)
        {
            CheckUri(uri);

            try
            {
                var timeoutMs = timeout.TotalMilliseconds <= Int32.MaxValue ? Convert.ToInt32(timeout.TotalMilliseconds) : Int32.MaxValue;

                var request = (HttpWebRequest)WebRequest.Create(uri);
                request.Timeout = timeoutMs;
                request.ReadWriteTimeout = timeoutMs;

                var response = request.GetResponse();
                var downloadResponse = new DownloadResponse();
                downloadResponse.Uri = uri;

                using (var responseStream = response.GetResponseStream())
                {
                    downloadResponse.ResponseStream = new MemoryStream();
                    if (responseStream != null)
                    {
                        responseStream.CopyTo(downloadResponse.ResponseStream);
                    }
                }

                return downloadResponse;
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to download object from {0}.", uri), e);
            }
        }