public static int ProcessAllFeaturesInWebApp(string webAppUrl, IEnumerable <Guid> featureIds, SPFeatureScope scope, bool activate, bool force, out Exception exception) { var processingCounter = 0; exception = null; if (string.IsNullOrEmpty(webAppUrl)) { exception = new ArgumentNullException("webAppUrl is null"); return(processingCounter); } try { var webApp = FarmRead.GetWebAppByUrl(webAppUrl); if (webApp == null) { exception = new ArgumentNullException("webApp not found by Url " + webAppUrl); return(processingCounter); } processingCounter += ProcessAllFeaturesInWebApp(webApp, featureIds, scope, activate, force, out exception); } catch (Exception ex) { exception = ex; } return(processingCounter); }
/// <summary>forcefully removes a feature definition from the farm feature definition collection</summary> /// <param name="id">Feature Definition ID</param> public static int Uninstall(Guid id, int compatibilityLevel, bool force, out Exception exception) { var processingCounter = 0; exception = null; try { var featureDefinitions = FarmRead.GetFeatureDefinitionCollection(); var featureDefinitionsBefore = featureDefinitions.Count; #if (SP2013) { featureDefinitions.Remove(id, compatibilityLevel, force); } #else { featureDefinitions.Remove(id, force); } #endif processingCounter = featureDefinitionsBefore - featureDefinitions.Count; } catch (Exception ex) { exception = ex; } return(processingCounter); }
public static SPWebApplication GetWebAppByUrl(string webAppUrl) { if (string.IsNullOrEmpty(webAppUrl)) { return(null); } SPWebApplication webApp = null; // first try content web apps: var webApps = FarmRead.GetWebApplicationsContent(); if (webApps != null && webApps.Count > 0) { webApp = webApps.FirstOrDefault(wa => wa.GetResponseUri(SPUrlZone.Default).ToString().Equals(webAppUrl, StringComparison.InvariantCultureIgnoreCase)); } // else try admin web apps: if (webApp == null) { webApps = FarmRead.GetWebApplicationsAdmin(); if (webApps != null && webApps.Count > 0) { webApp = webApps.FirstOrDefault(wa => wa.GetResponseUri(SPUrlZone.Default).ToString().Equals(webAppUrl, StringComparison.InvariantCultureIgnoreCase)); } } return(webApp); }
private static int ProcessAllFeaturesInFarm(SPWebService farm, IEnumerable <Guid> featureIds, SPFeatureScope scope, bool activate, bool force, out Exception exception) { var processingCounter = 0; exception = null; if (farm == null) { exception = new ArgumentNullException("farm is null"); return(processingCounter); } try { if (scope == SPFeatureScope.Farm || scope == SPFeatureScope.ScopeInvalid) { processingCounter += ProcessAllFarmFeaturesInFarm(farm, featureIds, activate, force, out exception); } if (scope != SPFeatureScope.Farm) { SPWebApplicationCollection webApps = FarmRead.GetWebApplicationsContent(); if (webApps != null && webApps.Count > 0) { foreach (SPWebApplication wa in webApps) { processingCounter += ProcessAllFeaturesInWebApp(wa, featureIds, scope, activate, force, out exception); } } webApps = FarmRead.GetWebApplicationsAdmin(); if (webApps != null && webApps.Count > 0) { foreach (SPWebApplication wa in webApps) { processingCounter += ProcessAllFeaturesInWebApp(wa, featureIds, scope, activate, force, out exception); } } } } catch (Exception ex) { exception = ex; } return(processingCounter); }
private static int ProcessAllFeaturesInFarm(IEnumerable <Guid> featureIds, SPFeatureScope scope, bool activate, bool force, out Exception exception) { var processingCounter = 0; exception = null; try { var farm = FarmRead.GetFarm(); if (farm == null) { exception = new ArgumentNullException("farm is null !? not enough rights?"); return(processingCounter); } processingCounter += ProcessAllFeaturesInFarm(farm, featureIds, scope, activate, force, out exception); } catch (Exception ex) { exception = ex; } return(processingCounter); }