public void ActivateFeaturesInWeb(SPWeb web, List <Feature> features)
 {
     foreach (Feature feature in features)
     {
         if (feature.Scope == SPFeatureScope.Web)
         {
             try
             {
                 if (!(web.Features[feature.Id] is SPFeature))
                 {
                     web.Features.Add(feature.Id);
                     ++Activations;
                 }
             }
             catch (Exception exc)
             {
                 LogException(exc, string.Format(
                                  "Attempting to activate web feature {0} on web {1}",
                                  feature.Id,
                                  LocationManager.SafeDescribeObject(web)
                                  ));
             }
         }
     }
 }
 /// <summary>
 /// Activate any webapp features on specified web application
 /// </summary>
 private void ActivateFeaturesInWebApp(SPWebApplication webapp, List <Feature> features)
 {
     foreach (Feature feature in features)
     {
         if (feature.Scope == SPFeatureScope.WebApplication)
         {
             try
             {
                 if (!(SPWebService.ContentService.Features[feature.Id] is SPFeature))
                 {
                     SPWebService.ContentService.Features.Add(feature.Id);
                     ++Activations;
                 }
             }
             catch (Exception exc)
             {
                 LogException(exc, string.Format(
                                  "Attempting to activate webapp feature {0} on webapp {1}",
                                  feature.Id,
                                  LocationManager.SafeDescribeObject(webapp)
                                  ));
             }
         }
     }
 }
 /// <summary>
 /// Activate any site level features on specified site
 /// </summary>
 private void ActivateFeaturesInSiteCollection(SPSite site, List <Feature> features)
 {
     foreach (Feature feature in features)
     {
         if (feature.Scope == SPFeatureScope.Site)
         {
             try
             {
                 if (!(site.Features[feature.Id] is SPFeature))
                 {
                     site.Features.Add(feature.Id);
                     ++Activations;
                 }
             }
             catch (Exception exc)
             {
                 LogException(exc, string.Format(
                                  "Attempting to activate site feature {0} on site {1}",
                                  feature.Id,
                                  LocationManager.SafeDescribeObject(site)
                                  ));
             }
         }
     }
 }
Example #4
0
 private void PerformAction(object locobj, SPFeatureCollection spFeatureCollection, Feature feature)
 {
     try
     {
         if (_action == Action.Activating)
         {
             if (!(spFeatureCollection[feature.Id] is SPFeature))
             {
                 ++ActivationAttempts;
                 spFeatureCollection.Add(feature.Id);
                 if ((spFeatureCollection[feature.Id] is SPFeature))
                 {
                     _featureDb.RecordFeatureActivation(locobj, feature.Id);
                     ++Activations;
                 }
             }
         }
         else
         {
             if ((spFeatureCollection[feature.Id] is SPFeature))
             {
                 ++ActivationAttempts;
                 spFeatureCollection.Remove(feature.Id);
                 if (!(spFeatureCollection[feature.Id] is SPFeature))
                 {
                     _featureDb.RecordFeatureDeactivation(locobj, feature.Id);
                     ++Activations;
                 }
             }
         }
     }
     catch (Exception exc)
     {
         LogException(exc, string.Format(
                          "{0} feature {1} on {2}: {3}",
                          _action,
                          feature.Id,
                          feature.Scope,
                          LocationManager.SafeDescribeObject(locobj)
                          ));
     }
 }