Exemple #1
0
        private void DownloadInternal(IProgress <ProgressChangedEventArgs> progress)
        {
            Debug.Assert(Prefs != null);

            lock (DownloadSyncRoot)
            {
                if (!CheckLastDownloadTime())
                {
                    return;
                }

                Logger.Info("Downloading new project data from Stanford...");

                IWebOperation httpWebOperation = WebOperation.Create(Prefs.Get <string>(Preference.ProjectDownloadUrl));
                if (progress != null)
                {
                    httpWebOperation.ProgressChanged += (sender, e) =>
                    {
                        int    progressPercentage = Convert.ToInt32((e.Length / (double)e.TotalLength) * 100);
                        string message            = String.Format(CultureInfo.InvariantCulture, "Downloading {0} of {1} bytes...", e.Length, e.TotalLength);
                        progress.Report(new ProgressChangedEventArgs(progressPercentage, message));
                    };
                }
                httpWebOperation.WebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
                httpWebOperation.WebRequest.Proxy       = Prefs.GetWebProxy();
                httpWebOperation.Download(FilePath);

                LastDownloadTime = DateTime.Now;
            }
        }
Exemple #2
0
        public ApplicationUpdate CheckForUpdate(string applicationId, string updateUrl, IWebProxy proxy)
        {
            string localFilePath = Path.Combine(Path.GetTempPath(), String.Concat(applicationId, ApplicationUpdateXml));

            IWebOperation web = WebOperation.Create(updateUrl);

            if (proxy != null)
            {
                web.WebRequest.Proxy = proxy;
            }
            web.WebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
            web.Download(localFilePath);
            return(ApplicationUpdateSerializer.DeserializeFromXml(localFilePath));
        }
Exemple #3
0
        /// <summary>
        /// Download a File via Ftp.
        /// </summary>
        /// <param name="ftpWebOperation">Web Operation.</param>
        /// <param name="localFilePath">Path to local file.</param>
        /// <param name="username">Ftp Login Username.</param>
        /// <param name="password">Ftp Login Password.</param>
        /// <param name="ftpMode">Ftp Transfer Mode.</param>
        /// <exception cref="ArgumentNullException">Throws if ftpWebOperation is null.</exception>
        /// <exception cref="ArgumentException">Throws if localFilePath is null or empty.</exception>
        public void FtpDownloadHelper(IWebOperation ftpWebOperation, string localFilePath, string username, string password, FtpMode ftpMode)
        {
            if (ftpWebOperation == null)
            {
                throw new ArgumentNullException("ftpWebOperation");
            }
            if (String.IsNullOrEmpty(localFilePath))
            {
                throw new ArgumentException("Argument 'localFilePath' cannot be a null or empty string.");
            }

            ftpWebOperation.WebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
            ((IFtpWebRequest)ftpWebOperation.WebRequest).SetFtpMode(ftpMode);

            ftpWebOperation.WebRequest.SetNetworkCredentials(username, password);
            ftpWebOperation.Download(localFilePath);
        }
        /// <summary>
        /// Downloads the project information.
        /// </summary>
        /// <remarks>Access to the Download method is synchronized.</remarks>
        public void Download(Stream stream, IProgress <ProgressInfo> progress)
        {
            IWebOperation httpWebOperation = WebOperation.Create(_prefs.Get <string>(Preference.ProjectDownloadUrl));

            if (progress != null)
            {
                httpWebOperation.ProgressChanged += (sender, e) =>
                {
                    int    progressPercentage = Convert.ToInt32(e.Length / (double)e.TotalLength * 100);
                    string message            = String.Format(CultureInfo.CurrentCulture, "Downloading {0} of {1} bytes...", e.Length, e.TotalLength);
                    progress.Report(new ProgressInfo(progressPercentage, message));
                };
            }
            httpWebOperation.WebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
            httpWebOperation.WebRequest.Proxy       = _prefs.GetWebProxy();
            httpWebOperation.Download(stream);
        }
