private void ProcessFile() { i++; if (files.Length <= i || files[i] == null) { if (PushBulletAPI.GetBoolConfigurationOption(PushBullet.conf, "showDoneWindow", true)) { MessageBox.Show(Properties.Strings.UploadCompleted, "Ok", MessageBoxButton.OK, MessageBoxImage.Information); } Application.Current.Dispatcher.BeginInvoke(new Action(() => Application.Current.Shutdown())); return; } Application.Current.Dispatcher.BeginInvoke(new Action(() => uploadLabel.Content = string.Format(Properties.Strings.UploadingFormatStr, Path.GetFileName(files[i]), i + 1, files.Length))); if (!File.Exists(files[i])) { PushBullet.ShowError(string.Format(Properties.Strings.FileDoesNotExist, files[i])); ProcessFile(); return; } FileInfo info = new FileInfo(files[i]); if (info.Length > 0x1900000 || info.Length == 0) // 0x1900000 == 26214400 bytes == 25 MiB { PushBullet.ShowError(string.Format(Properties.Strings.IncorrectSize, files[i])); ProcessFile(); return; } currentWorker = new BackgroundWorker(); currentWorker.DoWork += RunInBackground; currentWorker.ProgressChanged += UpdateProgress; currentWorker.RunWorkerCompleted += UpdateUIElements; currentWorker.WorkerReportsProgress = true; currentWorker.WorkerSupportsCancellation = true; Application.Current.Dispatcher.BeginInvoke(new Action(() => currentWorker.RunWorkerAsync(new string[] { deviceId, files[i] }))); }
private void CheckAPIKeyBg(object sender, DoWorkEventArgs e) { PushBulletAPI.DevicesResponse devices; try { devices = PushBulletAPI.GetDevices(); } catch (Exception ex) { e.Result = false; PushBullet.ShowError(Properties.Strings.InvalidKey + " " + ex.ToString()); return; } e.Result = devices; }
private void RunInBackground(object sender, DoWorkEventArgs e) { string[] arguments = (string[])e.Argument; try { PushBulletAPI.PushFile(arguments[0], arguments[1], OnDataUploaded); } catch (Exception ex) { if (ex.GetType() != typeof(System.Threading.ThreadInterruptedException)) { PushBullet.ShowError(string.Format(Properties.Strings.UploadError, ex.ToString())); } else { Application.Current.Dispatcher.BeginInvoke(new Action(() => Application.Current.Shutdown())); } } }