Ejemplo n.º 1
0
        private void ReportFeature(object obj, bool faulty, SPFeatureScope scope, Guid featureId, string url, string name)
        {
            OnFoundFeature(featureId, url, name);
            FeatureParent        location = LocationManager.GetLocation(obj);
            List <FeatureParent> locs     = null;

            if (featureLocations.ContainsKey(featureId))
            {
                locs = featureLocations[featureId];
            }
            else
            {
                locs = new List <FeatureParent>();
            }
            locs.Add(location);
            featureLocations[featureId] = locs;
            if (faulty)
            {
                int faults = 0;
                if (faultyFeatures.ContainsKey(featureId))
                {
                    faults = faultyFeatures[featureId];
                }
                ++faults;
                faultyFeatures[featureId] = faults;
            }
        }
        public List<Guid> featureList; // features previously deactivated here

        #endregion Fields

        #region Constructors

        public FeatureLoc(SPWeb web)
        {
            this.Scope = SPFeatureScope.Web;
            this.WebId = web.ID;
            this.SiteId = web.Site.ID;
            this.WebAppId = web.Site.WebApplication.Id;
        }
Ejemplo n.º 3
0
 public FeatureLoc(SPWeb web)
 {
     this.Scope    = SPFeatureScope.Web;
     this.WebId    = web.ID;
     this.SiteId   = web.Site.ID;
     this.WebAppId = web.Site.WebApplication.Id;
 }
Ejemplo n.º 4
0
        private void FindWebApplication(SPFeatureReceiverProperties properties)
        {
            SPFeatureScope scope = properties.Feature.Definition.Scope;

            if (scope == SPFeatureScope.Web)
            {
                SPWeb       web       = properties.Feature.Parent as SPWeb;
                SPUserToken oSysToken = GetSysToken(web.Site.ID);
                using (SPSite centralSite = new SPSite(web.Site.ID, oSysToken))
                {
                    webApp = centralSite.WebApplication;
                }
            }


            if (scope == SPFeatureScope.Site)
            {
                SPSite site = properties.Feature.Parent as SPSite;

                SPUserToken oSysToken = GetSysToken(site.ID);
                using (SPSite centralSite = new SPSite(site.ID, oSysToken))
                {
                    webApp = centralSite.WebApplication;
                }
            }

            if (scope == SPFeatureScope.WebApplication)
            {
                webApp = properties.Feature.Parent as SPWebApplication;
            }
        }
Ejemplo n.º 5
0
 private FeatureLoc(SPFeatureScope scope, Guid WebAppId, Guid SiteId, Guid WebId)
 {
     this.Scope    = scope;
     this.WebAppId = WebAppId;
     this.SiteId   = SiteId;
     this.WebId    = WebId;
 }
Ejemplo n.º 6
0
 public FeatureParent(string displayName, string url, Guid id, SPFeatureScope scope, Guid?contentDatabaseId = null)
 {
     DisplayName       = displayName;
     Url               = url;
     Id                = id;
     Scope             = scope;
     ContentDatabaseId = contentDatabaseId;
 }
        private void AddFeaturesForWA(SPWebApplication wa, TreeNode pnode)
        {
            SPFeatureScope      Scope  = SPFeatureScope.WebApplication;
            SPFeatureCollection active = wa.Features;

            List <SPFeatureDefinition> fds = SPBroker.GetAllFeaturesForScope(Scope);

            AddFeaturesForScope(pnode, fds, active);
        }
        private void AddFeaturesForSC(SPSite col, TreeNode pnode)
        {
            SPFeatureScope      Scope  = SPFeatureScope.Site;
            SPFeatureCollection active = col.Features;

            List <SPFeatureDefinition> fds = SPBroker.GetAllFeaturesForScope(Scope);

            AddFeaturesForScope(pnode, fds, active);
        }
        private void AddFeaturesForWeb(SPWeb pw, TreeNode pnode)
        {
            SPFeatureScope      Scope  = SPFeatureScope.Web;
            SPFeatureCollection active = pw.Features;

            List <SPFeatureDefinition> fds = SPBroker.GetAllFeaturesForScope(Scope);

            AddFeaturesForScope(pnode, fds, active);
        }
 public static string ScopeToAbbrev(SPFeatureScope scope)
 {
     switch (scope)
     {
         case SPFeatureScope.Farm: return "Farm";
         case SPFeatureScope.WebApplication: return "WebApp";
         case SPFeatureScope.Site: return "SiteColl";
         case SPFeatureScope.Web: return "Web";
         default: return "Invalid";
     }
 }
Ejemplo n.º 11
0
        public static List <SPFeatureDefinition> GetAllFeaturesForScope(SPFeatureScope Scope)
        {
            List <SPFeatureDefinition> result = new List <SPFeatureDefinition>();

            foreach (SPFeatureDefinition fd in SPFarm.Local.FeatureDefinitions)
            {
                if (fd.Scope == Scope)
                {
                    result.Add(fd);
                }
            }
            return(result);
        }
Ejemplo n.º 12
0
        private void AddLocationItemToDisplay(SPFeatureScope scope, string webappTitle, string siteTitle, string webTitle, int featureCount)
        {
            string       scopeString = (scope == SPFeatureScope.WebApplication ? "WebApp" : scope.ToString());
            ListViewItem item        = new ListViewItem(scopeString);

            item.SubItems.Add(webappTitle);
            item.SubItems.Add(siteTitle);
            item.SubItems.Add(webTitle);
            if (InstallConfiguration.FeatureIdList.Count > 1)
            {
                item.SubItems.Add(featureCount.ToString());
            }
            myList.Items.Add(item);
        }
Ejemplo n.º 13
0
        public static string ScopeToAbbrev(SPFeatureScope scope)
        {
            switch (scope)
            {
            case SPFeatureScope.Farm: return("Farm");

            case SPFeatureScope.WebApplication: return("WebApp");

            case SPFeatureScope.Site: return("SiteColl");

            case SPFeatureScope.Web: return("Web");

            default: return("Invalid");
            }
        }
