コード例 #1
0
            /// <summary>
            /// Actually activate/deactivate users specified features on all listed locations
            /// </summary>
            protected internal override bool Execute()
            {
                log.Info(this.Description);

                ReadOnlyCollection <Guid?> featureIds = InstallConfiguration.FeatureIdList;

                if (featureIds == null || featureIds.Count == 0)
                {
                    log.Warn(CommonUIStrings.logNoFeaturesSpecified);
                    return(true);
                }
                if (requestedLocs == null || requestedLocs.LocationsCount == 0)
                {
                    // caller responsible for giving message, depending on operation (install, upgrade,...) ?
                    log.Warn(CommonUIStrings.logNoLocationsForActivationDeactivation);
                    return(true);
                }

                FeatureActivator.PerformActivations(direction, operation, log);

                return(true);
            }
コード例 #2
0
        public static void PerformActivations(ActivationDirection direction, InstallOperation operation, ILog log)
        {
            FeatureActivator factor = new FeatureActivator(direction, operation, log);

            try
            {
                factor.PerformAllActivations();
                return;
            }
            catch (Exception exc)
            {
                log.Error("Error: " + direction.ToString(), exc);
            }
            if (factor.rollback)
            {
                return;
            }
            if (factor.completedLocs.LocationsCount == 0)
            {
                log.Info("No feature de/activations completed, so none to rollback");
                return;
            }

            // Switch actions & execute rollback
            factor.rollback      = true;
            factor.direction     = (factor.direction == ActivationDirection.Activate ? ActivationDirection.Deactivate : ActivationDirection.Activate);
            factor.requestedLocs = factor.completedLocs;
            try
            {
                log.Info("Rollback: " + FeatureActivator.Describe(factor.requestedLocs, factor.direction));
                factor.PerformAllActivations();
            }
            catch (Exception exc)
            {
                log.Error("Error during rollback: " + direction.ToString(), exc);
            }
        }
コード例 #3
0
 protected internal override bool Execute()
 {
     try
     {
         // Modif JPI - Début
         ReadOnlyCollection <Guid?> featureIds = InstallConfiguration.FeatureIdList;
         if (featureIds != null && featureIds.Count > 0)
         {
             foreach (Guid?featureId in featureIds)
             {
                 if (featureId != null)
                 {
                     SPFeature feature = FeatureActivator.ActivateOneFeature(SPWebService.AdministrationService.Features, featureId.Value, log);
                 }
             }
         }
         return(true);
         // Modif JPI - Fin
     }
     catch (Exception ex)
     {
         throw new InstallException(ex.Message, ex);
     }
 }
コード例 #4
0
 public static string GetFeatureName(Guid?featureId)
 {
     return(FeatureActivator.GetFeatureName(featureId));
 }
