public string Download(string filename, IDownloadNotificator notificator)
 {
     var sourcePath = Path.Combine(configuration.UpdatesLocation, filename);
     var targetPath = Path.Combine(Path.GetTempPath(), filename);
     File.Copy(sourcePath, targetPath, true);
     return targetPath;
 }
示例#2
0
        public string Download(string filename, IDownloadNotificator notificator)
        {
            var sourcePath = Path.Combine(configuration.UpdatesLocation, filename);
            var targetPath = Path.Combine(Path.GetTempPath(), filename);

            File.Copy(sourcePath, targetPath, true);
            return(targetPath);
        }
示例#3
0
        public void Download(string remoteFilename, string localFilename, IDownloadNotificator notificator)
        {
            FtpWebResponse response1 = null;
            FtpWebResponse response2 = null;
            FileStream outputStream = null;
            Stream responseStream = null;

            log.DebugFormat("Downloading file {0} with local name {1} from {2}", remoteFilename, localFilename, serverUri);

            try
            {
                var remoteFileUri = serverUri + remoteFilename;

                var request1 = (FtpWebRequest) WebRequest.Create(remoteFileUri);
                request1.Method = WebRequestMethods.Ftp.GetFileSize;
                response1 = (FtpWebResponse) request1.GetResponse();
                long fileSize = response1.ContentLength;

                var request2 = (FtpWebRequest)WebRequest.Create(remoteFileUri);
                request2.Method = WebRequestMethods.Ftp.DownloadFile;
                request2.UseBinary = true;

                response2 = (FtpWebResponse)request2.GetResponse();
                responseStream = response2.GetResponseStream();

                outputStream = File.Create(localFilename);
                var buffer = new byte[1024];
                while (true)
                {
                    int bytesRead = responseStream.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                        break;
                    outputStream.Write(buffer, 0, bytesRead);

                    notificator.UpdateProgress((int) (outputStream.Position*100/fileSize));
                }

                notificator.Complete();
            }
            catch (WebException ex)
            {
                log.Warn("Cannot download update", ex);
                throw new UpdatesProviderInaccessibleException("Cannot download update", ex);
            }
            finally
            {
                if (response1 != null) response1.Close();
                if (response2 != null) response2.Close();
                if (outputStream != null) outputStream.Close();
                if (responseStream != null) responseStream.Close();
            }
        }
示例#4
0
        public string Download(string filename, IDownloadNotificator notificator)
        {
            var localDirectory = string.IsNullOrEmpty(configuration.LocalDirectory) == false
                                 	? configuration.LocalDirectory
                                 	: Path.GetTempPath();

            var localFilename = Path.Combine(localDirectory, filename);
            if (File.Exists(localFilename))
                File.Delete(localFilename);

            notificator.Show();

            ThreadPool.QueueUserWorkItem(x => ftp.Download(filename, localFilename, notificator));

            notificator.WaitForCompletition();

            notificator.Close();

            return localFilename;
        }
示例#5
0
        public string Download(string filename, IDownloadNotificator notificator)
        {
            var localDirectory = string.IsNullOrEmpty(configuration.LocalDirectory) == false
                                                ? configuration.LocalDirectory
                                                : Path.GetTempPath();

            var localFilename = Path.Combine(localDirectory, filename);

            if (File.Exists(localFilename))
            {
                File.Delete(localFilename);
            }

            notificator.Show();

            ThreadPool.QueueUserWorkItem(x => ftp.Download(filename, localFilename, notificator));

            notificator.WaitForCompletition();

            notificator.Close();

            return(localFilename);
        }
示例#6
0
        public void Download(string remoteFilename, string localFilename, IDownloadNotificator notificator)
        {
            FtpWebResponse response1      = null;
            FtpWebResponse response2      = null;
            FileStream     outputStream   = null;
            Stream         responseStream = null;

            log.DebugFormat("Downloading file {0} with local name {1} from {2}", remoteFilename, localFilename, serverUri);

            try
            {
                var remoteFileUri = serverUri + remoteFilename;

                var request1 = (FtpWebRequest)WebRequest.Create(remoteFileUri);
                request1.Method = WebRequestMethods.Ftp.GetFileSize;
                response1       = (FtpWebResponse)request1.GetResponse();
                long fileSize = response1.ContentLength;

                var request2 = (FtpWebRequest)WebRequest.Create(remoteFileUri);
                request2.Method    = WebRequestMethods.Ftp.DownloadFile;
                request2.UseBinary = true;

                response2      = (FtpWebResponse)request2.GetResponse();
                responseStream = response2.GetResponseStream();

                outputStream = File.Create(localFilename);
                var buffer = new byte[1024];
                while (true)
                {
                    int bytesRead = responseStream.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                    {
                        break;
                    }
                    outputStream.Write(buffer, 0, bytesRead);

                    notificator.UpdateProgress((int)(outputStream.Position * 100 / fileSize));
                }

                notificator.Complete();
            }
            catch (WebException ex)
            {
                log.Warn("Cannot download update", ex);
                throw new UpdatesProviderInaccessibleException("Cannot download update", ex);
            }
            finally
            {
                if (response1 != null)
                {
                    response1.Close();
                }
                if (response2 != null)
                {
                    response2.Close();
                }
                if (outputStream != null)
                {
                    outputStream.Close();
                }
                if (responseStream != null)
                {
                    responseStream.Close();
                }
            }
        }