/// <summary> /// Actually activate/deactivate users specified features on requested site collection list /// </summary> protected internal override bool Execute() { if (command == SiteCollectionCommand.Activate) { log.Info(CommonUIStrings.logFeatureActivate); } else { log.Info(CommonUIStrings.logFeatureDeactivate); } ReadOnlyCollection<Guid?> featureIds = InstallConfiguration.FeatureIdList; if (featureIds == null || featureIds.Count == 0) { log.Warn(CommonUIStrings.logNoFeaturesSpecified); return true; } if (siteCollectionLocs == null || siteCollectionLocs.Count == 0) { // caller responsible for giving message, depending on operation (install, upgrade,...) return true; } try { foreach (SiteLoc siteLoc in siteCollectionLocs) { SPSite siteCollection = null; try { siteCollection = new SPSite(siteLoc.SiteId); foreach (Guid? featureId in siteLoc.featureList) { if (featureId == null) continue; if (command == SiteCollectionCommand.Activate) { FeatureActivator.ActivateOneFeature(siteCollection.Features, featureId.Value, log); if (!FeatureActivator.IsFeatureActivatedOnSite(siteCollection, featureId.Value)) { // do not add to completedLocs, b/c it didn't complete log.Warn("Activation failed on " + siteCollection.Url + " : " + GetFeatureName(featureId)); } else { completedLocs.Add(siteLoc); log.Info(siteCollection.Url + " : " + GetFeatureName(featureId)); } } else { siteCollection.Features.Remove(featureId.Value, true); completedLocs.Add(siteLoc); log.Info(siteCollection.Url + " : " + GetFeatureName(featureId)); } } } catch (Exception exc) { if (rollback) { // during rollback simply log errors and continue string message; if (command == SiteCollectionCommand.Activate) message = "Activating feature(s)"; else message = "Deactivating feature(s)"; log.Error(message, exc); } else { log.Error(siteCollection.Url); throw exc; } } finally { // guarantee SPSite is released ASAP even in face of exception if (siteCollection != null) siteCollection.Dispose(); } } return true; } catch (Exception exc) { if (rollback) { log.Error("Error during rollback", exc); return false; } rollback = true; // rollback work accomplished so far if (command == SiteCollectionCommand.Activate) { DeactivateSiteCollectionFeatureCommand reverseCommand = new DeactivateSiteCollectionFeatureCommand(this.Parent, completedLocs); reverseCommand.Execute(); } else { ActivateSiteCollectionFeatureCommand reverseCommand = new ActivateSiteCollectionFeatureCommand(this.Parent, completedLocs); reverseCommand.Execute(); } throw exc; } }
/// <summary> /// Actually activate/deactivate users specified features on requested site collection list /// </summary> protected internal override bool Execute() { if (command == SiteCollectionCommand.Activate) { log.Info(CommonUIStrings.logFeatureActivate); } else { log.Info(CommonUIStrings.logFeatureDeactivate); } ReadOnlyCollection <Guid?> featureIds = InstallConfiguration.FeatureIdList; if (featureIds == null || featureIds.Count == 0) { log.Warn(CommonUIStrings.logNoFeaturesSpecified); return(true); } if (siteCollectionLocs == null || siteCollectionLocs.Count == 0) { // caller responsible for giving message, depending on operation (install, upgrade,...) return(true); } try { foreach (SiteLoc siteLoc in siteCollectionLocs) { SPSite siteCollection = null; try { siteCollection = new SPSite(siteLoc.SiteId); foreach (Guid?featureId in siteLoc.featureList) { if (featureId == null) { continue; } if (command == SiteCollectionCommand.Activate) { FeatureActivator.ActivateOneFeature(siteCollection.Features, featureId.Value, log); if (!FeatureActivator.IsFeatureActivatedOnSite(siteCollection, featureId.Value)) { // do not add to completedLocs, b/c it didn't complete log.Warn("Activation failed on " + siteCollection.Url + " : " + GetFeatureName(featureId)); } else { completedLocs.Add(siteLoc); log.Info(siteCollection.Url + " : " + GetFeatureName(featureId)); } } else { siteCollection.Features.Remove(featureId.Value, true); completedLocs.Add(siteLoc); log.Info(siteCollection.Url + " : " + GetFeatureName(featureId)); } } } catch (Exception exc) { if (rollback) { // during rollback simply log errors and continue string message; if (command == SiteCollectionCommand.Activate) { message = "Activating feature(s)"; } else { message = "Deactivating feature(s)"; } log.Error(message, exc); } else { log.Error(siteCollection.Url); throw exc; } } finally { // guarantee SPSite is released ASAP even in face of exception if (siteCollection != null) { siteCollection.Dispose(); } } } return(true); } catch (Exception exc) { if (rollback) { log.Error("Error during rollback", exc); return(false); } rollback = true; // rollback work accomplished so far if (command == SiteCollectionCommand.Activate) { DeactivateSiteCollectionFeatureCommand reverseCommand = new DeactivateSiteCollectionFeatureCommand(this.Parent, completedLocs); reverseCommand.Execute(); } else { ActivateSiteCollectionFeatureCommand reverseCommand = new ActivateSiteCollectionFeatureCommand(this.Parent, completedLocs); reverseCommand.Execute(); } throw exc; } }
protected internal override void Open(InstallOptions options) { executeCommands = new CommandList(); rollbackCommands = new CommandList(); nextCommand = 0; SPFeatureScope featureScope = InstallConfiguration.FeatureScope; DeactivateSiteCollectionFeatureCommand deactivateSiteCollectionFeatureCommand = null; switch (Form.Operation) { case InstallOperation.Install: executeCommands.Add(new AddSolutionCommand(this)); if ((options.WebApplicationTargets != null) && (options.WebApplicationTargets.Count > 0)) { executeCommands.Add(new CreateDeploymentJobCommand(this, options.WebApplicationTargets)); } else { // KML TODO - need to get rid of options.Targets? - check with Lars executeCommands.Add(new CreateDeploymentJobCommand(this, options.Targets)); } executeCommands.Add(new WaitForJobCompletionCommand(this, res.WaitDeploy)); if (featureScope == SPFeatureScope.Farm) { executeCommands.Add(new ActivateFarmFeatureCommand(this)); } else if (featureScope == SPFeatureScope.Site) { executeCommands.Add(new ActivateSiteCollectionFeatureCommand(this, options.SiteCollectionTargets)); } executeCommands.Add(new RegisterVersionNumberCommand(this)); for (int i = executeCommands.Count - 1; i <= 0; i--) { rollbackCommands.Add(executeCommands [i]); } break; case InstallOperation.Upgrade: if (featureScope == SPFeatureScope.Farm) { executeCommands.Add(new DeactivateFarmFeatureCommand(this)); } else if (featureScope == SPFeatureScope.Site) { deactivateSiteCollectionFeatureCommand = new DeactivateSiteCollectionFeatureCommand(this); executeCommands.Add(deactivateSiteCollectionFeatureCommand); } if (!IsSolutionRenamed()) { executeCommands.Add(new CreateUpgradeJobCommand(this)); executeCommands.Add(new WaitForJobCompletionCommand(this, res.WaitUpgrade)); } else { executeCommands.Add(new CreateRetractionJobCommand(this)); executeCommands.Add(new WaitForJobCompletionCommand(this, res.WaitRetract)); executeCommands.Add(new RemoveSolutionCommand(this)); executeCommands.Add(new AddSolutionCommand(this)); executeCommands.Add(new CreateDeploymentJobCommand(this, GetDeployedApplications())); executeCommands.Add(new WaitForJobCompletionCommand(this, res.WaitDeploy)); } if (featureScope == SPFeatureScope.Farm) { executeCommands.Add(new ActivateFarmFeatureCommand(this)); } if (featureScope == SPFeatureScope.Site) { executeCommands.Add(new ActivateSiteCollectionFeatureCommand(this, deactivateSiteCollectionFeatureCommand.DeactivatedSiteCollections)); } executeCommands.Add(new RegisterVersionNumberCommand(this)); break; case InstallOperation.Repair: if (featureScope == SPFeatureScope.Farm) { executeCommands.Add(new DeactivateFarmFeatureCommand(this)); } if (featureScope == SPFeatureScope.Site) { deactivateSiteCollectionFeatureCommand = new DeactivateSiteCollectionFeatureCommand(this); executeCommands.Add(deactivateSiteCollectionFeatureCommand); } executeCommands.Add(new CreateRetractionJobCommand(this)); executeCommands.Add(new WaitForJobCompletionCommand(this, res.WaitRetract)); executeCommands.Add(new RemoveSolutionCommand(this)); executeCommands.Add(new AddSolutionCommand(this)); executeCommands.Add(new CreateDeploymentJobCommand(this, GetDeployedApplications())); executeCommands.Add(new WaitForJobCompletionCommand(this, res.WaitDeploy)); if (featureScope == SPFeatureScope.Farm) { executeCommands.Add(new ActivateFarmFeatureCommand(this)); } if (featureScope == SPFeatureScope.Site) { executeCommands.Add(new ActivateSiteCollectionFeatureCommand(this, deactivateSiteCollectionFeatureCommand.DeactivatedSiteCollections)); } executeCommands.Add(new RegisterVersionNumberCommand(this)); break; case InstallOperation.Uninstall: if (featureScope == SPFeatureScope.Farm) { executeCommands.Add(new DeactivateFarmFeatureCommand(this)); } if (featureScope == SPFeatureScope.Site) { executeCommands.Add(new DeactivateSiteCollectionFeatureCommand(this)); } executeCommands.Add(new CreateRetractionJobCommand(this)); executeCommands.Add(new WaitForJobCompletionCommand(this, res.WaitRetract)); executeCommands.Add(new RemoveSolutionCommand(this)); executeCommands.Add(new UnregisterVersionNumberCommand(this)); break; } progressBar.Maximum = executeCommands.Count; descriptionLabel.Text = executeCommands [0].Description; timer.Interval = 1000; timer.Tick += new EventHandler(TimerEventInstall); timer.Start(); }