Ejemplo n.º 14
0
        public FeatureSet(List <Feature> features)
        {
            this.Count = features.Count;
            foreach (Feature feature in features)
            {
                if (_HighestScope == SPFeatureScope.ScopeInvalid)
                {
                    _HighestScope = feature.Scope;
                    _LowestScope  = feature.Scope;
                }
                else
                {
                    if (feature.Scope > _HighestScope)
                    {
                        _HighestScope = feature.Scope;
                    }
                    if (feature.Scope < _LowestScope)
                    {
                        _LowestScope = feature.Scope;
                    }
                }
                switch (feature.Scope)
                {
                case SPFeatureScope.Farm:
                    _FarmFeatures.Add(feature);
                    break;

                case SPFeatureScope.WebApplication:
                    _WebAppFeatures.Add(feature);
                    break;

                case SPFeatureScope.Site:
                    _SiteCollectionFeatures.Add(feature);
                    break;

                case SPFeatureScope.Web:
                    _WebFeatures.Add(feature);
                    break;

                default:
                    throw new Exception(string.Format(
                                            "Unknown feature scope {0} in feature {1}",
                                            feature.Scope,
                                            feature.Name
                                            ));
                }
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Look up & return feature from our master definition list
        /// (Create a placeholder entry if we're lacking it)
        /// </summary>
        private Feature GetOrAddFeatureFromDefinitions(Guid featureId, SPFeatureScope scope)
        {
            Feature feature = null;

            if (!_AllFeatureDefinitions.ContainsKey(featureId))
            {
                // Not sure if this can happen (an undefined feature is activated)
                // but in case, manufacture an empty definition for it in our list
                feature = new Feature(featureId, scope);
                _AllFeatureDefinitions.Add(featureId, feature);
            }
            else
            {
                feature = _AllFeatureDefinitions[featureId];
            }
            return(feature);
        }
Ejemplo n.º 16
0
 private void LoadAllFeatureActivations(Dictionary <Guid, List <Location> > activatedFeatureLocations)
 {
     foreach (KeyValuePair <Guid, List <Location> > activation in activatedFeatureLocations)
     {
         Guid            featureId = activation.Key;
         List <Location> locations = activation.Value;
         SPFeatureScope  scope     = locations[0].Scope;
         Feature         feature   = GetOrAddFeatureFromDefinitions(featureId, scope);
         // Add to FeatureLocations, which can be done as a lump
         _FeatureLocations[featureId] = locations;
         feature.Activations          = locations.Count;
         // Add to LocationFeatures, which has to be done one location at a time
         foreach (Location location in locations)
         {
             AddToLocationFeatures(location, feature);
         }
     }
 }
Ejemplo n.º 17
0
 public FeatureSet(List<Feature> features)
 {
     foreach (Feature feature in features)
     {
         if (_HighestScope == SPFeatureScope.ScopeInvalid)
         {
             _HighestScope = feature.Scope;
             _LowestScope = feature.Scope;
         }
         else
         {
             if (feature.Scope > _HighestScope)
             {
                 _HighestScope = feature.Scope;
             }
             if (feature.Scope < _LowestScope)
             {
                 _LowestScope = feature.Scope;
             }
         }
         switch (feature.Scope)
         {
             case SPFeatureScope.Farm:
                 _FarmFeatures.Add(feature);
                 break;
             case SPFeatureScope.WebApplication:
                 _WebAppFeatures.Add(feature);
                 break;
             case SPFeatureScope.Site:
                 _SiteCollectionFeatures.Add(feature);
                 break;
             case SPFeatureScope.Web:
                 _WebFeatures.Add(feature);
                 break;
             default:
                 throw new Exception(string.Format(
                     "Unknown feature scope {0} in feature {1}",
                     feature.Scope,
                     feature.Name
                     ));
         }
     }
 }
Ejemplo n.º 18
0
        /// <summary>Adds features to the custom Feature class</summary>
        /// <param name="spFeatureDefinitions"></param>
        public void AddFeatures(SPFeatureCollection spfeatures, SPFeatureScope scope)
        {
            this._spfeatures = spfeatures;

            foreach (SPFeature spfeature in spfeatures)
            {
                Feature feature = new Feature(spfeature.DefinitionId, scope);
                try
                {
                    feature.Name = spfeature.Definition.DisplayName;
                }
                catch (Exception exc)
                {
                    feature.AppendExceptionMsg(exc);
                }

                this._features.Add(feature);
            }
        }
Ejemplo n.º 19
0
        /// <summary>Adds features to the custom Feature class</summary>
        /// <param name="spFeatureDefinitions"></param>
        public void AddFeatures(SPFeatureCollection spfeatures, SPFeatureScope scope)
        {
            this._spfeatures = spfeatures;

            foreach (SPFeature spfeature in spfeatures)
            {
                Feature feature = new Feature(spfeature.DefinitionId, scope);
                try
                {
                    feature.Name = spfeature.Definition.DisplayName;
                }
                catch (Exception exc)
                {
                    feature.AppendExceptionMsg(exc);
                }

                this._features.Add(feature);
            }
        }
Ejemplo n.º 20
0
        internal static InstallerControl CreateDeploymentTargetsControl()
        {
            InstallerControl control      = null;
            SPFeatureScope   featureScope = InstallConfiguration.FeatureScope;

            if (featureScope == SPFeatureScope.Farm)
            {
                control          = new DeploymentTargetsControl();
                control.Title    = Resources.CommonUIStrings.controlTitleFarmDeployment;
                control.SubTitle = Resources.CommonUIStrings.controlSubTitleFarmDeployment;
            }
            else if (featureScope == SPFeatureScope.Site)
            {
                control          = new SiteCollectionDeploymentTargetsControl();
                control.Title    = Resources.CommonUIStrings.controlTitleSiteDeployment;
                control.SubTitle = Resources.CommonUIStrings.controlSubTitleSiteDeployment;
            }
            return(control);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Builds the feature list data table.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="showHidden">if set to <c>true</c> [show hidden].</param>
        /// <returns></returns>
        private static DataTable BuildFeatureListDataTable(string url, SPFeatureScope scope, bool showHidden)
        {
            string[]  dataTableColumns = new string[] { "FeatureId", "Title", "DisplayName", "Description", "Status", "Scope" };
            DataTable dtblFeatureList  = new DataTable();

            dtblFeatureList.TableName = "Feature";

            for (int index = 0; index < dataTableColumns.Length; index++)
            {
                string     columnName = dataTableColumns[index];
                DataColumn column     = new DataColumn(columnName, typeof(string));
                dtblFeatureList.Columns.Add(column);
            }

            AddFeaturesToTable(ref dtblFeatureList, url, scope, showHidden);
            dtblFeatureList.Locale           = CultureInfo.CurrentUICulture;
            dtblFeatureList.DefaultView.Sort = "Title ASC";
            return(dtblFeatureList);
        }
        internal static InstallerControl CreateDeploymentTargetsControl()
        {
            InstallerControl control      = null;
            SPFeatureScope   featureScope = InstallConfiguration.FeatureScope;

            if (featureScope == SPFeatureScope.Farm)
            {
                control          = new DeploymentTargetsControl();
                control.Title    = res.FarmDeploymentTargets;
                control.SubTitle = res.FarmDeploymentTargets2;
            }
            else if (featureScope == SPFeatureScope.Site)
            {
                control          = new SiteCollectionDeploymentTargetsControl();
                control.Title    = res.SiteDeploymentTargets;
                control.SubTitle = res.SiteDeploymentTargets2;
            }
            return(control);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Runs the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <param name="keyValues">The key values.</param>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public override int Execute(string command, StringDictionary keyValues, out string output)
        {
            output = string.Empty;

            string url        = Params["url"].Value.TrimEnd('/');
            bool   asXml      = Params["xml"].UserTypedIn;
            bool   showHidden = Params["showhidden"].UserTypedIn;

            SPFeatureScope scope = SPFeatureScope.ScopeInvalid;

            if (Params["scope"].UserTypedIn)
            {
                scope = (SPFeatureScope)Enum.Parse(typeof(SPFeatureScope), Params["scope"].Value, true);
            }

            DataTable dt = BuildFeatureListDataTable(url, scope, showHidden);

            if (asXml)
            {
                DataSet features = new DataSet("Features");
                features.Tables.Add(dt);

                output += features.GetXml();
            }
            else
            {
                int i = 0;
                foreach (DataRow row in dt.Rows)
                {
                    i++;
                    if (scope == SPFeatureScope.ScopeInvalid)
                    {
                        output += string.Format("{0}. {1}: {2} ({3} - {4})\r\n", i, row["DisplayName"], row["Title"], row["Scope"], row["Status"]);
                    }
                    else
                    {
                        output += string.Format("{0}. {1}: {2} ({3})\r\n", i, row["DisplayName"], row["Title"], row["Status"]);
                    }
                }
            }
            return((int)ErrorCodes.NoError);
        }
        /// <summary>
        /// try to remove the feature from the farm in all feature collections with this scope
        /// this only needs to run, when a feature definition should be uninstalled, and it has an error,
        /// so that it is not clear, which scope the feature definition was defined for.
        /// </summary>
        /// <param name="featureID">feature guid of the feature to be removed</param>
        /// <param name="scope">scope of all the feature collections in the farm to be scanned</param>
        /// <returns>was the feature found, if yes, it had this scope and other scopes don't need to be scanned</returns>
        private bool tryToRemove(Guid featureID, SPFeatureScope scope)
        {
            string msgString = string.Empty;
            int    featurefound;

            featurefound = parentWindow.removeFeaturesWithinFarm(featureID, scope);
            /// search all webs
            if (featurefound == 0)
            {
                msgString = "Search through all Scopes:'" + scope.ToString() + "' done..., feature not found.";
                parentWindow.logTxt(DateTime.Now.ToString(FrmMain.DATETIMEFORMAT) + " - " + msgString + Environment.NewLine);
                return(false);
            }
            else
            {
                msgString = "Success! Feature was found and deactivated " + featurefound + " times in Scope:'" + scope.ToString() + "'!";
                MessageBox.Show(msgString);
                parentWindow.logTxt(DateTime.Now.ToString(FrmMain.DATETIMEFORMAT) + " - " + msgString + Environment.NewLine);
                return(true);
            }
        }
        /// <summary>
        /// try to remove the feature from the farm in all feature collections with this scope
        /// this only needs to run, when a feature definition should be uninstalled, and it has an error,
        /// so that it is not clear, which scope the feature definition was defined for.
        /// </summary>
        /// <param name="featureID">feature guid of the feature to be removed</param>
        /// <param name="scope">scope of all the feature collections in the farm to be scanned</param>
        /// <returns>was the feature found, if yes, it had this scope and other scopes don't need to be scanned</returns>
        private bool tryToRemove(Guid featureID, SPFeatureScope scope)
        {
            string msgString = string.Empty;
            int    featurefound;

            featurefound = parentWindow.RemoveFeaturesWithinFarm(featureID, scope);
            /// search all webs
            if (featurefound == 0)
            {
                msgString = "Search through all Scopes:'" + scope.ToString() + "' done..., feature not found.";
                Log.Information(msgString);
                return(false);
            }
            else
            {
                msgString = "Success! Feature was found and deactivated " + featurefound + " times in Scope:'" + scope.ToString() + "'!";
                MessageBox.Show(msgString);
                Log.Information(msgString);
                return(true);
            }
        }
Ejemplo n.º 26
0
        private void ReportFeature(SPFeatureScope scope, Guid featureId, string url, string name)
        {
            OnFoundFeature(featureId, url, name);
            Location location = new Location();

            location.Scope     = scope;
            location.FeatureId = featureId;
            location.Url       = url;
            location.Name      = name;
            List <Location> locs = null;

            if (featureLocations.ContainsKey(featureId))
            {
                locs = featureLocations[featureId];
            }
            else
            {
                locs = new List <Location>();
            }
            locs.Add(location);
            featureLocations[featureId] = locs;
        }
Ejemplo n.º 27
0
        private void FindWebApplication(SPFeatureReceiverProperties properties)
        {
            SPFeatureScope scope = properties.Feature.Definition.Scope;

            if (scope == SPFeatureScope.Web)
            {
                SPWeb web = properties.Feature.Parent as SPWeb;
                webApp = web.Site.WebApplication;
            }


            if (scope == SPFeatureScope.Site)
            {
                SPSite site = properties.Feature.Parent as SPSite;
                webApp = site.WebApplication;
            }

            if (scope == SPFeatureScope.WebApplication)
            {
                webApp = properties.Feature.Parent as SPWebApplication;
            }
        }
Ejemplo n.º 28
0
        public static Scope ToScope(this SPFeatureScope spFeatureScope)
        {
            switch (spFeatureScope)
            {
            //case SPFeatureScope.ScopeInvalid:
            //    return Scope.ScopeInvalid;
            case SPFeatureScope.Farm:
                return(Scope.Farm);

            case SPFeatureScope.WebApplication:
                return(Scope.WebApplication);

            case SPFeatureScope.Site:
                return(Scope.Site);

            case SPFeatureScope.Web:
                return(Scope.Web);

            default:
                return(Scope.ScopeInvalid);
            }
        }
Ejemplo n.º 29
0
        public static FeatureParent GetFeatureParent(SPFeature feature, SPFeatureScope scope)
        {
            try
            {
                if (feature != null && feature.Parent != null && scope != SPFeatureScope.ScopeInvalid)
                {
                    switch (scope)
                    {
                    case SPFeatureScope.Farm:
                        var f = feature.Parent as SPWebService;     // SPWebService.ContentService.Features
                        return(GetFeatureParent(f));

                    case SPFeatureScope.WebApplication:
                        var wa = feature.Parent as SPWebApplication;
                        return(GetFeatureParent(wa));

                    case SPFeatureScope.Site:
                        var s = feature.Parent as SPSite;
                        return(GetFeatureParent(s));

                    case SPFeatureScope.Web:
                        var w = feature.Parent as SPWeb;
                        return(GetFeatureParent(w));

                    default:
                        return(GetFeatureParentUndefined());
                    }
                }
                else
                {
                    return(GetFeatureParentUndefined());
                }
            }
            catch (Exception ex)
            {
                return(GetFeatureParentUndefined(ex.Message));
            }
        }
        private static int ProcessAllFeaturesInFarm(IEnumerable <Guid> featureIds, SPFeatureScope scope, bool activate, bool force, out Exception exception)
        {
            var processingCounter = 0;

            exception = null;


            try
            {
                var farm = FarmRead.GetFarm();
                if (farm == null)
                {
                    exception = new ArgumentNullException("farm is null !? not enough rights?");
                    return(processingCounter);
                }

                processingCounter += ProcessAllFeaturesInFarm(farm, featureIds, scope, activate, force, out exception);
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            return(processingCounter);
        }
Ejemplo n.º 31
0
        /// <summary>searches for faulty features and provides the option to remove them</summary>
        /// <param name="features">SPFeatureCollection, the container for the features</param>
        /// <param name="scope">is needed, in case a feature is found, so that it can be deleted</param>
        /// <returns></returns>
        private bool findFaultyFeatureInCollection(SPFeatureCollection features, SPFeatureScope scope)
        {
            bool faultyFound = false;
            if (features == null)
            {
                logDateMsg("ERROR: Feature Collection was null!");
                return false;
            }
            if (features.Count == 0)
            {
                logDateMsg("ERROR: Feature Collection was empty!");
                return false;
            }

            // string DBName = string.Empty; // tbd: retrieve the database name of the featureCollection
            string featuresName = features.ToString();

            try
            {
                foreach (SPFeature feature in features)
                {
                    FeatureChecker checker = new FeatureChecker();
                    FeatureChecker.Status status = checker.CheckFeature(feature);
                    if (status.Faulty)
                    {
                        faultyFound = true;

                        string msgString = DescribeFeatureAndLocation(feature);
                        logDateMsg(msgString);
                        string caption = string.Format("Found Faulty {0} Feature", scope);
                        DialogResult response = MessageBox.Show(msgString, caption,
                            MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                        if (response == DialogResult.Yes)
                        {
                            removeFeaturesWithinFarm(feature.DefinitionId, scope);
                        }
                        if (response == DialogResult.Cancel)
                        {
                            return faultyFound;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is SqlException)
                {
                    string msgstring = string.Format("Cannot access a feature collection of scope '{0}'! Not enough access rights for a content DB on SQL Server! dbOwner rights are recommended. Please read the following error message:\n\n'{1}'", scope.ToString(), ex.ToString());
                    string MessageCaption = string.Format("FeatureCollection in a Content DB not accessible");
                    if(MessageBox.Show(msgstring, MessageCaption,MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        return faultyFound;
                    }
                }
                else
                {
                    MessageBox.Show(ex.ToString(), "An error has occured!", MessageBoxButtons.OK);
                }
                return faultyFound;
            }
            return faultyFound;
        }
 public FeatureLoc(SPSite site)
 {
     this.Scope = SPFeatureScope.Site;
     this.SiteId = site.ID;
     this.WebAppId = site.WebApplication.Id;
 }
 public FeatureLoc(SPWebApplication webapp)
 {
     this.Scope = SPFeatureScope.WebApplication;
     this.WebAppId = webapp.Id;
 }
Ejemplo n.º 34
0
        private void featureActivater(SPFeatureScope activationScope)
        {
            int featuresActivated = 0;
            string msgString = string.Empty;

            int checkedItems = clbFeatureDefinitions.CheckedItems.Count;

            foreach (Feature checkedFeature in clbFeatureDefinitions.CheckedItems)
            {
                switch (activationScope)
                {
                    case SPFeatureScope.Farm:
                        msgString = "Do you really want to activate the checked feature: '" + checkedFeature.ToString() + "' in the whole farm?";

                        if (MessageBox.Show(msgString, "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            featuresActivated += featureActivateInSPFarm(checkedFeature.Id, checkedFeature.Scope);
                        }
                        break;

                    case SPFeatureScope.WebApplication:
                        if (m_CurrentWebApp == null)
                        {
                            MessageBox.Show("No Web Application selected.");
                            return;
                        }
                        msgString = "Do you really want to activate the selected feature: '" + checkedFeature.ToString() + "' in the web app '" +
                            m_CurrentWebApp.Name.ToString() + "'?";
                        if (MessageBox.Show(msgString, "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                        {
                            featuresActivated += featureActivateInSPWebApp(m_CurrentWebApp, checkedFeature.Id, checkedFeature.Scope);
                        }
                        break;

                    case SPFeatureScope.Site:
                        if (m_CurrentSite == null)
                        {
                            MessageBox.Show("No SiteCollection selected.");
                            return;
                        }
                        msgString = "The feature: <" + checkedFeature.ToString() + "> will be activated everywhere in Site Collection <" +
                            m_CurrentSite.Url.ToString() + ">?";
                        if (MessageBox.Show(msgString, "Please Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            featuresActivated += featureActivateInSPSite(m_CurrentSite, checkedFeature.Id, checkedFeature.Scope);
                        }
                        break;

                    case SPFeatureScope.Web:
                        if (m_CurrentWeb == null)
                        {
                            MessageBox.Show("No Site (SPWeb) selected.");
                            return;
                        }
                        if (checkedFeature.Scope != SPFeatureScope.Web)
                            goto default;
                        msgString = "The feature: <" + checkedFeature.ToString() + "> will be activated in the Site <" +
                             m_CurrentWeb.Url.ToString() + ">?";
                        if (MessageBox.Show(msgString, "Please Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                        {
                            featuresActivated += featureActivateInSPWeb(m_CurrentWeb, checkedFeature.Id);
                        }
                        break;

                    default:

                        msgString = "Error, selected feature can't be activated - " + checkedFeature.ToString();
                        MessageBox.Show(msgString, "Warning!");
                        logDateMsg(msgString);
                        break;

                }

            }
            msgString = featuresActivated.ToString() + " Feature(s) were/was activated.";
            MessageBox.Show(msgString);
            logDateMsg(msgString);
        }
Ejemplo n.º 35
0
        /// <summary>activate features in the whole farm</summary>
        /// <param name="featureID"></param>
        /// <param name="featureScope"></param>
        /// <returns></returns>
        public int featureActivateInSPFarm(Guid featureID, SPFeatureScope featureScope)
        {
            string msgString;
            int featuresActivated = 0;

            // all the content WebApplications
            SPWebApplicationCollection webApplicationCollection = SPWebService.ContentService.WebApplications;

            switch (featureScope)
            {
                case SPFeatureScope.Farm:

                    // activate farm scoped features to the farm
                    try
                    {
                        if (!(SPWebService.ContentService.Features[featureID] is SPFeature))
                        {
                            SPWebService.ContentService.Features.Add(featureID);
                            featuresActivated += 1;
                        }
                    }
                    catch
                    {
                        msgString = "Error, selected feature can't be activated - " + featureID.ToString() + " on Farm level.";
                        MessageBox.Show(msgString, "Warning!");
                        logDateMsg(msgString);
                    }
                    break;

                #region Iterate through lower scopes
                // Web Application Scoped Feature Activation
                case SPFeatureScope.WebApplication:

                    // activate web app feature in every Web Application
                    foreach (SPWebApplication webApp in webApplicationCollection)
                    {
                        featuresActivated += featureActivateInSPWebApp(webApp, featureID, featureScope);
                    }

                    break;

                // SPSite Scoped Feature Activation
                case SPFeatureScope.Site:
                    foreach (SPWebApplication webApp in webApplicationCollection)
                    {

                        // activate site feature in every SPSite in this Web Application
                        foreach (SPSite site in webApp.Sites)
                        {
                            using (site)
                            {
                                featuresActivated += featureActivateInSPSite(site, featureID, featureScope);
                            }
                        }
                    }
                    break;

                // Web Scoped Feature Activation
                case SPFeatureScope.Web:

                    foreach (SPWebApplication webApp in webApplicationCollection)
                    {

                        // activate web feature in every SPWeb in this Web Application
                        foreach (SPSite site in webApp.Sites)
                        {
                            using (site)
                            {
                                foreach (SPWeb web in site.AllWebs)
                                {
                                    using (web)
                                    {
                                        featuresActivated += featureActivateInSPWeb(web, featureID);
                                    }
                                }
                            }
                        }
                    }
                    break;

                #endregion

                default:
                    msgString = "Error, Scope " + featureScope + " not allowed for Activation in Web Application";
                    MessageBox.Show(msgString, "Warning!");
                    logDateMsg(msgString);
                    break;
            }
            return featuresActivated;
        }
        private static int ProcessAllFeaturesInFarm(SPWebService farm, IEnumerable <Guid> featureIds, SPFeatureScope scope, bool activate, bool force, out Exception exception)
        {
            var processingCounter = 0;

            exception = null;

            if (farm == null)
            {
                exception = new ArgumentNullException("farm is null");
                return(processingCounter);
            }
            try
            {
                if (scope == SPFeatureScope.Farm || scope == SPFeatureScope.ScopeInvalid)
                {
                    processingCounter += ProcessAllFarmFeaturesInFarm(farm, featureIds, activate, force, out exception);
                }

                if (scope != SPFeatureScope.Farm)
                {
                    SPWebApplicationCollection webApps = FarmRead.GetWebApplicationsContent();

                    if (webApps != null && webApps.Count > 0)
                    {
                        foreach (SPWebApplication wa in webApps)
                        {
                            processingCounter += ProcessAllFeaturesInWebApp(wa, featureIds, scope, activate, force, out exception);
                        }
                    }

                    webApps = FarmRead.GetWebApplicationsAdmin();
                    if (webApps != null && webApps.Count > 0)
                    {
                        foreach (SPWebApplication wa in webApps)
                        {
                            processingCounter += ProcessAllFeaturesInWebApp(wa, featureIds, scope, activate, force, out exception);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            return(processingCounter);
        }
Ejemplo n.º 37
0
        /// <summary>removes the defined feature within a complete farm</summary>
        /// <param name="featureID"></param>
        /// <param name="trueForSPWeb"></param>
        /// <returns>number of deleted features</returns>
        public int removeFeaturesWithinFarm(Guid featureID, SPFeatureScope featureScope)
        {
            int removedFeatures = 0;
            int scannedThrough = 0;
            string msgString;

            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                msgString = "Removing Feature '" + featureID.ToString() + ", Scope: " + featureScope.ToString() + "' from the Farm.";
                logDateMsg("Farm - " + msgString);
                if (featureScope == SPFeatureScope.Farm)
                {
                    try
                    {
                        SPWebService.ContentService.Features.Remove(featureID, true);
                        removedFeatures++;
                        logDateMsg(
                            string.Format("Success removing feature {0} from {1}",
                            featureID,
                            LocationManager.SafeDescribeObject(SPFarm.Local)));
                    }
                    catch (Exception exc)
                    {
                        logException(exc,
                            string.Format("Exception removing feature {0} from farm",
                            featureID,
                            LocationManager.SafeDescribeObject(SPFarm.Local)));

                        logDateMsg("Farm - The Farm Scoped feature '" + featureID.ToString() + "' was not found. ");
                    }
                }
                else
                {

                    // all the content WebApplications
                    SPWebApplicationCollection webApplicationCollection = SPWebService.ContentService.WebApplications;

                    //  administrative WebApplications
                    // SPWebApplicationCollection webApplicationCollection = SPWebService.AdministrationService.WebApplications;

                    foreach (SPWebApplication webApplication in webApplicationCollection)
                    {

                        removedFeatures += removeFeaturesWithinWebApp(webApplication, featureID, featureScope);
                        scannedThrough++;
                    }
                }
                msgString = removedFeatures + " Features removed in the Farm. " + scannedThrough + " Web Applications were scanned.";
                logDateMsg("Farm - " + msgString);
            });
            return removedFeatures;
        }
Ejemplo n.º 38
0
        /// <summary>Delete a collection of SiteCollection or Web Features forcefully in one site</summary>
        /// <param name="manager"></param>
        /// <param name="checkedListItems"></param>
        private int removeAllSelectedFeatures(CheckedListBox.CheckedItemCollection checkedListItems, SPFeatureScope deletionScope, SPFeatureScope featureScope)
        {
            int removedFeatures = 0;
            foreach (Feature checkedFeature in checkedListItems)
            {
                switch (deletionScope)
                {

                    case SPFeatureScope.Farm:
                        removedFeatures += removeFeaturesWithinFarm(checkedFeature.Id, featureScope);
                        break;
                    case SPFeatureScope.WebApplication:
                        removedFeatures += removeFeaturesWithinWebApp(m_CurrentWebApp, checkedFeature.Id, featureScope);
                        break;

                    // only relevant for web scoped features
                    case SPFeatureScope.Site:
                        if (featureScope == SPFeatureScope.Site) goto default;
                        removedFeatures += removeWebFeaturesWithinSiteCollection(m_CurrentSite, checkedFeature.Id);
                        break;

                    default:
                        logDateMsg("no features removed, deletion scope defined wrong!");
                        break;
                }

            }
            return removedFeatures;
        }
Ejemplo n.º 39
0
        /// <summary>remove all features within a web application, if feature is web scoped, different method is called</summary>
        /// <param name="webApp"></param>
        /// <param name="featureID"></param>
        /// <param name="trueForSPWeb"></param>
        /// <returns>number of deleted features</returns>
        private int removeFeaturesWithinWebApp(SPWebApplication webApp, Guid featureID, SPFeatureScope featureScope)
        {
            int removedFeatures = 0;
            int scannedThrough = 0;
            string msgString;

            msgString = "Removing Feature '" + featureID.ToString() + "' from Web Application: '" + webApp.Name.ToString() + "'.";
            logDateMsg(" WebApp - " + msgString);

            SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    if (featureScope == SPFeatureScope.WebApplication)
                    {
                        try
                        {
                            webApp.Features.Remove(featureID, true);
                            removedFeatures++;
                            logDateMsg(
                                string.Format("Success removing feature {0} from {1}",
                                featureID,
                                LocationManager.SafeDescribeObject(webApp)));
                        }
                        catch (Exception exc)
                        {
                            logException(exc,
                                string.Format("Exception removing feature {0} from {1}",
                                featureID,
                                LocationManager.SafeDescribeObject(webApp)));
                        }
                    }
                    else
                    {

                        foreach (SPSite site in webApp.Sites)
                        {
                            using (site)
                            {
                                if (featureScope == SPFeatureScope.Web)
                                {
                                    removedFeatures += removeWebFeaturesWithinSiteCollection(site, featureID);
                                }
                                else
                                {
                                    //forcefully remove the feature
                                    site.Features.Remove(featureID, true);
                                    removedFeatures += 1;

                                }
                                scannedThrough++;
                            }
                        }
                    }

                });
            msgString = removedFeatures + " Features removed in the Web Application. " + scannedThrough + " SiteCollections were scanned.";
            logDateMsg(" WebApp - " + msgString);

            return removedFeatures;
        }
Ejemplo n.º 40
0
        /// <summary>activates features in a SiteCollection</summary>
        /// <param name="site"></param>
        /// <param name="featureID"></param>
        /// <param name="featureScope"></param>
        /// <returns></returns>
        public int featureActivateInSPSite(SPSite site, Guid featureID, SPFeatureScope featureScope)
        {
            int featuresActivated = 0;
            string msgString = string.Empty;

            if (featureScope == SPFeatureScope.Web)
            {
                // activate web feature in every SPWeb in this SPSite
                foreach (SPWeb web in site.AllWebs)
                {
                    using (web)
                    {
                        featuresActivated += featureActivateInSPWeb(web, featureID);
                    }
                }
            }
            else
            {
                if (featureScope == SPFeatureScope.Site)
                {
                    // activate Site scoped feature in this SPSite
                    try
                    {
                        if (!(site.Features[featureID] is SPFeature))
                        {
                            site.Features.Add(featureID);
                            featuresActivated += 1;
                        }
                    }
                    catch
                    {
                        msgString = "Error, selected feature can't be activated - " + featureID.ToString() + " in SiteCollection: '" + site.Url.ToString() + "'.";
                        MessageBox.Show(msgString, "Warning!");
                        logDateMsg(msgString);
                    }
                }

                else
                {
                    msgString = "Error, Scope " + featureScope + " not allowed for Activation in SiteCollection";
                    MessageBox.Show(msgString, "Warning!");
                    logDateMsg(msgString);
                    return 0;
                }
            }
            msgString = featuresActivated + " Features added in SiteCollection" + site.Url.ToString();
            logDateMsg(msgString);

            return featuresActivated;
        }
Ejemplo n.º 41
0
        /// <summary>activate all features in a web application</summary>
        /// <param name="webApp"></param>
        /// <param name="featureID"></param>
        /// <param name="featureScope"></param>
        /// <returns></returns>
        public int featureActivateInSPWebApp(SPWebApplication webApp, Guid featureID, SPFeatureScope featureScope)
        {
            string msgString;
            int featuresActivated = 0;

            switch (featureScope)
            {
                // Web Application Scoped Feature Activation
                case SPFeatureScope.WebApplication:

                    // activate web app scoped feature in the web application
                    try
                    {
                        if (!(webApp.Features[featureID] is SPFeature))
                        {

                            webApp.Features.Add(featureID);
                            featuresActivated += 1;
                        }
                    }
                    catch
                    {
                        msgString = "Error, selected feature can't be activated - in WebApp: '" + webApp.Name.ToString() + "'.";
                        MessageBox.Show(msgString, "Warning!");
                        logDateMsg(msgString);
                    }

                    break;

                #region Iterate through lower scopes
                // Site Scoped Feature Activation
                case SPFeatureScope.Site:
                    // activate site feature in every SPSit in this Web Application
                    foreach (SPSite site in webApp.Sites)
                    {
                        using (site)
                        {
                            featuresActivated += featureActivateInSPSite(site, featureID, featureScope);
                        }
                    }

                    break;

                // Web Scoped Feature Activation
                case SPFeatureScope.Web:

                    // activate web feature in every SPWeb in this Web Application
                    foreach (SPSite site in webApp.Sites)
                    {
                        using (site)
                        {
                            foreach (SPWeb web in site.AllWebs)
                            {
                                using (web)
                                {
                                    featuresActivated += featureActivateInSPWeb(web, featureID);
                                }
                            }
                        }
                    }
                    break;
                #endregion

                default:
                    msgString = "Error, Scope " + featureScope + " not allowed for Activation in Web Application";
                    MessageBox.Show(msgString, "Warning!");
                    logDateMsg(msgString);
                    break;
            }
            return featuresActivated;
        }
Ejemplo n.º 42
0
        private void activateSelectedFeaturesAcrossSpecifiedScope(SPFeatureScope activationScope)
        {
            string msgString = string.Empty;

            // TODO - if we checked whether there are any web level ones
            // we could maybe save traversing all the webs
            List<Feature> selectedFeatures = GetSelectedFeatureDefinitions();

            string msg;
            msg = string.Format(
                "Do you really want to activate the selected {0} feature(s) in the selected {1}",
                selectedFeatures.Count,
                activationScope
                );
            if (MessageBox.Show(msgString, "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
            {
                return;
            }
            FeatureActivator activator = new FeatureActivator();
            activator.ExceptionLoggingListeners += new FeatureActivator.ExceptionLoggerHandler(activator_ExceptionLoggingListeners);

            switch (activationScope)
            {
                case SPFeatureScope.Farm:
                    {
                        activator.TraverseActivateFeaturesInFarm(selectedFeatures);
                    }
                    break;

                case SPFeatureScope.WebApplication:
                    {
                        SPWebApplication webapp = GetCurrentWebApplication();
                        activator.TraverseActivateFeaturesInWebApplication(webapp, selectedFeatures);
                    }
                    break;

                case SPFeatureScope.Site:
                    {
                        using (SPSite site = OpenCurrentSite())
                        {
                            if (site == null) { return; }
                            try
                            {
                                activator.TraverseActivateFeaturesInSiteCollection(site, selectedFeatures);
                            }
                            finally
                            {
                                site.Dispose();
                            }
                        }
                    }
                    break;

                case SPFeatureScope.Web:
                    {
                        using (SPSite site = OpenCurrentSite())
                        {
                            if (site == null) { return; }
                            try
                            {
                                using (SPWeb web = site.OpenWeb())
                                {
                                    if (web == null) { return; }
                                    try
                                    {
                                        activator.ActivateFeaturesInWeb(web, selectedFeatures);
                                    }
                                    finally
                                    {
                                        site.Dispose();
                                    }
                                }
                            }
                            finally
                            {
                                site.Dispose();
                            }
                        }
                    }
                    break;
                default:
                    {
                        msg = "Unknown scope: " + activationScope.ToString();
                        MessageBox.Show(msg, "Warning!");
                        logDateMsg(msg);
                    }
                    break;
            }
            int featuresActivated = activator.Activations;
            msg = string.Format(
                "{0} Feature(s) were/was activated.",
                featuresActivated);
            MessageBox.Show(msgString);
            logDateMsg(msgString);
        }
Ejemplo n.º 43
0
 private void ReportFeature(SPFeatureScope scope, Guid featureId, string url, string name)
 {
     OnFoundFeature(featureId, url, name);
     Location location = new Location();
     location.Scope = scope;
     location.FeatureId = featureId;
     location.Url = url;
     location.Name = name;
     List<Location> locs = null;
     if (featureLocations.ContainsKey(featureId))
     {
         locs = featureLocations[featureId];
     }
     else
     {
         locs = new List<Location>();
     }
     locs.Add(location);
     featureLocations[featureId] = locs;
 }
Ejemplo n.º 44
0
 public Feature(Guid id, SPFeatureScope scope)
 {
     this._id = id;
     this._scope = scope;
 }
        /// <summary>search for the feature and deactivate it in the specified scoped feature collections only</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnScopeSelected_Click(object sender, EventArgs e)
        {
            string msgString = string.Empty;
            int featurefound = 0;

            this.Hide();
            try
            {
                if (radioScopeWeb.Checked)
                {
                    scopeWindowScope = SPFeatureScope.Web;
                }
                else
                {
                    if (radioScopeSite.Checked)
                    {
                        scopeWindowScope = SPFeatureScope.Site;
                    }
                    else
                    {
                        if (radioScopeWebApp.Checked)
                        {
                            scopeWindowScope = SPFeatureScope.WebApplication;
                        }
                        else
                        {
                            if (radioScopeFarm.Checked)
                            {
                                scopeWindowScope = SPFeatureScope.Farm;
                            }
                            else
                                msgString = "Error in scope selection! Task canceled";
                            MessageBox.Show(msgString);
                            ((FrmMain)parentWindow).logTxt(DateTime.Now.ToString(FrmMain.DATETIMEFORMAT) + " - " + msgString + Environment.NewLine);

                            return;
                        }
                    }
                }
                featurefound = parentWindow.removeFeaturesWithinFarm(featureID, scopeWindowScope);
                if (featurefound == 0)
                {
                    msgString = "Feature not found in Scope:'" + scopeWindowScope.ToString() + "'. Do you want to try something else?";
                    if (MessageBox.Show(msgString, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        this.Show();
                    }
                    else
                    {

                    }
                }
                else
                {
                    msgString = "Success! Feature was found and deactivated " + featurefound + " times in Scope:'" + scopeWindowScope.ToString() + "'!";
                    MessageBox.Show(msgString);
                    parentWindow.logTxt(DateTime.Now.ToString(FrmMain.DATETIMEFORMAT) + " - " + msgString + Environment.NewLine);

                    SPFarm.Local.FeatureDefinitions.Remove(featureID, true);
                    parentWindow.logTxt(DateTime.Now.ToString(FrmMain.DATETIMEFORMAT) + " - FeatureDefinition was uninstalled." + Environment.NewLine);

                }
            }
            catch
            {
            }
            finally
            {
                        this.Close();
                        this.Dispose();
            }
        }
        public static int ProcessAllFeaturesInSite(string siteUrl, IEnumerable <Guid> featureIds, SPFeatureScope scope, bool activate, bool force, out Exception exception)
        {
            var       processingCounter = 0;
            Exception reEx = null;

            exception = null;

            if (string.IsNullOrEmpty(siteUrl))
            {
                exception = new ArgumentNullException("siteUrl is null");
                return(processingCounter);
            }
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (var site = new SPSite(siteUrl))
                    {
                        processingCounter += ProcessAllFeaturesInSite(site, featureIds, scope, activate, force, out reEx);
                    }
                });
                exception = reEx;
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            return(processingCounter);
        }
 public FeatureLoc(SPFarm farm)
 {
     this.Scope = SPFeatureScope.Farm;
     // leave everything null for farm
 }
        private static int ProcessAllFeaturesInSite(SPSite site, IEnumerable <Guid> featureIds, SPFeatureScope scope, bool activate, bool force, out Exception exception)
        {
            var processingCounter = 0;

            exception = null;

            if (site == null)
            {
                exception = new ArgumentNullException("site was null");
                return(processingCounter);
            }

            try
            {
                if (scope == SPFeatureScope.Site || scope == SPFeatureScope.ScopeInvalid)
                {
                    processingCounter += ProcessAllSiteFeaturesInSite(site, featureIds, activate, force, out exception);
                }

                if (scope == SPFeatureScope.Web || scope == SPFeatureScope.ScopeInvalid)
                {
                    foreach (SPWeb web in site.AllWebs)
                    {
                        processingCounter += ProcessAllWebFeaturesInWeb(web, featureIds, activate, force, out exception);
                    }
                }
            }
            catch (Exception ex)
            {
                exception = ex;
            }
            return(processingCounter);
        }
Ejemplo n.º 49
0
 public Feature(Guid id, SPFeatureScope scope)
 {
     this.Id = id;
     this.Scope = scope;
     this.CompatibilityLevel = COMPATUNKNOWN;
 }
Ejemplo n.º 50
0
        /// <summary>
        /// Adds the features to table.
        /// </summary>
        /// <param name="dtblFeatureList">The data table feature list.</param>
        /// <param name="url">The URL.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="showHidden">if set to <c>true</c> [show hidden].</param>
        private static void AddFeaturesToTable(ref DataTable dtblFeatureList, string url, SPFeatureScope scope, bool showHidden)
        {
            CultureInfo info;
            Dictionary <SPFeatureScope, SPFeatureCollection> activeFeatures = new Dictionary <SPFeatureScope, SPFeatureCollection>();

            // We need to get the SPSite and SPWeb so that we can get the culture info and any active features if a scope was passed in.
            using (SPSite site = new SPSite(url))
            {
                using (SPWeb web = site.AllWebs[Utilities.GetServerRelUrlFromFullUrl(url)])
                {
                    info = new CultureInfo((int)web.Language, false);

                    activeFeatures[SPFeatureScope.Farm]           = SPWebService.ContentService.Features;
                    activeFeatures[SPFeatureScope.WebApplication] = site.WebApplication.Features;
                    activeFeatures[SPFeatureScope.Site]           = site.Features;
                    activeFeatures[SPFeatureScope.Web]            = web.Features;
                }
            }

            foreach (SPFeatureDefinition definition in SPFarm.Local.FeatureDefinitions)
            {
                try
                {
                    Guid featureID = definition.Id;
                    // If the scope is marked as invalid then that's our flag that it wasn't provided so we're going to
                    // list everything regardless of scope and show those that are active for the Web scope.
                    if (definition.Scope != scope && scope != SPFeatureScope.ScopeInvalid)
                    {
                        continue;
                    }

                    if (definition.Hidden && !showHidden)
                    {
                        continue;
                    }
                    if (!definition.SupportsLanguage(info))
                    {
                        continue;
                    }

                    bool isActive = false;
                    if (activeFeatures[definition.Scope] != null)
                    {
                        isActive = (activeFeatures[definition.Scope][featureID] != null);
                    }

                    DataRow row = BuildDataRowFromFeatureDefinition(dtblFeatureList, info, definition, isActive);
                    dtblFeatureList.Rows.Add(row);
                }
                catch (SPException)
                {
                    continue;
                }
            }
        }
Ejemplo n.º 51
0
 /// <summary>
 /// Look up & return feature from our master definition list
 /// (Create a placeholder entry if we're lacking it)
 /// </summary>
 private Feature GetOrAddFeatureFromDefinitions(Guid featureId, SPFeatureScope scope)
 {
     Feature feature = null;
     if (!_AllFeatureDefinitions.ContainsKey(featureId))
     {
         // Not sure if this can happen (an undefined feature is activated)
         // but in case, manufacture an empty definition for it in our list
         feature = new Feature(featureId, scope);
         _AllFeatureDefinitions.Add(featureId, feature);
     }
     else
     {
         feature = _AllFeatureDefinitions[featureId];
     }
     return feature;
 }
        /// <summary>
        /// try to remove the feature from the farm in all feature collections with this scope
        /// this only needs to run, when a feature definition should be uninstalled, and it has an error,
        /// so that it is not clear, which scope the feature definition was defined for.
        /// </summary>
        /// <param name="featureID">feature guid of the feature to be removed</param>
        /// <param name="scope">scope of all the feature collections in the farm to be scanned</param>
        /// <returns>was the feature found, if yes, it had this scope and other scopes don't need to be scanned</returns>
        private bool tryToRemove(Guid featureID, SPFeatureScope scope)
        {
            string msgString = string.Empty;
            int featurefound;

            featurefound = parentWindow.removeFeaturesWithinFarm(featureID, scope);
            /// search all webs
            if (featurefound == 0)
            {
                msgString = "Search through all Scopes:'" + scope.ToString() + "' done..., feature not found.";
                parentWindow.logTxt(DateTime.Now.ToString(FrmMain.DATETIMEFORMAT) + " - " + msgString + Environment.NewLine);
                return false;
            }
            else
            {
                msgString = "Success! Feature was found and deactivated " + featurefound + " times in Scope:'" + scope.ToString() + "'!";
                MessageBox.Show(msgString);
                parentWindow.logTxt(DateTime.Now.ToString(FrmMain.DATETIMEFORMAT) + " - " + msgString + Environment.NewLine);
                return true;
            }
        }
Ejemplo n.º 53
0
 private void ReportFeature(object obj, bool faulty, SPFeatureScope scope, Guid featureId, string url, string name)
 {
     OnFoundFeature(featureId, url, name);
     Location location = LocationManager.CreateLocation(obj);
     List<Location> locs = null;
     if (featureLocations.ContainsKey(featureId))
     {
         locs = featureLocations[featureId];
     }
     else
     {
         locs = new List<Location>();
     }
     locs.Add(location);
     featureLocations[featureId] = locs;
     if (faulty)
     {
         int faults = 0;
         if (faultyFeatures.ContainsKey(featureId))
         {
             faults = faultyFeatures[featureId];
         }
         ++faults;
         faultyFeatures[featureId] = faults;
     }
 }
Ejemplo n.º 54
0
        private void activateSelectedFeaturesAcrossSpecifiedScope(SPFeatureScope activationScope, Location currentLocation, FeatureActivator.Action action)
        {
            List<Feature> selectedFeatures = GetSelectedFeatureDefinitions();
            FeatureSet featureSet = new FeatureSet(selectedFeatures);
            string verbnow = "?", verbpast = "?";
            switch (action)
            {
                case FeatureActivator.Action.Activating:
                    verbnow = "activate"; verbpast = "activated";
                    break;
                case FeatureActivator.Action.Deactivating:
                    verbnow = "deactivate"; verbpast = "deactivated";
                    break;
                default:
                    throw new Exception("Invalid action in activateSelectedFeaturesAcrossSpecifiedScope");
            }

            if (selectedFeatures.Count > 10)
            {
                InfoBox(string.Format(
                    "Too many features ({0}) selected; max 10 may be {1} at time",
                    selectedFeatures.Count,
                    verbpast
                    ));
                return;
            }

            if (featureSet.LowestScope < activationScope)
            {
                InfoBox(string.Format(
                    "{0} Feature(s) cannot be {1} at level {2}",
                    featureSet.LowestScope,
                    verbpast,
                    activationScope
                    ));
                return;
            }

            string currentLocName = "?";
            if (activationScope == SPFeatureScope.Farm)
            {
                currentLocName = "Local Farm";
            }
            else
            {
                currentLocName = currentLocation.Name + " -- " + currentLocation.Url;
            }
            string msg;
            msg = string.Format(
                "{0}  the selected {1} features: \n"
                + "{2}"
                + "in the selected {3}: \n\t{4}",
                CultureInfo.CurrentCulture.TextInfo.ToTitleCase(verbnow),
                selectedFeatures.Count,
                GetFeatureSummaries(selectedFeatures, "\t{Name} ({Scope})\n"),
                activationScope,
                currentLocName
                );
            if (!ConfirmBox(msg))
            {
                return;
            }
            FeatureActivator activator = new FeatureActivator(m_featureDb, action, featureSet);
            activator.ExceptionLoggingListeners += new FeatureActivator.ExceptionLoggerHandler(activator_ExceptionLoggingListeners);

            switch (activationScope)
            {
                case SPFeatureScope.Farm:
                    {
                        activator.TraverseActivateFeaturesInFarm();
                    }
                    break;

                case SPFeatureScope.WebApplication:
                    {
                        SPWebApplication webapp = GetCurrentWebApplication();
                        activator.TraverseActivateFeaturesInWebApplication(webapp);
                    }
                    break;

                case SPFeatureScope.Site:
                    {
                        using (SPSite site = OpenCurrentSite())
                        {
                            if (site == null) { return; }
                            try
                            {
                                activator.TraverseActivateFeaturesInSiteCollection(site);
                            }
                            finally
                            {
                                site.Dispose();
                            }
                        }
                    }
                    break;

                case SPFeatureScope.Web:
                    {
                        using (SPSite site = OpenCurrentSite())
                        {
                            if (site == null) { return; }
                            try
                            {
                                using (SPWeb web = site.OpenWeb())
                                {
                                    if (web == null) { return; }
                                    try
                                    {
                                        activator.ActivateFeaturesInWeb(web);
                                    }
                                    finally
                                    {
                                        site.Dispose();
                                    }
                                }
                            }
                            finally
                            {
                                site.Dispose();
                            }
                        }
                    }
                    break;
                default:
                    {
                        msg = "Unknown scope: " + activationScope.ToString();
                        ErrorBox(msg);
                    }
                    break;
            }
            msg = string.Format(
                "{0} Feature(s) {1}.",
                activator.Activations,
                verbpast);
            MessageBox.Show(msg);
            logDateMsg(msg);
        }
 private FeatureLoc(SPFeatureScope scope, Guid WebAppId, Guid SiteId, Guid WebId)
 {
     this.Scope = scope;
     this.WebAppId = WebAppId;
     this.SiteId = SiteId;
     this.WebId = WebId;
 }
Ejemplo n.º 56
0
        /// <summary>searches for faulty features and provides the option to remove them</summary>
        /// <param name="features">SPFeatureCollection, the container for the features</param>
        /// <param name="scope">is needed, in case a feature is found, so that it can be deleted</param>
        /// <returns></returns>
        private bool findFaultyFeatureInCollection(SPFeatureCollection features, SPFeatureScope scope)
        {
            return false;
            /*
            bool faultyFound = false;
            if (features == null)
            {
                logDateMsg("ERROR: Feature Collection was null!");
                return false;
            }
            if (features.Count == 0)
            {
                logDateMsg("ERROR: Feature Collection was empty!");
                return false;
            }

            // string DBName = string.Empty; // tbd: retrieve the database name of the featureCollection
            string featuresName = features.ToString();

            try
            {
                foreach (SPFeature feature in features)
                {
                    FeatureChecker checker = new FeatureChecker();
                    FeatureChecker.Status status = checker.CheckFeature(feature);
                    if (status.Faulty)
                    {
                        faultyFound = true;
                        string location = LocationInfo.SafeDescribeObject(feature.Parent);

                        string msgString = "Faulty Feature found! Id=" + feature.DefinitionId.ToString();
            #if SP2013
                        msgString += " Activation=" + feature.TimeActivated.ToString("yyyy-MM-dd");
            #endif
                        string solutionInfo = GetFeatureSolutionInfo(feature);
                        if (!string.IsNullOrEmpty(solutionInfo))
                        {
                            msgString += solutionInfo;
                        }
                        msgString += Environment.NewLine
                            + "Found in " + location + "." + Environment.NewLine
                            + " Should it be removed from the farm?";
                        logDateMsg(msgString);
                        string caption = "Found Faulty Feature";
                        DialogResult response = MessageBox.Show(msgString, caption,
                            MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                        if (response == DialogResult.Yes)
                        {
                            removeFeaturesWithinFarm(feature.DefinitionId, scope);
                        }
                        if (response == DialogResult.Cancel)
                        {
                            return faultyFound;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is SqlException)
                {
                    string msgstring = string.Format("Cannot access a feature collection of scope '{0}'! Not enough access rights for a content DB on SQL Server! dbOwner rights are recommended. Please read the following error message:\n\n'{1}'", scope.ToString(), ex.ToString());
                    string MessageCaption = string.Format("FeatureCollection in a Content DB not accessible");
                    if(MessageBox.Show(msgstring, MessageCaption,MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        return faultyFound;
                    }
                }
                else
                {
                    MessageBox.Show(ex.ToString(), "An error has occured!", MessageBoxButtons.OK);
                }
                return faultyFound;
            }
            return faultyFound;
             * */
        }
 private void AddLocationItemToDisplay(SPFeatureScope scope, string webappTitle, string siteTitle, string webTitle, int featureCount)
 {
     string scopeString = (scope == SPFeatureScope.WebApplication ? "WebApp" : scope.ToString());
     ListViewItem item = new ListViewItem(scopeString);
     item.SubItems.Add(webappTitle);
     item.SubItems.Add(siteTitle);
     item.SubItems.Add(webTitle);
     if (InstallConfiguration.FeatureIdList.Count > 1)
     {
         item.SubItems.Add(featureCount.ToString());
     }
     myList.Items.Add(item);
 }