string GetSpeedInfo(string operation, FileSystemProgressEventArgs e) { if (e.BytesPerSecond != 0) { return(string.Format("{3} file {0}... {1}/sec {2} remaining", e.SourceFileInfo.Name, Util.FormatSize(e.BytesPerSecond), e.RemainingTime, operation)); } return(string.Format("{1} file {0}...", e.SourceFileInfo.Name, operation)); }
void IClientView.UpdateProgress(FileSystemProgressEventArgs e, bool smallProgress, bool totalProgress) { if (smallProgress) { progressBar.Value = (int)e.Percentage; } if (totalProgress) { progressBarTotal.Value = (int)e.TotalPercentage; } Application.DoEvents(); }
/// <summary> /// Displays progress information of the current operation. /// </summary> private void client_Progress(object sender, FileSystemProgressEventArgs e) { switch (e.State) { case TransferState.DeletingDirectory: // It's about to delete a directory. To skip deleting this directory, simply set e.Skip = true. _view.UpdateStatus(string.Format("Deleting directory {0}...", e.SourceFileSystem.GetFileName(e.SourcePath))); if (_settings.Get <bool>(SettingInfo.ShowProgressWhileDeleting)) { //progressBarTotal.Value = (int)e.TotalPercentage; _view.UpdateProgress(e, false, true); } return; case TransferState.DeletingFile: // It's about to delete a file. To skip deleting this file, simply set e.Skip = true. _view.UpdateStatus(string.Format("Deleting file {0}...", e.SourceFileSystem.GetFileName(e.SourcePath))); if (_settings.Get <bool>(SettingInfo.ShowProgressWhileDeleting)) { //progressBarTotal.Value = (int)e.TotalPercentage; _view.UpdateProgress(e, false, true); } return; case TransferState.SettingFileAttribute: // It's about to setting attributes of a file. To skip this file, simply set e.Skip = true. _view.UpdateStatus(string.Format("Setting attributes file {0}...", e.SourceFileSystem.GetFileName(e.SourcePath))); if (_settings.Get <bool>(SettingInfo.ShowProgressWhileDeleting)) { //progressBarTotal.Value = (int)e.TotalPercentage; _view.UpdateProgress(e, false, true); } return; case TransferState.SettingFilePermission: // It's about to setting attributes of a file. To skip this file, simply set e.Skip = true. _view.UpdateStatus(string.Format("Setting permissions file {0}...", e.SourceFileSystem.GetFileName(e.SourcePath))); if (_settings.Get <bool>(SettingInfo.ShowProgressWhileDeleting)) { //progressBarTotal.Value = (int)e.TotalPercentage; _view.UpdateProgress(e, false, true); } return; case TransferState.BuildingDirectoryStructure: // It informs us that the directory structure has been prepared for the multiple file transfer. _view.UpdateStatus("Building directory structure..."); break; #region Comparing File Events case TransferState.StartComparingFile: // Source file and destination file are about to be compared. // To skip comparing these files, simply set e.Skip = true. // To override the comparison result, set the e.ComparionResult property. _view.UpdateStatus(string.Format("Comparing file {0}...", System.IO.Path.GetFileName(e.SourcePath))); _view.UpdateProgress(e, true, true); break; case TransferState.Comparing: // Source file and destination file are being compared. _view.UpdateStatus(GetSpeedInfo("Comparing", e)); _view.UpdateProgress(e, true, true); break; case TransferState.FileCompared: // Source file and destination file have been compared. // Comparison result is saved in the e.ComparisonResult property. _view.UpdateProgress(e, true, true); break; #endregion #region Uploading File Events case TransferState.StartUploadingFile: // Source file (local file) is about to be uploaded. Destination file is the remote file. // To skip uploading this file, simply set e.Skip = true. _view.UpdateStatus(string.Format("Uploading file {0}...", System.IO.Path.GetFileName(e.SourcePath))); _view.UpdateProgress(e, true, true); break; case TransferState.Uploading: // Source file is being uploaded to the remote server. _view.UpdateStatus(GetSpeedInfo("Uploading", e)); _view.UpdateProgress(e, true, true); break; case TransferState.FileUploaded: // Source file has been uploaded. _view.UpdateProgress(e, true, true); break; #endregion #region Downloading File Events case TransferState.StartDownloadingFile: // Source file (remote file) is about to be downloaded. // To skip uploading this file, simply set e.Skip = true. _view.UpdateStatus(string.Format("Downloading file {0}...", System.IO.Path.GetFileName(e.SourcePath))); _view.UpdateProgress(e, true, true); break; case TransferState.Downloading: // Source file is being downloaded to the local disk. _view.UpdateStatus(GetSpeedInfo("Downloading", e)); _view.UpdateProgress(e, true, true); break; case TransferState.FileDownloaded: // Remote file has been downloaded. _view.UpdateProgress(e, true, true); break; #endregion } }
void ftpClient_DownloadProgressUpdate(object sender, FileSystemProgressEventArgs e) { lblProgress.Content = e.Percentage + "%"; }
// =============================================== // Private Events // =============================================== void ftpClient_Progress(object sender, FileSystemProgressEventArgs e) { Application.Current.Dispatcher.BeginInvoke( DispatcherPriority.Normal, new Action(() => { DownloadProgressUpdate(this, e); })); }