private void InitiateEnumerator(SPEnumerator enumerator) { if (enumerator != null) { // Listen for web application events so that we can export the settings for the specified application. enumerator.SPWebApplicationEnumerated += new SPEnumerator.SPWebApplicationEnumeratedEventHandler(OnSPWebApplicationEnumerated); enumerator.SPSiteEnumerated += new SPEnumerator.SPSiteEnumeratedEventHandler(OnSPSiteEnumerated); enumerator.Enumerate(); } }
protected override void UpdateDataObject() { ShouldProcessReason reason; if (!base.ShouldProcess("Set Quotas", null, null, out reason)) { if (reason == ShouldProcessReason.WhatIf) { m_whatIf = true; } } SPFarm farm = SPFarm.Local; SPWebService webService = farm.Services.GetValue <SPWebService>(""); m_quotaColl = webService.QuotaTemplates; m_setQuota = !SyncExistingOnly.IsPresent; if (QuotaTemplate != null) { m_quota = QuotaTemplate.Read(); if (m_quota == null) { throw new SPCmdletException("The specified quota template name could not be found."); } } SPEnumerator enumerator = null; switch (ParameterSetName) { case "SPSite1": case "SPSite2": Sync(Site.Read()); return; case "SPWebApplication1": case "SPWebApplication2": enumerator = new SPEnumerator(WebApplication.Read()); break; default: enumerator = new SPEnumerator(Farm.Read()); break; } enumerator.SPSiteEnumerated += enumerator_SPSiteEnumerated; enumerator.Enumerate(); }
internal void ActivateDeactivateFeatureAtScope(SPFeatureDefinition feature, ActivationScope scope, bool activate, string url, bool force, bool ignoreNonActive) { m_IgnoreNonActive = ignoreNonActive; m_Activate = activate; m_Force = force; m_Url = url; m_FeatureId = feature.Id; if (feature.Scope == SPFeatureScope.Farm) { if (scope != ActivationScope.Farm) { throw new SPSyntaxException("The Feature specified is scoped to the Farm. The -scope parameter must be \"Farm\"."); } ActivateDeactivateFeatureAtFarm(activate, m_FeatureId, m_Force, m_IgnoreNonActive); } else if (feature.Scope == SPFeatureScope.WebApplication) { if (scope != ActivationScope.Farm && scope != ActivationScope.WebApplication) { throw new SPSyntaxException("The Feature specified is scoped to the Web Application. The -scope parameter must be either \"Farm\" or \"WebApplication\"."); } if (scope == ActivationScope.Farm) { SPEnumerator enumerator = new SPEnumerator(SPFarm.Local); enumerator.SPWebApplicationEnumerated += enumerator_SPWebApplicationEnumerated; enumerator.Enumerate(); } else { if (string.IsNullOrEmpty(m_Url)) { throw new SPSyntaxException("The -url parameter is required if the scope is \"WebApplication\"."); } SPWebApplication webApp = SPWebApplication.Lookup(new Uri(m_Url)); ActivateDeactivateFeatureAtWebApplication(webApp, m_FeatureId, activate, m_Force, m_IgnoreNonActive); } } else if (feature.Scope == SPFeatureScope.Site) { if (scope == ActivationScope.Web) { throw new SPSyntaxException("The Feature specified is scoped to Site. The -scope parameter cannot be \"Web\"."); } SPSite site = null; SPEnumerator enumerator = null; try { if (scope == ActivationScope.Farm) { enumerator = new SPEnumerator(SPFarm.Local); } else if (scope == ActivationScope.WebApplication) { SPWebApplication webApp = SPWebApplication.Lookup(new Uri(m_Url)); enumerator = new SPEnumerator(webApp); } else if (scope == ActivationScope.Site) { site = new SPSite(m_Url); ActivateDeactivateFeatureAtSite(site, activate, m_FeatureId, m_Force, m_IgnoreNonActive); } if (enumerator != null) { enumerator.SPSiteEnumerated += enumerator_SPSiteEnumerated; enumerator.Enumerate(); } } finally { if (site != null) { site.Dispose(); } } } else if (feature.Scope == SPFeatureScope.Web) { SPSite site = null; SPWeb web = null; SPEnumerator enumerator = null; try { if (scope == ActivationScope.Farm) { enumerator = new SPEnumerator(SPFarm.Local); } else if (scope == ActivationScope.WebApplication) { SPWebApplication webApp = SPWebApplication.Lookup(new Uri(m_Url)); enumerator = new SPEnumerator(webApp); } else if (scope == ActivationScope.Site) { site = new SPSite(m_Url); enumerator = new SPEnumerator(site); } else if (scope == ActivationScope.Web) { site = new SPSite(m_Url); web = site.AllWebs[Utilities.GetServerRelUrlFromFullUrl(m_Url)]; enumerator = new SPEnumerator(web); } if (enumerator != null) { enumerator.SPWebEnumerated += enumerator_SPWebEnumerated; enumerator.Enumerate(); } } finally { if (web != null) { web.Dispose(); } if (site != null) { site.Dispose(); } } } }