protected override void ExecuteCore(SelectedItemCollection selection)
        {
            // find SRs that are using the storage-systems. First look in XC.

            var srsInUse = new List<IXenObject>();

            foreach (StorageLinkSystem system in GetSelection().AsXenObjects())
            {
                foreach (IXenConnection connection in ConnectionsManager.XenConnections.FindAll(c => c.IsConnected))
                {
                    foreach (SR sr in connection.Cache.SRs)
                    {
                        foreach (XenRef<PBD> pbdRef in sr.PBDs)
                        {
                            PBD pbd = sr.Connection.Resolve<PBD>(pbdRef);

                            if (pbd != null && pbd.device_config.ContainsKey("storageSystemId") && pbd.device_config["storageSystemId"] == system.opaque_ref)
                            {
                                srsInUse.Add(sr);
                                break;
                            }
                        }
                    }
                }
            }

            string title = GetSelection().Count == 1 ? Messages.MAINWINDOW_CONFIRM_REMOVE_STORAGE_SYSTEM_TITLE : Messages.MAINWINDOW_CONFIRM_REMOVE_STORAGE_SYSTEMS_TITLE;

            if (srsInUse.Count == 0)
            {
                // now check for SRs using the the storage-systems in SL.

                DelegatedAsyncAction scanAction = null;
                scanAction = new DelegatedAsyncAction(null, ConfirmationDialogTitle, "", "", s =>
                {
                    foreach (StorageLinkSystem system in GetSelection().AsXenObjects())
                    {
                        scanAction.Title = string.Format(Messages.STORAGELINK_SCANNING_FOR_SRS, system);
                        scanAction.Description = string.Format(Messages.STORAGELINK_SCANNING_FOR_SRS, system);

                        var systemSRs = system.StorageLinkConnection.FullSRRescan().FindAll(ss => ss.StorageLinkSystemId == system.StorageSystemId);

                        srsInUse.AddRange(systemSRs.ConvertAll(slr => (IXenObject)slr));
                    }
                }, true);

                scanAction.AppliesTo.AddRange(GetSelection().AsXenObjects().ConvertAll(s => s.opaque_ref));

                new ActionProgressDialog(scanAction, ProgressBarStyle.Marquee).ShowDialog();

                if (!scanAction.Succeeded)
                {
                    // scan failed. A message will have been displayed.
                    return;
                }
            }

            if (srsInUse.Count > 0)
            {
                // show confirmation dialog.

                string text = Messages.MAINWINDOW_CONFIRM_REMOVE_STORAGE_SYSTEMS_TEXT;

                if (GetSelection().Count == 1)
                {
                    text = string.Format(Messages.MAINWINDOW_CONFIRM_REMOVE_STORAGE_SYSTEM_TEXT, GetSelection()[0].XenObject);
                }
                    
                var reasons = new Dictionary<SelectedItem, string>();

                foreach (IXenObject x in srsInUse)
                {
                    reasons[new SelectedItem(x)] = Messages.STORAGELINK_IN_USE;
                }

                var dialog = new CommandErrorDialog(title, text, reasons, CommandErrorDialog.DialogMode.OKCancel);

                if (dialog.ShowDialog(Parent) != DialogResult.OK)
                {
                    return;
                }
            }

            // remove storage-system
            var actions = new List<AsyncAction>();

            foreach (StorageLinkSystem system in GetSelection().AsXenObjects())
            {
                actions.Add(new RemoveStorageLinkSystemAction(system));
            }

            RunMultipleActions(actions,
                Messages.REMOVE_STORAGE_LINK_SYSTEMS_ACTION_TITLE,
                Messages.REMOVE_STORAGE_LINK_SYSTEMS_ACTION_START_DESCRIPTION,
                Messages.REMOVE_STORAGE_LINK_SYSTEMS_ACTION_END_DESCRIPTION, true);
        }
        public static void ShowLicensingFailureDialog(List<LicenseFailure> licenseFailures, string exceptionMessage, Control parent)
        {
            Debug.Assert(licenseFailures.Count > 0);

             if (licenseFailures.Count == 1)
             {
                 Program.Invoke(Program.MainWindow, () =>
                 {
                     using (var dlg = new ThreeButtonDialog(new ThreeButtonDialog.Details(SystemIcons.Error, licenseFailures[0].AlertText,
                                                                Messages.LICENSE_ERROR_TITLE),
                                                            ThreeButtonDialog.ButtonOK))
                     {
                         dlg.ShowDialog(parent);
                     }
                 });
             }
             else
             {
                 var failureDic = new Dictionary<SelectedItem, string>();

                 foreach (var f in licenseFailures)
                 {
                     failureDic.Add(new SelectedItem(f.Host), f.AlertText);
                 }

                 Program.Invoke(Program.MainWindow, () =>
                 {
                     using (var dlg = new CommandErrorDialog(Messages.LICENSE_ERROR_TITLE, exceptionMessage, failureDic))
                     {
                         dlg.ShowDialog(parent);
                     }
                 });
             }
        }