Exemple #1
0
        private void GetSiteFeatuesAndBelow(SPSite site, Guid webAppId)
        {
            if (site != null)
            {
                var parent = FeatureParent.GetFeatureParent(site);

                AddParentToHierarchyAndParentsList(webAppId, parent, true);

                var siteFeatures = site.Features;

                if (siteFeatures != null && siteFeatures.Count > 0)
                {
                    var activatedSiCoFeatures = ActivatedFeature.MapSpFeatureToActivatedFeature(siteFeatures, parent);
                    ActivatedFeatures.AddRange(activatedSiCoFeatures);
                }

                var webs = site.AllWebs;

                if (webs != null && webs.Count > 0)
                {
                    foreach (SPWeb w in webs)
                    {
                        GetWebFeatures(w, site.ID);
                        w.Dispose();
                    }
                }
            }
        }
Exemple #2
0
        public static FeatureParent GetFeatureParent(SPWebService farmWebService)
        {
            FeatureParent p = null;

            try
            {
                if (farmWebService == null)
                {
                    return(GetFeatureParentUndefined());
                }
                p = new FeatureParent()
                {
                    DisplayName = "Farm",
                    Url         = "Farm",
                    Id          = farmWebService.Id,
                    Scope       = SPFeatureScope.Farm
                };
            }
            catch (Exception ex)
            {
                Log.Error("Error when trying to get Farm object.", ex);
                return(GetFeatureParentUndefined(ex.Message));
            }

            try
            {
                var farmFeatures = farmWebService.Features;
                p.ActivatedFeatures = ActivatedFeature.MapSpFeatureToActivatedFeature(farmFeatures, p);
            }
            catch (Exception ex)
            {
                Log.Error("Error when trying to load Farm features.", ex);
            }
            return(p);
        }
Exemple #3
0
        public static FeatureParent GetFeatureParent(SPWebApplication webApp, string name = "")
        {
            FeatureParent p           = null;
            string        locationUrl = string.Empty;

            try
            {
                if (webApp == null)
                {
                    return(GetFeatureParentUndefined());
                }

                locationUrl = webApp.GetResponseUri(SPUrlZone.Default).ToString();

                p = new FeatureParent()
                {
                    DisplayName = string.IsNullOrEmpty(name) ? webApp.Name : name,  // + " (" + web.Name + ")",
                    Url         = locationUrl,
                    Id          = webApp.Id,
                    Scope       = SPFeatureScope.WebApplication
                };
            }
            catch (Exception ex)
            {
                Log.Error(
                    string.Format(
                        "Error when trying to get web app {0}.",
                        locationUrl
                        ),
                    ex);
                return(GetFeatureParentUndefined(ex.Message));
            }

            try
            {
                var features = webApp.Features;
                p.ActivatedFeatures = ActivatedFeature.MapSpFeatureToActivatedFeature(features, p);
            }
            catch (Exception ex)
            {
                Log.Error(
                    string.Format(
                        "Error when trying to load features from web app {0}.",
                        locationUrl
                        ),
                    ex);
            }
            return(p);
        }
Exemple #4
0
        public static FeatureParent GetFeatureParent(SPWeb web)
        {
            FeatureParent p           = null;
            string        locationUrl = string.Empty;

            try
            {
                if (web == null)
                {
                    return(GetFeatureParentUndefined());
                }

                locationUrl = web.Url;

                p = new FeatureParent()
                {
                    DisplayName = web.Title, // + " (" + web.Name + ")",
                    Url         = locationUrl,
                    Id          = web.ID,
                    Scope       = SPFeatureScope.Web
                };
            }
            catch (Exception ex)
            {
                Log.Error(
                    string.Format(
                        "Error when trying to get web {0}.",
                        locationUrl
                        ),
                    ex);
                return(GetFeatureParentUndefined(ex.Message));
            }

            try
            {
                var features = web.Features;
                p.ActivatedFeatures = ActivatedFeature.MapSpFeatureToActivatedFeature(features, p);
            }
            catch (Exception ex)
            {
                Log.Error(
                    string.Format(
                        "Error when trying to load features from web {0}.",
                        locationUrl
                        ),
                    ex);
            }
            return(p);
        }
