public UpdatePresenter(Action<Exception> exceptionLogger, ApplicationUpdate updateData, 
     IWebProxy proxy, IUpdateView updateView, ISaveFileDialogView saveFileView,
     IWebOperation webOperation)
 {
     _exceptionLogger = exceptionLogger;
      _updateData = updateData;
      _proxy = proxy;
      _updateView = updateView;
      _saveFileView = saveFileView;
      _webOperation = webOperation;
      _updateView.AttachPresenter(this);
 }
 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(url);
      // execute the download
      _webOperation.Download(LocalFilePath);
 }
 private void PerformDownloadCallback(IAsyncResult result)
 {
     var action = (Action<string>)result.AsyncState;
      try
      {
     action.EndInvoke(result);
     if (_webOperation.Result.Equals(WebOperationResult.Completed))
     {
        // verify, throws exception on error
        VerifyDownload();
        // no errors, set ready flag
        UpdateReady = true;
        // success, close the view
        _updateView.CloseView();
     }
     // not completed, let the user try again if they wish
     else
     {
        SetViewControlsForUpdateSelection();
     }
      }
      catch (Exception ex)
      {
     LogException(ex);
     string message = String.Format(CultureInfo.CurrentCulture,
                                    "Download failed with the following error:{0}{0}{1}",
                                    Environment.NewLine, ex.Message);
     _updateView.ShowErrorMessage(message);
     // download error, let the user try again if they wish
     SetViewControlsForUpdateSelection();
      }
      finally
      {
     // clean up
     _webOperation.ProgressChanged -= WebOperationProgressChanged;
     _webOperation = null;
     // signal listeners
     OnDownloadFinished(EventArgs.Empty);
      }
 }
Exemple #4
0
        /// <summary>
        /// Check an HTTP Connection.
        /// </summary>
        /// <param name="httpWebOperation">Web Operation.</param>
        /// <param name="username">Http Login Username.</param>
        /// <param name="password">Http Login Password.</param>
        /// <exception cref="ArgumentException">Throws if httpWebOperation is null.</exception>
        public void HttpCheckConnection(IWebOperation httpWebOperation, string username, string password)
        {
            if (httpWebOperation == null) throw new ArgumentNullException("httpWebOperation", "Argument 'httpWebOperation' cannot be null.");

             httpWebOperation.OperationRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
             httpWebOperation.OperationRequest.Timeout = 5000; // 5 second timeout

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

             httpWebOperation.CheckConnection();
        }
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 = 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 #6
0
      /// <summary>
      /// Check an FTP Connection.
      /// </summary>
      /// <param name="ftpWebOperation">Web Operation.</param>
      /// <param name="username">Ftp Login Username.</param>
      /// <param name="password">Ftp Login Password.</param>
      /// <param name="ftpMode">Ftp Transfer Mode.</param>
      /// <exception cref="ArgumentException">Throws if ftpWebOperation is null.</exception>
      public void FtpCheckConnection(IWebOperation ftpWebOperation, string username, string password, FtpMode ftpMode)
      {
         if (ftpWebOperation == null) throw new ArgumentNullException("ftpWebOperation");

         var ftpWebRequest = (IFtpWebRequest)ftpWebOperation.WebRequest;
         ftpWebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
         ftpWebRequest.KeepAlive = false; // Close the Request
         ftpWebRequest.Timeout = 5000; // 5 second timeout
         ftpWebRequest.SetFtpMode(ftpMode);

         ftpWebOperation.WebRequest.SetNetworkCredentials(username, password);

         ftpWebOperation.CheckConnection();
      }
Exemple #7
0
        /// <summary>
        /// Get the Length of the Http Download.
        /// </summary>
        /// <param name="httpWebOperation">Web Operation.</param>
        /// <param name="username">Http Login Username.</param>
        /// <param name="password">Http Login Password.</param>
        /// <exception cref="ArgumentNullException">Throws if resourceUri is null.</exception>
        public long GetHttpDownloadLength(IWebOperation httpWebOperation, string username, string password)
        {
            if (httpWebOperation == null) throw new ArgumentNullException("httpWebOperation");

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

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

             return _httpWebOperation.GetDownloadLength();
        }
Exemple #8
0
      /// <summary>
      /// Get the Length of the Http Download.
      /// </summary>
      /// <param name="ftpWebOperation">Web Operation.</param>
      /// <param name="username">Http Login Username.</param>
      /// <param name="password">Http Login Password.</param>
      /// <param name="ftpMode">Ftp Transfer Mode.</param>
      /// <exception cref="ArgumentNullException">Throws if resourceUri is null.</exception>
      public long GetFtpDownloadLength(IWebOperation ftpWebOperation, string username, string password, FtpMode ftpMode)
      {
         if (ftpWebOperation == null) throw new ArgumentNullException("ftpWebOperation", "Argument 'httpWebOperation' cannot be null.");

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

         ftpWebOperation.WebRequest.SetNetworkCredentials(username, password);
         return ftpWebOperation.GetDownloadLength();
      }
Exemple #9
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);
      }
Exemple #10
0
      internal void FtpUploadHelper(IWebOperation ftpWebOperation, Stream localStream, int maximumLength, string username, string password, FtpMode ftpMode)
      {
         if (ftpWebOperation == null) throw new ArgumentNullException("ftpWebOperation");
         if (localStream == null) throw new ArgumentNullException("localStream");

         ftpWebOperation.WebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
         ((IFtpWebRequest)ftpWebOperation.WebRequest).SetFtpMode(ftpMode);
         ftpWebOperation.WebRequest.SetNetworkCredentials(username, password);

         if (maximumLength >= 0 && localStream.Length >= maximumLength)
         {
            localStream.Position = localStream.Length - maximumLength;
         }
         ftpWebOperation.Upload(localStream);
      }
Exemple #11
0
 internal void FtpUploadHelper(IWebOperation ftpWebOperation, Stream localStream, string username, string password, FtpMode ftpMode)
 {
    FtpUploadHelper(ftpWebOperation, localStream, -1, username, password, ftpMode);
 }
Exemple #12
0
 internal void FtpUploadHelper(IWebOperation ftpWebOperation, string localFilePath, string username, string password, FtpMode ftpMode)
 {
    FtpUploadHelper(ftpWebOperation, localFilePath, -1, username, password, ftpMode);
 }