Exemple #5
0
        /// <summary>
        /// Download a File via Http.
        /// </summary>
        /// <param name="httpWebOperation">Web Operation.</param>
        /// <param name="localFilePath">Path to local file.</param>
        /// <param name="username">Http Login Username.</param>
        /// <param name="password">Http Login Password.</param>
        /// <exception cref="ArgumentNullException">Throws if resourceUri is null.</exception>
        /// <exception cref="ArgumentException">Throws if localFilePath is null or empty.</exception>
        public void HttpDownloadHelper(IWebOperation httpWebOperation, string localFilePath, string username, string password)
        {
            if (httpWebOperation == null)
            {
                throw new ArgumentNullException("httpWebOperation");
            }
            if (String.IsNullOrEmpty(localFilePath))
            {
                throw new ArgumentException("Argument 'localFilePath' cannot be a null or empty string.");
            }

            httpWebOperation.WebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);

            httpWebOperation.WebRequest.SetNetworkCredentials(username, password);
            SetProxy(httpWebOperation.WebRequest);

            httpWebOperation.Download(localFilePath);
        }
Exemple #6
0
 private void PerformDownload(string url)
 {
     if (_webOperation == null)
     {
         // create
         _webOperation = WebOperation.Create(url);
     }
     // set proxy (if applicable)
     if (_proxy != null)
     {
         _webOperation.WebRequest.Proxy = _proxy;
     }
     // listen for progress messages
     _webOperation.ProgressChanged += WebOperationProgressChanged;
     // set the view for download
     SetViewControlsForDownload();
     // execute the download
     _webOperation.Download(LocalFilePath);
 }
Exemple #7
0
        /// <summary>
        /// Download a File via Http.
        /// </summary>
        /// <param name="httpWebOperation">Web Operation.</param>
        /// <param name="localFilePath">Path to local file.</param>
        /// <param name="username">Http Login Username.</param>
        /// <param name="password">Http Login Password.</param>
        /// <exception cref="ArgumentNullException">Throws if resourceUri is null.</exception>
        /// <exception cref="ArgumentException">Throws if localFilePath is null or empty.</exception>
        public void HttpDownloadHelper(IWebOperation httpWebOperation, string localFilePath, string username, string password)
        {
            if (httpWebOperation == null) throw new ArgumentNullException("httpWebOperation");
             if (String.IsNullOrEmpty(localFilePath)) throw new ArgumentException("Argument 'localFilePath' cannot be a null or empty string.");

             _httpWebOperation = httpWebOperation;
             _httpWebOperation.WebOperationProgress += OnHttpWebOperationProgress;
             _httpWebOperation.OperationRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);

             SetNetworkCredentials(_httpWebOperation.OperationRequest.Request, username, password);
             SetProxy(_httpWebOperation.OperationRequest.Request);

             _httpWebOperation.Download(localFilePath);
        }
Exemple #8
0
      /// <summary>
      /// Download a File via Ftp.
      /// </summary>
      /// <param name="ftpWebOperation">Web Operation.</param>
      /// <param name="localFilePath">Path to local file.</param>
      /// <param name="username">Ftp Login Username.</param>
      /// <param name="password">Ftp Login Password.</param>
      /// <param name="ftpMode">Ftp Transfer Mode.</param>
      /// <exception cref="ArgumentNullException">Throws if ftpWebOperation is null.</exception>
      /// <exception cref="ArgumentException">Throws if localFilePath is null or empty.</exception>
      public void FtpDownloadHelper(IWebOperation ftpWebOperation, string localFilePath, string username, string password, FtpMode ftpMode)
      {
         if (ftpWebOperation == null) throw new ArgumentNullException("ftpWebOperation");
         if (String.IsNullOrEmpty(localFilePath)) throw new ArgumentException("Argument 'localFilePath' cannot be a null or empty string.");

         ftpWebOperation.WebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
         ((IFtpWebRequest)ftpWebOperation.WebRequest).SetFtpMode(ftpMode);

         ftpWebOperation.WebRequest.SetNetworkCredentials(username, password);
         ftpWebOperation.Download(localFilePath);
      }