void _client_CheckFileExistsCompleted(object sender, SMT.Saas.Tools.NewFileUploadWS.CheckFileExistsCompletedEventArgs e) { if (e.Error == null) { long lengthtemp = e.Result.BytesUploaded; if (lengthtemp > 0) { MessageBoxResult result; if (lengthtemp > 0) { result = MessageBox.Show(e.Result.FileName + "文件部分存在, 如果是相同文件名上传请先做删除处理,是否继续上传?", "续传?", MessageBoxButton.OKCancel); if (result == MessageBoxResult.Cancel) { lengthtemp = 0; this._file.BytesUploaded = 0; _client.DeleteFileAsync(e.Result.SmtFileListId, e.Result.FileUrl); this._file.State = Constants.FileStates.Pending; return; } else { this._file.BytesUploaded = lengthtemp; this._dataSent = lengthtemp; int percent = (int)((this._file.BytesUploaded / this._file.FileSize) * 100); _file.FileStream.Seek(lengthtemp, System.IO.SeekOrigin.Begin); UploadProgressChangedEventArgs args = new UploadProgressChangedEventArgs(percent, lengthtemp, lengthtemp, this._file.FileSize, _file.FileName); //this.Dispatcher.BeginInvoke(delegate() //{ // UploadProgressChanged(this, args); //}); OnProgressChanged(); } } } StartUpload(); } }
void userFile_UploadProgressChanged(object sender, UploadProgressChangedEventArgs args) { TotalUploaded += args.BytesUploaded; progressBar.Value = TotalUploaded; totalSizeTextBlock.Text = string.Format("{0} / {1}", new ByteConverter().Convert(TotalUploaded, this.GetType(), null, null).ToString(), new ByteConverter().Convert(TotalUploadSize, this.GetType(), null, null).ToString()); double ByteProcessTime = 0; double EstimatedTime = 0; try { TimeSpan timeSpan = DateTime.Now - start; ByteProcessTime = TotalUploaded / timeSpan.TotalSeconds; Speed.Text = "速度:" + ((TotalUploaded / 1024) / timeSpan.TotalSeconds).ToString("F0") + "kb/秒"; EstimatedTime = (TotalUploadSize - TotalUploaded) / ByteProcessTime; timeSpan = TimeSpan.FromSeconds(EstimatedTime); timeLeftTextBlock.Text = string.Format("{0:00}:{1:00}:{2:00}", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds); } catch { } }