Esempio n. 1
0
        public void AddFeatureLocation(FeatureLoc floc)
        {
            switch (floc.Scope)
            {
            case SPFeatureScope.WebApplication:
                RecordFeatures(WebAppFeatures, floc);
                WebAppLocations.Add(floc);
                break;

            case SPFeatureScope.Site:
                RecordFeatures(SiteFeatures, floc);
                SiteLocations.Add(floc);
                break;

            case SPFeatureScope.Web:
                RecordFeatures(WebFeatures, floc);
                WebLocations.Add(floc);
                break;

            case SPFeatureScope.Farm:
                RecordFeatures(FarmFeatures, floc);
                FarmLocations.Add(floc);
                break;
            }
            ++_LocationsCount;
            _ActivationsCount += floc.featureList.Count;
        }
Esempio n. 2
0
 private void AddFeatureIdToFeatureLoc(FeatureLoc floc, Guid featureId)
 {
     if (floc.featureList == null)
     {
         floc.featureList = new List <Guid>();
     }
     floc.featureList.Add(featureId);
 }
Esempio n. 3
0
 private void RecordFeatures(Dictionary <Guid, int> features, FeatureLoc floc)
 {
     foreach (Guid featureId in floc.featureList)
     {
         int count = 0;
         if (features.ContainsKey(featureId))
         {
             count = features[featureId];
         }
         ++count;
         features[featureId] = count;
     }
 }
