public static void RunPackageOperation(LicenseAwarePackageManager packageManager, Func <Task> operationFactory, string operationLabel = null) { EventHandler <RequiringLicenseAcceptanceEventArgs> requiringLicenseHandler = null; using (var dialog = new PackageOperationDialog { ShowInTaskbar = true }) { if (!string.IsNullOrEmpty(operationLabel)) { dialog.Text = operationLabel; } requiringLicenseHandler = (sender, e) => { if (dialog.InvokeRequired) { dialog.Invoke(requiringLicenseHandler, sender, e); } else { dialog.Hide(); using (var licenseDialog = new LicenseAcceptanceDialog(e.LicensePackages)) { e.LicenseAccepted = licenseDialog.ShowDialog() == DialogResult.Yes; if (e.LicenseAccepted) { dialog.Show(); } } } }; dialog.RegisterEventLogger((EventLogger)packageManager.Logger); packageManager.RequiringLicenseAcceptance += requiringLicenseHandler; try { var operation = operationFactory(); operation.ContinueWith(task => { if (task.IsFaulted) { LogException(packageManager.Logger, task.Exception); } else { dialog.BeginInvoke((Action)dialog.Close); } }); dialog.ShowDialog(); } finally { packageManager.RequiringLicenseAcceptance -= requiringLicenseHandler; } } }
public void RunPackageOperation(IEnumerable <IPackage> packages, bool handleDependencies) { using (var dialog = new PackageOperationDialog()) { var logger = packageManagerProxy.Logger; dialog.RegisterEventLogger((EventLogger)logger); IObservable <Unit> operation; if (selectedRepository == packageManagerProxy.LocalRepository) { operation = Observable.Start(() => { foreach (var package in packages) { packageManagerProxy.UninstallPackage(package, false, handleDependencies); } }); dialog.Text = Resources.UninstallOperationLabel; } else { var allowPrereleaseVersions = AllowPrereleaseVersions; var update = packageView.OperationText == Resources.UpdateOperationName; dialog.Text = update ? Resources.UpdateOperationLabel : Resources.InstallOperationLabel; operation = Observable.Start(() => { foreach (var package in packages) { packageManagerProxy.InstallPackage(package, !handleDependencies, allowPrereleaseVersions); } }); } operationDialog = dialog; try { operation.ObserveOn(control).Subscribe( xs => { }, ex => logger.Log(MessageLevel.Error, ex.Message), () => dialog.Complete()); if (dialog.ShowDialog() == DialogResult.OK) { UpdatePackageFeed(packagePageSelector.SelectedIndex); } } finally { operationDialog = null; } } }
protected override void OnFormClosing(FormClosingEventArgs e) { if (MetadataSpecified && metadataVersion > metadataSaveVersion) { var result = MessageBox.Show( this, Resources.SavePackageMetadata, Text, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (result == DialogResult.Cancel || result == DialogResult.Yes && !SaveMetadata()) { DialogResult = DialogResult.None; e.Cancel = true; } } if (DialogResult == DialogResult.OK) { var packageFileName = packageBuilder.Id + "." + packageBuilder.Version + global::NuGet.Constants.PackageExtension; saveFileDialog.FileName = packageFileName; if (entryPoint != null) { RenamePackageFile(entryPoint, packageBuilder.Id); if (entryPointLayout != null) { RenamePackageFile(entryPointLayout, packageBuilder.Id); } } EnsureDirectory(saveFileDialog.InitialDirectory); if (saveFileDialog.ShowDialog() == DialogResult.OK) { using (var dialog = new PackageOperationDialog()) { ILogger logger = new EventLogger(); dialog.Text = Resources.ExportOperationLabel; dialog.RegisterEventLogger((EventLogger)logger); logger.Log(MessageLevel.Info, "Creating package '{0} {1}'.", packageBuilder.Id, packageBuilder.Version); var dialogClosed = Observable.FromEventPattern <FormClosedEventHandler, FormClosedEventArgs>( handler => dialog.FormClosed += handler, handler => dialog.FormClosed -= handler); var operation = Observable.Using( () => Stream.Synchronized(File.Open(saveFileDialog.FileName, FileMode.Create)), stream => Observable.Start(() => packageBuilder.Save(stream)).TakeUntil(dialogClosed)); using (var subscription = operation.ObserveOn(this).Subscribe( xs => dialog.Complete(), ex => logger.Log(MessageLevel.Error, ex.Message))) { if (dialog.ShowDialog() != DialogResult.OK) { e.Cancel = true; } else { SystemSounds.Asterisk.Play(); var message = string.Format(Resources.PackageExported, packageBuilder.Id, packageBuilder.Version); MessageBox.Show(this, message, Text, MessageBoxButtons.OK, MessageBoxIcon.None); } } } } else { e.Cancel = true; } } base.OnFormClosing(e); }