Exemplo n.º 1
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; }
            }
        }
Exemplo n.º 2
0
 void packageManager_RequiringLicenseAcceptance(object sender, RequiringLicenseAcceptanceEventArgs e)
 {
     if (control.InvokeRequired)
     {
         control.Invoke((EventHandler <RequiringLicenseAcceptanceEventArgs>)packageManager_RequiringLicenseAcceptance, sender, e);
     }
     else
     {
         if (operationDialog == null)
         {
             return;
         }
         operationDialog.Hide();
         using (var licenseDialog = new LicenseAcceptanceDialog(e.LicensePackages))
         {
             e.LicenseAccepted = licenseDialog.ShowDialog(control) == DialogResult.Yes;
             if (e.LicenseAccepted)
             {
                 operationDialog.Show();
             }
         }
     }
 }