/// <summary>populate the web application list</summary> private void loadWebAppList() { using (WaitCursor wait = new WaitCursor()) { listWebApplications.Items.Clear(); listSiteCollections.Items.Clear(); listSites.Items.Clear(); clbSPSiteFeatures.Items.Clear(); clbSPWebFeatures.Items.Clear(); removeBtnEnabled(false); if (SPWebService.ContentService != null) { foreach (SPWebApplication webApp in SPWebService.ContentService.WebApplications) { Location location = LocationManager.CreateLocation(webApp); listWebApplications.Items.Add(location); } } else { MessageBox.Show("No Content web application found. Are you Farm-Administrator? Is the database accessible?"); } if (listWebApplications.Items.Count > 0) { listSiteCollections.Enabled = true; // If there is only one, select it if (listWebApplications.Items.Count == 0) { listWebApplications.SelectedIndex = 0; } } else { listSiteCollections.Enabled = false; } } }
/// <summary>UI method to update the SPWeb list when a user changes the selection in site collection list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listSiteCollections_SelectedIndexChanged(object sender, EventArgs e) { using (WaitCursor wait = new WaitCursor()) { m_CurrentSiteLocation = listSiteCollections.SelectedItem as Location; ClearCurrentWebData(); ReloadCurrentSiteCollectionFeatures(); ReloadSubWebList(); } EnableActionButtonsAsAppropriate(); }
/// <summary>UI method to load the SiteCollection Features and Site Features /// Handles the SelectedIndexChanged event of the listSites control. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listSites_SelectedIndexChanged(object sender, EventArgs e) { using (WaitCursor wait = new WaitCursor()) { m_CurrentWebLocation = listSites.SelectedItem as Location; ReloadCurrentWebFeatures(); } EnableActionButtonsAsAppropriate(); }
/// <summary>Removes selected features from the current Web Application only</summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRemoveFromWebApp_Click(object sender, EventArgs e) { int featuresSelected = clbSPSiteFeatures.CheckedItems.Count + clbSPWebFeatures.CheckedItems.Count; if (featuresSelected == 0) { MessageBox.Show(NOFEATURESELECTED); logDateMsg(NOFEATURESELECTED); return; } int featuresRemoved = 0; string title = m_CurrentWebAppLocation.Name; string msgString = string.Empty; msgString = "The " + featuresSelected + " selected Feature(s) " + "will be removed/deactivated from the complete web application: " + title + ". Continue?"; if (MessageBox.Show(msgString, "Warning - Multi Site Deletion!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return; } using (WaitCursor wait = new WaitCursor()) { SPWebApplication webApp = GetCurrentWebApplication(); List<Feature> scFeatures = GetSelectedSiteCollectionFeatures(); List<Feature> webFeatures = GetSelectedWebFeatures(); TraverseForceRemoveFeaturesFromWebApplication(webApp, scFeatures, webFeatures); } removeReady(featuresRemoved); }
private void ReloadAllActivationData() { using (WaitCursor wait = new WaitCursor()) { ActivationFinder finder = new ActivationFinder(); // No Found callback b/c we process final list finder.ExceptionListeners += new ActivationFinder.ExceptionHandler(logException); // Call routine to actually find & report activations m_featureDb.LoadAllData(finder.FindAllActivationsOfAllFeatures()); } }
private void ReloadCurrentSiteCollections() { using (WaitCursor wait = new WaitCursor()) { try { ClearCurrentSiteCollectionData(); ClearCurrentWebData(); removeBtnEnabled(false); m_CurrentWebAppLocation = listWebApplications.SelectedItem as Location; if (m_CurrentWebAppLocation == null) { return; } SPWebApplication webApp = GetCurrentWebApplication(); foreach (SPSite site in webApp.Sites) { Location siteLocation = LocationManager.CreateLocation(site); listSiteCollections.Items.Add(siteLocation); } // select first site collection if there is only one if (listSiteCollections.Items.Count == 1) { listSiteCollections.SelectedIndex = 0; } } catch (Exception exc) { logException(exc, "Exception enumerating site collections"); } } }
/// <summary>Removes selected features from the current web only</summary> private void removeSPWebFeaturesFromCurrentWeb() { if (clbSPWebFeatures.CheckedItems.Count == 0) { MessageBox.Show(NOFEATURESELECTED); logDateMsg(NOFEATURESELECTED); return; } if (IsEmpty(m_CurrentWebLocation)) { MessageBox.Show("No web currently selected"); return; } if (clbSPSiteFeatures.CheckedItems.Count > 0) { throw new Exception("Mixed mode unsupported"); } string msgString = string.Format( "This will force deactivate the {0} selected feature(s) from the selected Site(SPWeb): {1}" + "\n Continue ?", clbSPWebFeatures.CheckedItems.Count, LocationManager.SafeDescribeLocation(m_CurrentWebLocation) ); if (MessageBox.Show(msgString, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return; } using (WaitCursor wait = new WaitCursor()) { using (SPSite site = OpenCurrentSite()) { using (SPWeb web = OpenCurrentWeb(site)) { List<Feature> webFeatures = GetSelectedWebFeatures(); ForceRemoveFeaturesFromLocation(m_CurrentWebAppLocation, web.Features, webFeatures); } } } msgString = "Done. Please refresh the feature list, when all features are removed!"; logDateMsg(msgString); }
/// <summary>Removes selected features from the current web only</summary> /// <param name="sender"></param> /// <param name="e"></param> private void removeSPWebFeaturesFromCurrentWeb() { if (clbSPWebFeatures.CheckedItems.Count > 0) { int featuresRemoved = 0; string msgString; msgString = "This will force remove/deactivate the selected Feature(s) from the selected Site(SPWeb) only. Continue ?"; if (MessageBox.Show(msgString, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { using (WaitCursor wait = new WaitCursor()) { featuresRemoved = DeleteSelectedFeatures(siteFeatureManager, clbSPSiteFeatures.CheckedItems); featuresRemoved = DeleteSelectedFeatures(webFeatureManager, clbSPWebFeatures.CheckedItems); } msgString = "Done. Please refresh the feature list, when all features are removed!"; logDateMsg(msgString); } } else { MessageBox.Show(NOFEATURESELECTED); logDateMsg(NOFEATURESELECTED); } }
private void btnFindFaultyFeature_Click(object sender, EventArgs e) { using (WaitCursor wait = new WaitCursor()) { //first, Look in Farm try { if (findFaultyFeatureInCollection(SPWebService.ContentService.Features, SPFeatureScope.Farm)) { return; } } catch (Exception exc) { logException(exc, "Error finding faulty features in farm"); } //check web applications try { foreach (SPWebApplication webApp in SPWebService.ContentService.WebApplications) { try { if (findFaultyFeatureInCollection(webApp.Features, SPFeatureScope.WebApplication)) { return; } } catch (Exception exc) { logException(exc, "Enumerating features in web app " + webApp.Name); } try { // then check all site collections foreach (SPSite site in webApp.Sites) { using (site) { try { // check sites if (findFaultyFeatureInCollection(site.Features, SPFeatureScope.Site)) { return; } } catch (Exception exc) { logException(exc, "Exception checking features in site " + site.Url); } try { foreach (SPWeb web in site.AllWebs) { using (web) { try { // check webs if (findFaultyFeatureInCollection(web.Features, SPFeatureScope.Web)) { return; } } catch (Exception exc) { logException(exc, "Exception checking features in web " + web.Url); } } } } catch (Exception exc) { string msg = FormatSiteException(site, exc, "Error enumerating webs"); logException(exc, msg); } } } } catch (Exception exc) { logException(exc, "Exception enumerating sites in web app " + webApp.Name); } } } catch (Exception exc) { logException(exc, "Enumerating web applications"); } } string msgString = "No Faulty Feature was found in the farm!"; MessageBox.Show(msgString); logDateMsg(msgString); }
/// <summary>Update SiteCollections list when a user changes the selection in Web Application list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listWebApplications_SelectedIndexChanged(object sender, EventArgs e) { using (WaitCursor wait = new WaitCursor()) { try { listSiteCollections.Items.Clear(); listSites.Items.Clear(); clbSPSiteFeatures.Items.Clear(); clbSPWebFeatures.Items.Clear(); removeBtnEnabled(false); if (listWebApplications.SelectedItem.ToString() != String.Empty) { foreach (SPWebApplication webApp in SPWebService.ContentService.WebApplications) { if (webApp.Name == listWebApplications.SelectedItem.ToString()) { m_CurrentWebApp = webApp; } } foreach (SPSite site in m_CurrentWebApp.Sites) { listSiteCollections.Items.Add(site.Url); } } // tabControl1.Enabled = false; // tabControl1.Visible = false; // listFeatures.Items.Clear(); // listDetails.Items.Clear(); } catch (Exception exc) { logException(exc, "Exception enumerating site collections"); } } }
/// <summary>populate the web application list</summary> private void loadWebAppList() { using (WaitCursor wait = new WaitCursor()) { listWebApplications.Items.Clear(); listSiteCollections.Items.Clear(); listSites.Items.Clear(); clbSPSiteFeatures.Items.Clear(); clbSPWebFeatures.Items.Clear(); removeBtnEnabled(false); if (SPWebService.ContentService != null) { foreach (SPWebApplication webApp in SPWebService.ContentService.WebApplications) { listWebApplications.Items.Add(webApp.Name); } } else { listWebApplications.Items.Add("SPWebService.ContentService == null"); MessageBox.Show("No Content web application found. Are you Farm-Administrator? Is the database accessible?"); } if (listWebApplications.Items.Count > 0) { listSiteCollections.Enabled = true; } else { listSiteCollections.Enabled = false; } } }
/// <summary>UI method to update the SPWeb list when a user changes the selection in site collection list /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listSiteCollections_SelectedIndexChanged(object sender, EventArgs e) { if (listSiteCollections.SelectedIndex > -1) { using (WaitCursor wait = new WaitCursor()) { //Clear the lists listSites.Items.Clear(); clbSPSiteFeatures.Items.Clear(); clbSPWebFeatures.Items.Clear(); removeBtnEnabled(false); // tabControl1.Enabled = true; // tabControl1.Visible = true; //If there is only one site collection chosen, list the subsites. if (listSiteCollections.SelectedItems.Count == 1) { m_CurrentSite = m_CurrentWebApp.Sites[listSiteCollections.SelectedIndices[0]]; try { foreach (SPWeb web in m_CurrentSite.AllWebs) { listSites.Items.Add(web.Name + " - " + web.Title + " - " + web.Url); } } catch (Exception exc) { string msg = FormatSiteException(m_CurrentSite, exc, "Error enumerating webs"); ReportError(msg); logException(exc, msg); } //List the features for the site. //FillFeatureList(); } } } else { // tabControl1.Enabled = false; // tabControl1.Visible = false; } }
/// <summary>gets all the features from the selected Web Site and Site Collection</summary> private void getFeatures() { using (WaitCursor wait = new WaitCursor()) { ClearLog(); clbSPSiteFeatures.Items.Clear(); clbSPWebFeatures.Items.Clear(); //using (SPSite site = new SPSite(txtUrl.Text)) using (SPSite site = m_CurrentSite) { siteFeatureManager = new FeatureManager(site.Url); siteFeatureManager.AddFeatures(site.Features, SPFeatureScope.Site); //using (SPWeb web = site.OpenWeb()) using (SPWeb web = m_CurrentWeb) { webFeatureManager = new FeatureManager(web.Url); webFeatureManager.AddFeatures(web.Features, SPFeatureScope.Web); } } // sort the features list siteFeatureManager.Features.Sort(); clbSPSiteFeatures.Items.AddRange(siteFeatureManager.Features.ToArray()); string featlist = BuildFeatureLog(siteFeatureManager.Url, siteFeatureManager.Features); logTxt(featlist); // sort the features list webFeatureManager.Features.Sort(); clbSPWebFeatures.Items.AddRange(webFeatureManager.Features.ToArray()); featlist = BuildFeatureLog(webFeatureManager.Url, webFeatureManager.Features); logTxt(featlist); // enables the removal buttons // removeBtnEnabled(true); } // commented out, was too annoying // MessageBox.Show("Done."); logDateMsg("Feature list updated."); }
private List<ActivationFinder.Location> GetFeatureLocations(Guid featureId) { Dictionary<Guid, List<ActivationFinder.Location>> dict = null; if (allFeatureLocations != null) { // use preloaded data dict = allFeatureLocations; } else { using (WaitCursor wait = new WaitCursor()) { ActivationFinder finder = new ActivationFinder(); // No Found callback b/c we process final list finder.ExceptionListeners += new ActivationFinder.ExceptionHandler(logException); // Call routine to actually find & report activations dict = finder.FindAllActivations(featureId); } } if (dict.ContainsKey(featureId)) { return dict[featureId]; } else { return new List<ActivationFinder.Location>(); // empty list } }
private void ReloadAllActivationData() { using (WaitCursor wait = new WaitCursor()) { ActivationFinder finder = new ActivationFinder(); // No Found callback b/c we process final list finder.ExceptionListeners += new ActivationFinder.ExceptionHandler(logException); // Call routine to actually find & report activations m_featureDb.LoadAllData(finder.FindAllActivationsOfAllFeatures()); m_featureDb.MarkFaulty(finder.GetFaultyFeatureIdList()); lblFeatureDefinitions.Text = string.Format( "All {0} Features installed in the Farm", m_featureDb.GetAllFeaturesCount()); } }
private void btnLoadAllFeatureActivations_Click(object sender, EventArgs e) { using (WaitCursor wait = new WaitCursor()) { allFeatureLocations = null; ActivationFinder finder = new ActivationFinder(); // No Found callback b/c we process final list finder.ExceptionListeners += new ActivationFinder.ExceptionHandler(logException); // Call routine to actually find & report activations allFeatureLocations = finder.FindAllActivationsOfAllFeatures(); } string msgtext = string.Format( "Locations of {0} features loaded", allFeatureLocations.Count ); MessageBox.Show(msgtext); }
private void ReloadAllFeatureDefinitions() { using (WaitCursor wait = new WaitCursor()) { this.gridFeatureDefinitions.DataSource = null; ReloadAllActivationData(); // reloads defintions & activation data SortableBindingList<Feature> features = m_featureDb.GetAllFeatures(); //features.Sort(); //clbFeatureDefinitions. this.gridFeatureDefinitions.DataSource = features; //new SortableBindingList<Feature>(features); logDateMsg("Feature Definition list updated."); } }
/// <summary>Used to populate the list of Farm Feature Definitions</summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnLoadFDefs_Click(object sender, EventArgs e) { using (WaitCursor wait = new WaitCursor()) { this.clbFeatureDefinitions.Items.Clear(); farmFeatureDefinitionsManager = new FeatureManager("Farm FeatureDefinitions"); farmFeatureDefinitionsManager.AddFeatures(SPFarm.Local.FeatureDefinitions); farmFeatureDefinitionsManager.Features.Sort(); // Display any errors enumerating exceptions foreach (Feature feature in farmFeatureDefinitionsManager.Features) { if (!string.IsNullOrEmpty(feature.ExceptionMsg)) { logDateMsg("Exception reading feature " + feature.Id + ": " + feature.ExceptionMsg); } } //clbFeatureDefinitions. this.clbFeatureDefinitions.Items.AddRange(farmFeatureDefinitionsManager.Features.ToArray()); string featlist = BuildFeatureLog(farmFeatureDefinitionsManager.Url, farmFeatureDefinitionsManager.Features); logTxt(featlist); logDateMsg("Feature Definition list updated."); } // tabControl1.Enabled = false; // tabControl1.Visible = false; // listFeatures.Items.Clear(); // listDetails.Items.Clear(); }
/// <summary>Removes selected features from the current site collection only</summary> private void removeSPSiteFeaturesFromCurrentSite() { if (clbSPSiteFeatures.CheckedItems.Count == 0) { MessageBox.Show(NOFEATURESELECTED); logDateMsg(NOFEATURESELECTED); return; } if (clbSPWebFeatures.CheckedItems.Count > 0) { throw new Exception("Mixed mode unsupported"); } if (IsEmpty(m_CurrentSiteLocation)) { MessageBox.Show("No site collection currently selected"); return; } string msgString; msgString = "This will force remove/deactivate the selected Feature(s) from the selected Site Collection only. Continue ?"; if (MessageBox.Show(msgString, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return; } using (WaitCursor wait = new WaitCursor()) { using (SPSite site = OpenCurrentSite()) { List<Feature> scFeatures = GetSelectedSiteCollectionFeatures(); Location scLocation = LocationManager.CreateLocation(site); ForceRemoveFeaturesFromLocation(null, site.Features, scFeatures); } } msgString = "Done. Please refresh the feature list, when all features are removed!"; logDateMsg(msgString); }
/// <summary>Removes selected features from the current SiteCollection only</summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRemoveFromSiteCollection_Click(object sender, EventArgs e) { string msgString = string.Empty; if ((clbSPSiteFeatures.CheckedItems.Count > 0) || (clbSPWebFeatures.CheckedItems.Count > 0)) { int featuresRemoved = 0; if (clbSPSiteFeatures.CheckedItems.Count == 0) { // normal removal of SiteColl Features from one site collection removeSPWebFeaturesFromCurrentWeb(); return; } else { // check which message, because there should be a warning, // when spweb and spsite features are mixed up in one action if (clbSPWebFeatures.CheckedItems.Count == 0) { // only remove SPWeb features from a site collection msgString = "This will force remove/deactivate the selected Site scoped Feature(s) from the selected SiteCollection. Continue ?"; } else { msgString = "This will force remove/deactivate all selected Features (Scoped Site AND Web!) from " + "the complete SiteCollection. Please be aware, that the selected Web Scoped Features " + "will be removed from each Site within the currently selected Site Collection!! " + "It is recommended to select only one Feature for Multisite deletion! Continue?"; } if (MessageBox.Show(msgString, "Warning - Multi Site Deletion!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { using (WaitCursor wait = new WaitCursor()) { // the site collection features can be easily removed same as before featuresRemoved += DeleteSelectedFeatures(siteFeatureManager, clbSPSiteFeatures.CheckedItems); // the web features need a special treatment foreach (Feature checkedFeature in clbSPWebFeatures.CheckedItems) { featuresRemoved += removeWebFeaturesWithinSiteCollection(m_CurrentSite, checkedFeature.Id); } } removeReady(featuresRemoved); } } } else { MessageBox.Show(NOFEATURESELECTED); logDateMsg(NOFEATURESELECTED); } }
/// <summary>Removes selected features from the current SiteCollection only</summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRemoveFromSiteCollection_Click(object sender, EventArgs e) { if ((clbSPSiteFeatures.CheckedItems.Count == 0) && (clbSPWebFeatures.CheckedItems.Count == 0)) { MessageBox.Show(NOFEATURESELECTED); logDateMsg(NOFEATURESELECTED); } string msgString = string.Empty; if (clbSPWebFeatures.CheckedItems.Count == 0) { // Only site collection features // normal removal of SiteColl Features from one site collection removeSPSiteFeaturesFromCurrentSite(); return; } int featuresRemoved = 0; if (clbSPSiteFeatures.CheckedItems.Count != 0) { string msg = "Cannot remove site features and web features simultaneously"; MessageBox.Show(msg); return; } // only remove SPWeb features from a site collection msgString = "This will force remove/deactivate the selected Site (SPWeb) scoped Feature(s) from all sites within the selected SiteCollections. Continue ?"; if (MessageBox.Show(msgString, "Warning - Multi Site Deletion!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { return; } using (WaitCursor wait = new WaitCursor()) { using (SPSite site = OpenCurrentSite()) { if (site == null) { return; } // the web features need a special treatment foreach (Feature checkedFeature in clbSPWebFeatures.CheckedItems) { featuresRemoved += removeWebFeaturesWithinSiteCollection(site, checkedFeature.Id); } } } removeReady(featuresRemoved); }
/// <summary>Removes selected features from the current Web Application only</summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRemoveFromWebApp_Click(object sender, EventArgs e) { string msgString = string.Empty; int featuresRemoved = 0; int featuresSelected = clbSPSiteFeatures.CheckedItems.Count + clbSPWebFeatures.CheckedItems.Count; if (featuresSelected > 0) { msgString = "The " + featuresSelected + " selected Feature(s) " + "will be removed/deactivated from the complete web application: " + m_CurrentWebApp + ". Continue?"; if (MessageBox.Show(msgString, "Warning - Multi Site Deletion!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { using (WaitCursor wait = new WaitCursor()) { // remove web scoped features from web application featuresRemoved += removeAllSelectedFeatures(clbSPSiteFeatures.CheckedItems, SPFeatureScope.WebApplication, SPFeatureScope.Site); // remove SiteCollection scoped features from web application featuresRemoved += removeAllSelectedFeatures(clbSPWebFeatures.CheckedItems, SPFeatureScope.WebApplication, SPFeatureScope.Web); } removeReady(featuresRemoved); } } else { MessageBox.Show(NOFEATURESELECTED); logDateMsg(NOFEATURESELECTED); } }
/// <summary>Uninstall the selected Feature definition</summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnUninstFeatureDef_Click(object sender, EventArgs e) { List<Feature> selectedFeatures = GetSelectedFeatureDefinitions(); if (selectedFeatures.Count == 1) { Feature feature = selectedFeatures[0]; if (MessageBox.Show("This will forcefully uninstall the " + selectedFeatures.Count + " selected feature definition(s) from the Farm. Continue ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { if (MessageBox.Show("Before uninstalling a feature, it should be deactivated everywhere in the farm. " + "Should the Feature be removed from everywhere in the farm before it gets uninstalled?", "Please Select", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { // iterate through the farm to remove the feature if (feature.Scope == SPFeatureScope.ScopeInvalid) { RemoveInvalidFeature formScopeUnclear = new RemoveInvalidFeature(this, feature.Id); formScopeUnclear.Show(); return; } else { removeFeaturesWithinFarm(feature.Id, feature.Scope); } } using (WaitCursor wait = new WaitCursor()) { UninstallSelectedFeatureDefinitions(selectedFeatures); } } } else { MessageBox.Show("Please select exactly 1 feature."); } }
/// <summary>populate the web application list</summary> private void loadWebAppList() { using (WaitCursor wait = new WaitCursor()) { listWebApplications.Items.Clear(); listSiteCollections.Items.Clear(); listSites.Items.Clear(); clbSPSiteFeatures.Items.Clear(); clbSPWebFeatures.Items.Clear(); removeBtnEnabled(false); if (SPWebService.ContentService == null) { listWebApplications.Items.Add("SPWebService.ContentService == null! Access error?"); } if (SPWebService.AdministrationService == null) { listWebApplications.Items.Add("SPWebService.AdministrationService == null! Access error?"); } foreach (SPWebApplication webApp in GetAllWebApps()) { listWebApplications.Items.Add(webApp.Name); } if (listWebApplications.Items.Count > 0) { listSiteCollections.Enabled = true; // If there is only one, select it if (listWebApplications.Items.Count == 0) { listWebApplications.SelectedIndex = 0; } } else { listSiteCollections.Enabled = false; } } }