private void UpdateDownloadDialogCancelButtonClick(object sender, EventArgs e) { UpdateManagerInstance.CancelDownload(); }
/// <summary> /// Shows the built-in UI while the updates are managed. /// </summary> public void ShowUserInterface() { if (_isTaskRunning) { return; } _isTaskRunning = true; var searchDialog = new UpdateSearchDialog { Updater = UpdateManagerInstance }; searchDialog.CancelButtonClicked += UpdateSearchDialogCancelButtonClick; var newUpdateDialog = new NewUpdateDialog { Updater = UpdateManagerInstance }; var noUpdateDialog = new NoUpdateFoundDialog { Updater = UpdateManagerInstance }; var progressIndicator = new Progress <UpdateDownloadProgressChangedEventArgs>(); var downloadDialog = new UpdateDownloadDialog { Updater = UpdateManagerInstance }; downloadDialog.CancelButtonClicked += UpdateDownloadDialogCancelButtonClick; #if PROVIDE_TAP try { // TAP TaskEx.Run(async delegate { if (!UseHiddenSearch) { _context.Post(searchDialog.ShowModalDialog, null); } try { _updatesAvailable = await UpdateManagerInstance.SearchForUpdatesAsync(); } catch (OperationCanceledException) { return; } catch (Exception ex) { if (UseHiddenSearch) { _context.Send( o => Popup.ShowPopup(SystemIcons.Error, _lp.UpdateSearchErrorCaption, ex, PopupButtons.Ok), null); } else { searchDialog.Fail(ex); _context.Post(searchDialog.CloseDialog, null); } return; } if (!UseHiddenSearch) { _context.Post(searchDialog.CloseDialog, null); await TaskEx.Delay(100); // Prevents race conditions that cause that the UpdateSearchDialog can't be closed before further actions are done } if (_updatesAvailable) { var newUpdateDialogReference = new DialogResultReference(); _context.Send(newUpdateDialog.ShowModalDialog, newUpdateDialogReference); if (newUpdateDialogReference.DialogResult == DialogResult.Cancel) { return; } } else if (!_updatesAvailable && UseHiddenSearch) { return; } else if (!_updatesAvailable && !UseHiddenSearch) { var noUpdateDialogResultReference = new DialogResultReference(); if (!UseHiddenSearch) { _context.Send(noUpdateDialog.ShowModalDialog, noUpdateDialogResultReference); } return; } _context.Post(downloadDialog.ShowModalDialog, null); try { progressIndicator.ProgressChanged += (sender, args) => downloadDialog.ProgressPercentage = (int)args.Percentage; await UpdateManagerInstance.DownloadPackagesAsync(progressIndicator); } catch (OperationCanceledException) { return; } catch (Exception ex) { downloadDialog.Fail(ex); _context.Send(downloadDialog.CloseDialog, null); return; } _context.Send(downloadDialog.CloseDialog, null); bool isValid = false; try { isValid = UpdateManagerInstance.ValidatePackages(); } catch (FileNotFoundException) { _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption, _lp.PackageNotFoundErrorText, PopupButtons.Ok), null); } catch (ArgumentException) { _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption, _lp.InvalidSignatureErrorText, PopupButtons.Ok), null); } catch (Exception ex) { _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption, ex, PopupButtons.Ok), null); } if (!isValid) { _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.InvalidSignatureErrorCaption, _lp.SignatureNotMatchingErrorText, PopupButtons.Ok), null); } else { UpdateManagerInstance.InstallPackage(); } }); } finally { _isTaskRunning = false; } #else try { //EAP UpdateManagerInstance.UpdateSearchFinished += SearchFinished; UpdateManagerInstance.UpdateSearchFinished += searchDialog.Finished; UpdateManagerInstance.UpdateSearchFailed += searchDialog.Failed; UpdateManagerInstance.PackagesDownloadProgressChanged += downloadDialog.ProgressChanged; UpdateManagerInstance.PackagesDownloadFinished += downloadDialog.Finished; UpdateManagerInstance.PackagesDownloadFailed += downloadDialog.Failed; Task.Factory.StartNew(() => { UpdateManagerInstance.SearchForUpdatesAsync(); if (!UseHiddenSearch) { var searchDialogResultReference = new DialogResultReference(); _context.Send(searchDialog.ShowModalDialog, searchDialogResultReference); _context.Send(searchDialog.CloseDialog, null); if (searchDialogResultReference.DialogResult == DialogResult.Cancel) { return; } } else { _searchResetEvent.WaitOne(); } if (_updatesAvailable) { var newUpdateDialogResultReference = new DialogResultReference(); _context.Send(newUpdateDialog.ShowModalDialog, newUpdateDialogResultReference); if (newUpdateDialogResultReference.DialogResult == DialogResult.Cancel) { return; } } else if (!_updatesAvailable && UseHiddenSearch) { return; } else if (!_updatesAvailable && !UseHiddenSearch) { _context.Send(noUpdateDialog.ShowModalDialog, null); _context.Send(noUpdateDialog.CloseDialog, null); return; } UpdateManagerInstance.DownloadPackagesAsync(); var downloadDialogResultReference = new DialogResultReference(); _context.Send(downloadDialog.ShowModalDialog, downloadDialogResultReference); _context.Send(downloadDialog.CloseDialog, null); if (downloadDialogResultReference.DialogResult == DialogResult.Cancel) { return; } bool isValid = false; try { isValid = UpdateManagerInstance.ValidatePackages(); } catch (FileNotFoundException) { _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption, _lp.PackageNotFoundErrorText, PopupButtons.Ok), null); } catch (ArgumentException) { _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption, _lp.InvalidSignatureErrorText, PopupButtons.Ok), null); } catch (Exception ex) { _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.PackageValidityCheckErrorCaption, ex, PopupButtons.Ok), null); } if (!isValid) { _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.InvalidSignatureErrorCaption, _lp.SignatureNotMatchingErrorText, PopupButtons.Ok), null); } else { try { UpdateManagerInstance.InstallPackage(); } catch (Win32Exception ex) { // TODO: Localize _context.Send(o => Popup.ShowPopup(SystemIcons.Error, "Error while starting the installer.", ex, PopupButtons.Ok), null); } catch (Exception ex) { _context.Send(o => Popup.ShowPopup(SystemIcons.Error, _lp.InstallerInitializingErrorCaption, ex, PopupButtons.Ok), null); } } }); } finally { _isTaskRunning = false; } #endif }
private void UpdateSearchDialogCancelButtonClick(object sender, EventArgs e) { UpdateManagerInstance.CancelSearch(); }