Пример #1
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;
            }
        }