Esempio n. 1
0
        protected virtual void OnUploadFinished(string fileName)
        {
            AutomationEventArgs args = new AutomationEventArgs();

            args.FileName = fileName;
            args.Progress = 10000;

            UploadFinished?.Invoke(args);
        }
Esempio n. 2
0
        /// <summary>
        /// 处理多文件上传
        /// </summary>
        /// <param name="p_files"></param>
        async Task <bool> HandleUpload(IList <FileData> p_files)
        {
            UploadStarted?.Invoke(this, EventArgs.Empty);

            List <string> result = null;

            _cts?.Dispose();
            _cts = new CancellationTokenSource();
            try
            {
                result = await Uploader.Send(p_files, FixedVolume, _cts);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "上传出错");
            }
            finally
            {
                _cts?.Dispose();
            }

            bool suc = false;

            if (result == null || result.Count != p_files.Count)
            {
                // 失败
                if (_cts == null)
                {
                    Kit.Msg("已取消上传!");
                }
                else
                {
                    Kit.Warn("😢上传失败,请重新上传!");
                }

                foreach (var vf in p_files)
                {
                    ((IUploadUI)vf.UploadUI).UploadFail(vf);
                }
                // 加载旧列表
                ReadData(Data);
            }
            else
            {
                suc = true;
                for (int i = 0; i < p_files.Count; i++)
                {
                    var vf = p_files[i];
                    await((IUploadUI)vf.UploadUI).UploadSuccess(result[i], vf);
                }
                WriteData();
            }
            UploadFinished?.Invoke(this, suc);
            return(suc);
        }
Esempio n. 3
0
        private async Task StartUpload()
        {
            Clipboard.SetText(RevisionLog);

            _pkgUploadr.MaxPartSizeMB = this.MaxPartSizeMB;
            var reply = await _pkgUploadr.StartUpload(Package, RevisionLog);

            UploadFinished?.Invoke(this, reply);

            //Alerter.Show(reply, "Package Upload");

            //if (reply.IsSuccessful)
            //    CheckUploadabilityCmd.ExecuteIfItCan();
        }
        public override void ResponseReceived(byte[] parameter)
        {
            switch ((DropAndExecuteCommunication)parameter[0])
            {
            case DropAndExecuteCommunication.ResponseUploadCompleted:
                var        taskGuid = new Guid(parameter.Skip(1).Take(16).ToArray());
                UploadTask uploadTask;
                lock (_uploadTasksLock)
                    uploadTask = _uploadTasks?.FirstOrDefault(x => x.Guid == taskGuid);

                if (uploadTask != null)
                {
                    uploadTask.IsUploaded = true;
                    if (_uploadTasks.All(x => x.IsUploaded))
                    {
                        UploadFinished?.Invoke(this, EventArgs.Empty);
                    }
                }
                break;

            case DropAndExecuteCommunication.ResponseUploadFailed:
                taskGuid = new Guid(parameter.Skip(1).Take(16).ToArray());
                lock (_uploadTasksLock)
                    uploadTask = _uploadTasks?.FirstOrDefault(x => x.Guid == taskGuid);

                if (uploadTask != null)
                {
                    uploadTask.IsUploaded = false;
                    uploadTask.Progress   = 0;
                    uploadTask.IsSent     = false;

                    if (!_isUploading)
                    {
                        new Thread(Upload)
                        {
                            IsBackground = true
                        }
                    }
                    .Start();
                }
Esempio n. 5
0
        private async void UploadTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (FileUpload.Uploader.Running)
            {
                try
                {
                    if (Created)
                    {
                        ProgressBar.Invoke(new Action(() =>
                        {
                            ProgressBar.Value = (int)(Math.Min(100, FileUpload.Uploader.Progress * 100 + 1));                             // If we set the progressbar to a higher value first, there is no animation
                            ProgressBar.Value = (int)(FileUpload.Uploader.Progress * 100);
                        }
                                                      ));
                    }
                }
                catch { }
            }
            else
            {
                if (!UploadTimer.Enabled)
                {
                    UploadTimer.Stop();
                }

                if (Created)
                {
                    ProgressBar.Invoke(new Action(() => StatusLabel.Text = "Finished"));
                }
                Uploading = false;
                if (Created)
                {
                    ProgressBar.Invoke(new Action(() => ProgressBar.Value = 0));
                }


                if (!FileUpload.IsSharing & FileUpload.Share && FileUpload.Uploader.Finished && !FileUpload.Uploader.Error)
                {
                    FileUpload.IsSharing = true;

                    string s = await Client.ShareFile(
                        FileUpload.Uploader.Identifier,
                        FileUpload.FirstView,
                        FileUpload.Public,
                        FileUpload.PublicRegistered,
                        FileUpload.Whitelisted,
                        FileUpload.Whitelist
                        );



                    string link = Config.AppSettings["ShareGenUrl"].Value + s;
                    if (Created)
                    {
                        LinkText.Invoke(new Action(() => LinkText.Text = link));
                    }
                    SetClipboardText(link);
                    SystemSounds.Beep.Play();
                }

                UploadFinished?.Invoke(this, EventArgs.Empty);
            }
        }