Exemple #5
0
        public static FeatureParent GetFeatureParent(SPSite siCo)
        {
            FeatureParent p           = null;
            string        locationUrl = string.Empty;

            try
            {
                if (siCo == null)
                {
                    return(GetFeatureParentUndefined());
                }

                locationUrl = siCo.Url;

                p = new FeatureParent()
                {
                    DisplayName = siCo.RootWeb.Title,
                    Url         = locationUrl,
                    Id          = siCo.ID,
                    Scope       = SPFeatureScope.Site
                };
            }
            catch (Exception ex)
            {
                Log.Error(
                    string.Format(
                        "Error when trying to get SiteCollection {0}.",
                        locationUrl
                        ),
                    ex);
                return(GetFeatureParentUndefined(ex.Message));
            }

            try
            {
                var features = siCo.Features;
                p.ActivatedFeatures = ActivatedFeature.MapSpFeatureToActivatedFeature(features, p);
            }
            catch (Exception ex)
            {
                Log.Error(
                    string.Format(
                        "Error when trying to load features from {0}.",
                        locationUrl
                        ),
                    ex);
            }
            return(p);
        }
Exemple #6
0
        private void GetWebFeatures(SPWeb web, Guid SiteCollectionId)
        {
            if (web != null)
            {
                var parent = FeatureParent.GetFeatureParent(web);

                AddParentToHierarchyAndParentsList(SiteCollectionId, parent, false);

                var webFeatures = web.Features;

                if (webFeatures != null && webFeatures.Count > 0)
                {
                    var activatedWebFeatures = ActivatedFeature.MapSpFeatureToActivatedFeature(webFeatures, parent);
                    ActivatedFeatures.AddRange(activatedWebFeatures);
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Get activated features from farm and build up SharePointParentHierarchy
        /// </summary>
        private void LoadAllActivatedFeaturesAndHierarchy()
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                var farm = FarmRead.GetFarm();
                // Get Farm features
                var farmFeatures = farm.Features;

                var parent = FeatureParent.GetFeatureParent(farm);

                FarmId = parent.Id;

                SharePointParentHierarchy.Add(FarmId, new List <FeatureParent>());
                Parents.Add(parent);

                if (farmFeatures != null)
                {
                    var activatedFarmFeatures = ActivatedFeature.MapSpFeatureToActivatedFeature(farmFeatures, parent);

                    ActivatedFeatures.AddRange(activatedFarmFeatures);
                }

                // Get Web App features

                var adminWebApps = FarmRead.GetWebApplicationsAdmin();

                // Central Admin
                var caIndex = 1;
                foreach (SPWebApplication adminApp in adminWebApps)
                {
                    if (adminApp != null)
                    {
                        var index    = (adminApp.Features.Count == 1 && caIndex == 1) ? string.Empty : " " + caIndex.ToString();
                        var caParent = FeatureParent.GetFeatureParent(adminApp, "Central Admin" + index);

                        AddParentToHierarchyAndParentsList(FarmId, caParent, true);

                        var adminFeatures = adminApp.Features;

                        if (adminFeatures != null && adminFeatures.Count > 0)
                        {
                            var activatedCaWebAppFeatures = ActivatedFeature.MapSpFeatureToActivatedFeature(adminFeatures, caParent);
                            ActivatedFeatures.AddRange(activatedCaWebAppFeatures);
                        }

                        var sites = adminApp.Sites;

                        if (sites != null && sites.Count > 0)
                        {
                            foreach (SPSite s in sites)
                            {
                                GetSiteFeatuesAndBelow(s, caParent.Id);
                                s.Dispose();
                            }
                        }
                    }
                }

                // Content Web Apps
                var contentWebApps = FarmRead.GetWebApplicationsContent();

                foreach (SPWebApplication webApp in contentWebApps)
                {
                    if (webApp != null)
                    {
                        var waAsParent = FeatureParent.GetFeatureParent(webApp);

                        AddParentToHierarchyAndParentsList(FarmId, waAsParent, true);

                        var waFeatures = webApp.Features;

                        if (waFeatures != null && waFeatures.Count > 0)
                        {
                            var activatedWebAppFeatures = ActivatedFeature.MapSpFeatureToActivatedFeature(waFeatures, waAsParent);
                            ActivatedFeatures.AddRange(activatedWebAppFeatures);
                        }

                        var sites = webApp.Sites;

                        if (sites != null && sites.Count > 0)
                        {
                            foreach (SPSite s in sites)
                            {
                                GetSiteFeatuesAndBelow(s, waAsParent.Id);
                                s.Dispose();
                            }
                        }
                    }
                }
            });
        }