Esempio n. 4
0
        private void DoWebActivations()
        {
            string method = string.Format(CommonUIStrings.deactivateWebFeatureMessage
                                          , requestedLocs.WebFeatures.Count, requestedLocs.WebLocations.Count);

            if (direction == ActivationDirection.Activate)
            {
                method = string.Format(CommonUIStrings.activateWebFeatureMessage
                                       , requestedLocs.WebFeatures.Count, requestedLocs.WebLocations.Count);
            }

            string context = method;

            log.Info(context);
            try
            {
                foreach (FeatureLoc floc in requestedLocs.WebLocations)
                {
                    FeatureLoc completedLoc = FeatureLoc.CopyExceptFeatureList(floc);

                    SPSite site = null;
                    SPWeb  web  = null;
                    try
                    {
                        site = new SPSite(floc.SiteId);
                        web  = site.OpenWeb(floc.WebId);
                        string webName = web.Url;

                        foreach (Guid featureId in floc.featureList)
                        {
                            context = method + " feature: " + featureId.ToString();

                            if (direction == ActivationDirection.Activate)
                            {
                                if (IsFeatureActivatedOnWeb(web, featureId))
                                {
                                    string msg = string.Format(CommonUIStrings.ActivatingSkipped_FeatureAlreadyActiveOnWeb
                                                               , GetFeatureName(featureId), webName);
                                    log.Warn(msg);
                                }
                                else
                                {
                                    ActivateOneFeature(web.Features, featureId, log);

                                    if (!IsFeatureActivatedOnWeb(web, featureId))
                                    {
                                        // do not add to completedLocs, b/c it didn't complete
                                        log.Warn("Activation failed on web : " + GetFeatureName(featureId));
                                    }
                                    else
                                    {
                                        AddFeatureIdToFeatureLoc(completedLoc, featureId);
                                        log.Info(context + " : " + GetFeatureName(featureId));
                                    }
                                }
                            }
                            else
                            {
                                if (IsFeatureActivatedOnWeb(web, featureId))
                                {
                                    web.Features.Remove(featureId, true);
                                    AddFeatureIdToFeatureLoc(completedLoc, featureId);
                                    log.Info(context + " : " + GetFeatureName(featureId));
                                }
                                else
                                {
                                    string msg = string.Format(CommonUIStrings.DeactivatingSkipped_FeatureAlreadyActiveOnWeb
                                                               , GetFeatureName(featureId), webName);
                                    log.Warn(msg);
                                }
                            }
                        }
                        if (completedLoc.featureList != null)
                        {
                            completedLocs.AddFeatureLocation(completedLoc);
                        }
                    }
                    finally
                    {
                        if (web != null)
                        {
                            web.Dispose();
                            web = null;
                        }
                        if (site != null)
                        {
                            site.Dispose();
                            site = null;
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                log.Error(context, exc);
                throw exc;
            }
        }
Esempio n. 5
0
        private void DoWebAppActivations()
        {
            string method = string.Format(CommonUIStrings.deactivateWebAppFeatureMessage
                                          , requestedLocs.WebAppFeatures.Count, requestedLocs.WebAppLocations.Count);

            if (direction == ActivationDirection.Activate)
            {
                method = string.Format(CommonUIStrings.activateWebAppFeatureMessage
                                       , requestedLocs.WebAppFeatures.Count, requestedLocs.WebAppLocations.Count);
            }

            string context = method;

            log.Info(context);
            try
            {
                foreach (FeatureLoc floc in requestedLocs.WebAppLocations)
                {
                    FeatureLoc       completedLoc = FeatureLoc.CopyExceptFeatureList(floc);
                    SPWebApplication webapp       = ActivationReporter.GetWebAppById(floc.WebAppId);
                    string           webappName   = ActivationReporter.GetWebAppName(webapp);

                    foreach (Guid featureId in floc.featureList)
                    {
                        context = method + " feature: " + featureId.ToString();

                        if (direction == ActivationDirection.Activate)
                        {
                            if (IsFeatureActivatedOnWebApp(webapp, featureId))
                            {
                                string msg = string.Format(CommonUIStrings.ActivatingSkipped_FeatureAlreadyActiveOnWebApp
                                                           , GetFeatureName(featureId), webappName);
                                log.Warn(msg);
                            }
                            else
                            {
                                ActivateOneFeature(webapp.Features, featureId, log);

                                if (!IsFeatureActivatedOnWebApp(webapp, featureId))
                                {
                                    // do not add to completedLocs, b/c it didn't complete
                                    log.Warn("Activation failed on webapp : " + GetFeatureName(featureId));
                                }
                                else
                                {
                                    AddFeatureIdToFeatureLoc(completedLoc, featureId);
                                    log.Info(context + " : " + GetFeatureName(featureId));
                                }
                            }
                        }
                        else
                        {
                            if (IsFeatureActivatedOnWebApp(webapp, featureId))
                            {
                                webapp.Features.Remove(featureId, true);
                                AddFeatureIdToFeatureLoc(completedLoc, featureId);
                                log.Info(context + " : " + GetFeatureName(featureId));
                            }
                            else
                            {
                                string msg = string.Format(CommonUIStrings.DeactivatingSkipped_FeatureAlreadyActiveOnWebApp
                                                           , GetFeatureName(featureId), webappName);
                                log.Warn(msg);
                            }
                        }
                    }
                    if (completedLoc.featureList != null)
                    {
                        completedLocs.AddFeatureLocation(completedLoc);
                    }
                }
            }
            catch (Exception exc)
            {
                log.Error(context, exc);
                throw exc;
            }
        }
Esempio n. 6
0
        private void DoFarmActivations()
        {
            string method = string.Format(CommonUIStrings.deactivateFarmFeatureMessage, requestedLocs.FarmFeatures.Count);

            if (direction == ActivationDirection.Activate)
            {
                method = string.Format(CommonUIStrings.activateFarmFeatureMessage, requestedLocs.FarmFeatures.Count);
            }

            string context = method;

            log.Info(context);
            try
            {
                if (requestedLocs.FarmLocations.Count > 1)
                {
                    throw new Exception("Error: requestedLocs.FarmLocations.Count > 1");
                }
                FeatureLoc floc         = requestedLocs.FarmLocations[0];
                FeatureLoc completedLoc = FeatureLoc.CopyExceptFeatureList(floc);
                SPFarm     farm         = SPFarm.Local;
                foreach (Guid featureId in floc.featureList)
                {
                    context = method + " feature: " + featureId.ToString();

                    SPWebService adminService = SPWebService.AdministrationService;
                    if (direction == ActivationDirection.Activate)
                    {
                        if (IsFeatureActivatedOnFarm(farm, featureId))
                        {
                            string msg = string.Format(CommonUIStrings.ActivatingSkipped_FeatureAlreadyActiveOnFarm
                                                       , GetFeatureName(featureId));
                            log.Warn(msg);
                        }
                        else
                        {
                            ActivateOneFeature(adminService.Features, featureId, log);

                            if (!IsFeatureActivatedOnFarm(farm, featureId))
                            {
                                // do not add to completedLocs, b/c it didn't complete
                                log.Warn("Activation failed on farm : " + GetFeatureName(featureId));
                            }
                            else
                            {
                                AddFeatureIdToFeatureLoc(completedLoc, featureId);
                                log.Info(context + " : " + GetFeatureName(featureId));
                            }
                        }
                    }
                    else
                    {
                        if (IsFeatureActivatedOnFarm(farm, featureId))
                        {
                            adminService.Features.Remove(featureId, true);
                            AddFeatureIdToFeatureLoc(completedLoc, featureId);
                            log.Info(context + " : " + GetFeatureName(featureId));
                        }
                        else
                        {
                            string msg = string.Format(CommonUIStrings.DeactivatingSkipped_FeatureAlreadyActiveOnFarm
                                                       , GetFeatureName(featureId));
                            log.Warn(msg);
                        }
                    }
                }
                if (completedLoc.featureList != null)
                {
                    completedLocs.AddFeatureLocation(completedLoc);
                }
            }
            catch (Exception exc)
            {
                log.Error(context, exc);
                throw exc;
            }
        }
 private void AddFeatureIdToFeatureLoc(FeatureLoc floc, Guid featureId)
 {
     if (floc.featureList == null)
     {
         floc.featureList = new List<Guid>();
     }
     floc.featureList.Add(featureId);
 }
Esempio n. 8
0
        public List <Guid> featureList; // features previously deactivated here

        public static FeatureLoc CopyExceptFeatureList(FeatureLoc floc)
        {
            return(new FeatureLoc(floc.Scope, floc.WebAppId, floc.SiteId, floc.WebId));
        }
 private void RecordFeatures(Dictionary<Guid, int> features, FeatureLoc floc)
 {
     foreach (Guid featureId in floc.featureList)
     {
         int count = 0;
         if (features.ContainsKey(featureId))
         {
             count = features[featureId];
         }
         ++count;
         features[featureId] = count;
     }
 }
 public void AddFeatureLocation(FeatureLoc floc)
 {
     switch (floc.Scope)
     {
         case SPFeatureScope.WebApplication:
             RecordFeatures(WebAppFeatures, floc);
             WebAppLocations.Add(floc);
             break;
         case SPFeatureScope.Site:
             RecordFeatures(SiteFeatures, floc);
             SiteLocations.Add(floc);
             break;
         case SPFeatureScope.Web:
             RecordFeatures(WebFeatures, floc);
             WebLocations.Add(floc);
             break;
         case SPFeatureScope.Farm:
             RecordFeatures(FarmFeatures, floc);
             FarmLocations.Add(floc);
             break;
     }
     ++_LocationsCount;
     _ActivationsCount += floc.featureList.Count;
 }
 public static FeatureLoc CopyExceptFeatureList(FeatureLoc floc)
 {
     return new FeatureLoc(floc.Scope, floc.WebAppId, floc.SiteId, floc.WebId);
 }