PackageManager CreatePackageManager(IPackageRepository sourceRepository, EventLogger logger)
        {
            var packageManager = new LicenseAwarePackageManager(sourceRepository, packageManagerPath);

            packageManager.RequiringLicenseAcceptance += packageManager_RequiringLicenseAcceptance;
            packageManager.Logger = logger;
            return(packageManager);
        }
Exemple #2
0
        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; }
            }
        }