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; } }
public UpdatePresenter(Action <Exception> exceptionLogger, ApplicationUpdate updateData, IWebProxy proxy, IUpdateView updateView, harlam357.Windows.Forms.ISaveFileDialogView saveFileView, IWebOperation webOperation) { _exceptionLogger = exceptionLogger; _updateData = updateData; _proxy = proxy; _updateView = updateView; _saveFileView = saveFileView; _webOperation = webOperation; _updateView.AttachPresenter(this); }
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); }
/// <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()); }
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)); }
/// <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.WebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); httpWebOperation.WebRequest.SetNetworkCredentials(username, password); SetProxy(httpWebOperation.WebRequest); return(httpWebOperation.GetDownloadLength()); }
/// <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.WebRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); httpWebOperation.WebRequest.Timeout = 5000; // 5 second timeout httpWebOperation.WebRequest.SetNetworkCredentials(username, password); SetProxy(httpWebOperation.WebRequest); httpWebOperation.CheckConnection(); }
internal void FtpUploadHelper(IWebOperation ftpWebOperation, string localFilePath, int maximumLength, 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.Upload(localFilePath, maximumLength); }
/// <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); }
/// <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); }
/// <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(); }
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); }
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); } }
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); }
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); }
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); }
/// <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> /// 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(); }
/// <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(); }
internal void FtpUploadHelper(IWebOperation ftpWebOperation, Stream localStream, string username, string password, FtpMode ftpMode) { FtpUploadHelper(ftpWebOperation, localStream, -1, username, password, ftpMode); }
internal void FtpUploadHelper(IWebOperation ftpWebOperation, string localFilePath, string username, string password, FtpMode ftpMode) { FtpUploadHelper(ftpWebOperation, localFilePath, -1, username, password, ftpMode); }
/// <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); }
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); } }
/// <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(); }
/// <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(); }