示例#1
0
        void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            long lengthtemp = 0;

            if (!string.IsNullOrEmpty(e.Result))
            {
                lengthtemp = long.Parse(e.Result);
            }

            if (lengthtemp > 0)
            {
                MessageBoxResult result;
                if (lengthtemp == FileLength)
                {
                    result = MessageBox.Show("文件已存在,是否覆盖?", "是否覆盖?", MessageBoxButton.OKCancel);
                    if (result == MessageBoxResult.OK)
                    {
                        lengthtemp = 0;
                    }
                    else
                    {
                        UploadProgressChangedEventArgs args = new UploadProgressChangedEventArgs(100, FileLength - BytesUploaded, BytesUploaded, FileLength, file.Name);
                        this.Dispatcher.BeginInvoke(delegate()
                        {
                            UploadProgressChanged(this, args);
                        });
                        BytesUploaded = FileLength;
                        Status        = FileUploadStatus.Complete;
                        return;
                    }
                }
                else
                {
                    result = MessageBox.Show("文件已存在, 是否继续上传?", "是否继续?", MessageBoxButton.OKCancel);
                    if (result == MessageBoxResult.Cancel)
                    {
                        lengthtemp = 0;
                    }
                }
            }

            UploadFileEx();
        }
示例#2
0
        void upload_UploadProgressChanged(object sender, UploadProgressChangedEventArgs args)
        {
            TotalUploaded          += args.BytesUploaded;
            progressBar.Value       = TotalUploaded;
            totalSizeTextBlock.Text = string.Format("{0} of {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;
                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 { }
        }