コード例 #5
0
            /// <summary>
            /// Actually activate/deactivate users specified features on requested web list
            /// </summary>
            protected internal override bool Execute()
            {
                if (command == WebCommand.Activate)
                {
                    log.Info(CommonUIStrings.logFeatureActivate);
                }
                else
                {
                    log.Info(CommonUIStrings.logFeatureDeactivate);
                }
                ReadOnlyCollection <Guid?> featureIds = InstallConfiguration.FeatureIdList;

                if (featureIds == null || featureIds.Count == 0)
                {
                    log.Warn(CommonUIStrings.logNoFeaturesSpecified);
                    return(true);
                }
                if (webLocs == null || webLocs.Count == 0)
                {
                    // caller responsible for giving message, depending on operation (install, upgrade,...)
                    return(true);
                }
                try
                {
                    foreach (WebLoc webLoc in webLocs)
                    {
                        SPSite siteCollection = null;
                        SPWeb  web            = null;
                        try
                        {
                            siteCollection = new SPSite(webLoc.siteInfo.SiteId);
                            web            = siteCollection.OpenWeb(webLoc.WebId);

                            foreach (Guid?featureId in webLoc.featureList)
                            {
                                if (featureId == null)
                                {
                                    continue;
                                }

                                if (command == WebCommand.Activate)
                                {
                                    FeatureActivator.ActivateOneFeature(web.Features, featureId.Value, log);
                                    if (!FeatureActivator.IsFeatureActivatedOnWeb(web, featureId.Value))
                                    {
                                        // do not add to completedLocs, b/c it didn't complete
                                        log.Warn("Activation failed on " + web.Url + " : " + GetFeatureName(featureId));
                                    }
                                    else
                                    {
                                        completedLocs.Add(webLoc);
                                        log.Info(web.Url + " : " + GetFeatureName(featureId));
                                    }
                                }
                                else
                                {
                                    web.Features.Remove(featureId.Value, true);
                                    completedLocs.Add(webLoc);
                                    log.Info(web.Url + " : " + GetFeatureName(featureId));
                                }
                            }
                        }
                        catch (Exception exc)
                        {
                            if (rollback)
                            {
                                // during rollback simply log errors and continue
                                string message;
                                if (command == WebCommand.Activate)
                                {
                                    message = "Activating feature(s)";
                                }
                                else
                                {
                                    message = "Deactivating feature(s)";
                                }
                                log.Error(message, exc);
                            }
                            else
                            {
                                throw exc;
                            }
                        }
                        finally
                        {
                            // guarantee SPWeb is released ASAP even in face of exception
                            if (web != null)
                            {
                                web.Dispose();
                            }
                            // guarantee SPSite is released ASAP even in face of exception
                            if (siteCollection != null)
                            {
                                siteCollection.Dispose();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message, ex);
                }
                return(true);
            }
コード例 #6
0
            /// <summary>
            /// Actually activate/deactivate users specified features on requested site collection list
            /// </summary>
            protected internal override bool Execute()
            {
                if (command == SiteCollectionCommand.Activate)
                {
                    log.Info(CommonUIStrings.logFeatureActivate);
                }
                else
                {
                    log.Info(CommonUIStrings.logFeatureDeactivate);
                }
                ReadOnlyCollection <Guid?> featureIds = InstallConfiguration.FeatureIdList;

                if (featureIds == null || featureIds.Count == 0)
                {
                    log.Warn(CommonUIStrings.logNoFeaturesSpecified);
                    return(true);
                }
                if (siteCollectionLocs == null || siteCollectionLocs.Count == 0)
                {
                    // caller responsible for giving message, depending on operation (install, upgrade,...)
                    return(true);
                }
                try
                {
                    foreach (SiteLoc siteLoc in siteCollectionLocs)
                    {
                        SPSite siteCollection = null;
                        try
                        {
                            siteCollection = new SPSite(siteLoc.SiteId);
                            foreach (Guid?featureId in siteLoc.featureList)
                            {
                                if (featureId == null)
                                {
                                    continue;
                                }

                                if (command == SiteCollectionCommand.Activate)
                                {
                                    FeatureActivator.ActivateOneFeature(siteCollection.Features, featureId.Value, log);
                                    if (!FeatureActivator.IsFeatureActivatedOnSite(siteCollection, featureId.Value))
                                    {
                                        // do not add to completedLocs, b/c it didn't complete
                                        log.Warn("Activation failed on " + siteCollection.Url + " : " + GetFeatureName(featureId));
                                    }
                                    else
                                    {
                                        completedLocs.Add(siteLoc);
                                        log.Info(siteCollection.Url + " : " + GetFeatureName(featureId));
                                    }
                                }
                                else
                                {
                                    siteCollection.Features.Remove(featureId.Value, true);
                                    completedLocs.Add(siteLoc);
                                    log.Info(siteCollection.Url + " : " + GetFeatureName(featureId));
                                }
                            }
                        }
                        catch (Exception exc)
                        {
                            if (rollback)
                            {
                                // during rollback simply log errors and continue
                                string message;
                                if (command == SiteCollectionCommand.Activate)
                                {
                                    message = "Activating feature(s)";
                                }
                                else
                                {
                                    message = "Deactivating feature(s)";
                                }
                                log.Error(message, exc);
                            }
                            else
                            {
                                log.Error(siteCollection.Url);
                                throw exc;
                            }
                        }
                        finally
                        {
                            // guarantee SPSite is released ASAP even in face of exception
                            if (siteCollection != null)
                            {
                                siteCollection.Dispose();
                            }
                        }
                    }

                    return(true);
                }
                catch (Exception exc)
                {
                    if (rollback)
                    {
                        log.Error("Error during rollback", exc);
                        return(false);
                    }
                    rollback = true;
                    // rollback work accomplished so far
                    if (command == SiteCollectionCommand.Activate)
                    {
                        DeactivateSiteCollectionFeatureCommand reverseCommand = new DeactivateSiteCollectionFeatureCommand(this.Parent, completedLocs);
                        reverseCommand.Execute();
                    }
                    else
                    {
                        ActivateSiteCollectionFeatureCommand reverseCommand = new ActivateSiteCollectionFeatureCommand(this.Parent, completedLocs);
                        reverseCommand.Execute();
                    }
                    throw exc;
                }
            }
コード例 #7
0
        public static void PerformActivations(ActivationDirection direction, InstallOperation operation, ILog log)
        {
            FeatureActivator factor = new FeatureActivator(direction, operation, log);
            try
            {
                factor.PerformAllActivations();
                return;
            }
            catch (Exception exc)
            {
                log.Error("Error: " + direction.ToString(), exc);
            }
            if (factor.rollback) return;
            if (factor.completedLocs.LocationsCount == 0)
            {
                log.Info("No feature de/activations completed, so none to rollback");
                return;
            }

            // Switch actions & execute rollback
            factor.rollback = true;
            factor.direction = (factor.direction == ActivationDirection.Activate ? ActivationDirection.Deactivate : ActivationDirection.Activate);
            factor.requestedLocs = factor.completedLocs;
            try
            {
                log.Info("Rollback: " + FeatureActivator.Describe(factor.requestedLocs, factor.direction));
                factor.PerformAllActivations();
            }
            catch (Exception exc)
            {
                log.Error("Error during rollback: " + direction.ToString(), exc);
            }
        }
コード例 #8
0
 public static string Describe(FeatureLocations locs, FeatureActivator.ActivationDirection direction)
 {
     string fmt = (direction == FeatureActivator.ActivationDirection.Activate ? CommonUIStrings.activatingFeaturesMessage
         : CommonUIStrings.deactivatingFeaturesMessage);
     return String.Format(fmt
         , locs.ActivationsCount
         , InstallConfiguration.FeatureIdList.Count
         , locs.LocationsCount
     );
 }
コード例 #9
0
 private FeaturesCommand(InstallProcessControl parent, FeatureActivator.ActivationDirection direction, InstallOperation operation)
     : base(parent)
 {
     this.direction = direction;
     this.operation = operation;
     requestedLocs = InstallProcessControl.GetFeaturedLocations(operation);
 }