public void CanGetFeatureParentFromWebApp()
        {
            // Arrange
            var parentScope = SPFeatureScope.WebApplication;
            var parentUrl   = TestContent.SharePointContainers.WebApplication.Url;

            using (SPSite site = new SPSite(TestContent.SharePointContainers.SiCoInActive.Url))
            {
                SPWebApplication parent = site.WebApplication;


                var testFeatureHealthy = parent.Features[TestContent.TestFeatures.HealthyWebApp.Id];
                // var testFeatureFaulty = parent.Features[TestContent.TestFeatures.FaultyWebApp.Id];

                // Act
                var parentRetrievedWithScope = FeatureParent.GetFeatureParent(testFeatureHealthy, parentScope);
                var parentRetrievedNoScope   = FeatureParent.GetFeatureParent(testFeatureHealthy);


                // Assert
                Assert.Equal(parent.Name, parentRetrievedWithScope.DisplayName);
                Assert.Equal(parent.Id, parentRetrievedWithScope.Id);
                Assert.Equal(parentUrl, parentRetrievedWithScope.Url);
                Assert.Equal(parentScope, parentRetrievedWithScope.Scope);

                Assert.Equal(parent.Name, parentRetrievedNoScope.DisplayName);
                Assert.Equal(parent.Id, parentRetrievedNoScope.Id);
                Assert.Equal(parentUrl, parentRetrievedNoScope.Url);
                Assert.Equal(parentScope, parentRetrievedNoScope.Scope);
            }
        }
        public void CanGetFetaureParentFromFarm()
        {
            // Arrange
            var parentScope = SPFeatureScope.Farm;
            // var parentUrl = TestContent.SharePointContainers.WebApplication.Url;


            SPWebService parent = SPWebService.ContentService;


            var testFeatureHealthy = parent.Features[TestContent.TestFeatures.HealthyFarm.Id];
            // var testFeatureFaulty = parent.Features[TestContent.TestFeatures.FaultyFarm.Id];

            // Act
            var parentRetrievedWithScope = FeatureParent.GetFeatureParent(testFeatureHealthy, parentScope);
            var parentRetrievedNoScope   = FeatureParent.GetFeatureParent(testFeatureHealthy);


            // Assert
            Assert.Equal("Farm", parentRetrievedWithScope.DisplayName);
            Assert.Equal(parent.Id, parentRetrievedWithScope.Id);
            Assert.Equal("Farm", parentRetrievedWithScope.Url);
            Assert.Equal(parentScope, parentRetrievedWithScope.Scope);

            Assert.Equal("Farm", parentRetrievedNoScope.DisplayName);
            Assert.Equal(parent.Id, parentRetrievedNoScope.Id);
            Assert.Equal("Farm", parentRetrievedNoScope.Url);
            Assert.Equal(parentScope, parentRetrievedNoScope.Scope);
        }
Beispiel #3
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();
                    }
                }
            }
        }
        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;
            }
        }
        /// <summary>
        /// Record that a feature has been deactivated (at location specified by Location)
        /// </summary>
        public void RecordFeatureDeactivationAtLocation(FeatureParent location, Guid featureId)
        {
            Feature feature = GetOrAddFeatureFromDefinitions(featureId, location.Scope);

            RemoveFromFeatureLocations(feature, location);
            RemoveFromLocationFeatures(location, feature);
        }
        public void CanGetActivatedFeatureFromWeb()
        {
            // Arrange
            var parentScope = SPFeatureScope.Web;
            var parentUrl   = TestContent.SharePointContainers.SiCoActivated.Url;

            using (SPSite site = new SPSite(parentUrl))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    var parent = web;

                    var testFeatureHealthy = parent.Features[TestContent.TestFeatures.HealthyWeb.Id];
                    var testFeatureFaulty  = parent.Features[TestContent.TestFeatures.FaultyWeb.Id];

                    var featureParent = new FeatureParent(parent.Title, parentUrl, parent.ID, parentScope);

                    // Act
                    var sharePointFeatureHealthy = ActivatedFeature.GetActivatedFeature(testFeatureHealthy);
                    var sharePointFeatureFaulty  = ActivatedFeature.GetActivatedFeature(testFeatureFaulty);

                    var sharePointFeatureRetrievedWithParentHealthy = ActivatedFeature.GetActivatedFeature(testFeatureHealthy, featureParent);
                    var sharePointFeatureRetrievedWithParentFaulty  = ActivatedFeature.GetActivatedFeature(testFeatureFaulty, featureParent);

                    // Assert
                    Assert.Equal(TestContent.TestFeatures.FaultyWeb.Id, sharePointFeatureFaulty.Id);
                    Assert.Equal(TestContent.TestFeatures.FaultyWeb.Name, sharePointFeatureFaulty.Name);
                    Assert.Equal(featureParent.Url, sharePointFeatureFaulty.Parent.Url);
                    Assert.Equal(featureParent.DisplayName, sharePointFeatureFaulty.Parent.DisplayName);
                    Assert.Equal(featureParent.Id, sharePointFeatureFaulty.Parent.Id);
                    Assert.Equal(featureParent.Scope, sharePointFeatureFaulty.Parent.Scope);
                    Assert.Equal(TestContent.TestFeatures.FaultyWeb.Version, sharePointFeatureFaulty.Version);
                    Assert.Equal(parentScope, sharePointFeatureFaulty.Scope);
                    Assert.Equal(TestContent.TestFeatures.FaultyWeb.Faulty, sharePointFeatureFaulty.Faulty);

                    Assert.Equal(TestContent.TestFeatures.FaultyWeb.Id, sharePointFeatureRetrievedWithParentFaulty.Id);
                    Assert.Equal(TestContent.TestFeatures.FaultyWeb.Name, sharePointFeatureRetrievedWithParentFaulty.Name);
                    Assert.Equal(featureParent.Url, sharePointFeatureRetrievedWithParentFaulty.Parent.Url);
                    Assert.Equal(TestContent.TestFeatures.FaultyWeb.Version, sharePointFeatureRetrievedWithParentFaulty.Version);
                    Assert.Equal(parentScope, sharePointFeatureRetrievedWithParentFaulty.Scope);
                    Assert.Equal(TestContent.TestFeatures.FaultyWeb.Faulty, sharePointFeatureRetrievedWithParentFaulty.Faulty);

                    Assert.Equal(TestContent.TestFeatures.HealthyWeb.Id, sharePointFeatureHealthy.Id);
                    Assert.Equal(TestContent.TestFeatures.HealthyWeb.Name, sharePointFeatureHealthy.Name);
                    Assert.Equal(featureParent.Url, sharePointFeatureHealthy.Parent.Url);
                    Assert.Equal(TestContent.TestFeatures.HealthyWeb.Version, sharePointFeatureHealthy.Version);
                    Assert.Equal(parentScope, sharePointFeatureHealthy.Scope);
                    Assert.Equal(TestContent.TestFeatures.HealthyWeb.Faulty, sharePointFeatureHealthy.Faulty);

                    Assert.Equal(TestContent.TestFeatures.HealthyWeb.Id, sharePointFeatureRetrievedWithParentHealthy.Id);
                    Assert.Equal(TestContent.TestFeatures.HealthyWeb.Name, sharePointFeatureRetrievedWithParentHealthy.Name);
                    Assert.Equal(featureParent.Url, sharePointFeatureRetrievedWithParentHealthy.Parent.Url);
                    Assert.Equal(TestContent.TestFeatures.HealthyWeb.Version, sharePointFeatureRetrievedWithParentHealthy.Version);
                    Assert.Equal(parentScope, sharePointFeatureRetrievedWithParentHealthy.Scope);
                    Assert.Equal(TestContent.TestFeatures.HealthyWeb.Faulty, sharePointFeatureRetrievedWithParentHealthy.Faulty);
                }
            }
        }
 /// <summary>
 /// Remove record from our _FeaturesLocation
 /// </summary>
 private void RemoveFromFeatureLocations(Feature feature, FeatureParent location)
 {
     if (_FeatureLocations.ContainsKey(feature.Id))
     {
         List <FeatureParent> locations = _FeatureLocations[feature.Id];
         if (locations.Contains(location))
         {
             locations.Remove(location);
         }
         UpdateFeatureLocationCount(feature.Id);
     }
 }
        /// <summary>
        /// Remove record from our _LocationFeatures
        /// </summary>
        private void RemoveFromLocationFeatures(FeatureParent location, Feature feature)
        {
            string lkey = location.Key;

            if (_LocationFeatures.ContainsKey(lkey))
            {
                List <Feature> features = _LocationFeatures[lkey];
                if (features.Contains(feature))
                {
                    features.Remove(feature);
                }
            }
        }
        /// <summary>
        /// Add record to our _FeaturesLocation
        /// </summary>
        private void AddToFeatureLocations(Feature feature, FeatureParent location)
        {
            if (!_FeatureLocations.ContainsKey(feature.Id))
            {
                _FeatureLocations.Add(feature.Id, new List <FeatureParent>());
            }
            List <FeatureParent> locations = _FeatureLocations[feature.Id];

            if (!locations.Contains(location))
            {
                locations.Add(location);
                UpdateFeatureLocationCount(feature.Id);
            }
        }
        /// <summary>
        /// Add record to our _LocationFeatures
        /// </summary>
        private void AddToLocationFeatures(FeatureParent location, Feature feature)
        {
            string lkey = location.Key;

            if (!_LocationFeatures.ContainsKey(lkey))
            {
                _LocationFeatures.Add(lkey, new List <Feature>());
            }
            List <Feature> features = _LocationFeatures[lkey];

            if (!features.Contains(feature))
            {
                features.Add(feature);
            }
        }
Beispiel #11
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);
                }
            }
        }
        internal static List <FeatureParent> SelectedRowsToFeatureParent(DataGridViewSelectedRowCollection selectedRows)
        {
            if (selectedRows == null || selectedRows.Count == 1)
            {
                Log.Warning("No feature parents selected!");
                return(null);
            }

            var convertedRows = new List <FeatureParent>();

            foreach (DataGridViewRow row in selectedRows)
            {
                FeatureParent fd = row.DataBoundItem as FeatureParent;
                convertedRows.Add(fd);
            }

            return(convertedRows);
        }
        public void CanGetFeatureParentFromWeb()
        {
            // Arrange
            var parentScope = SPFeatureScope.Web;
            var parentUrl   = TestContent.SharePointContainers.SiCoActivated.Url;

            using (SPSite site = new SPSite(parentUrl))
            {
                using (SPWeb parent = site.OpenWeb())
                {
                    var testFeatureHealthy = parent.Features[TestContent.TestFeatures.HealthyWeb.Id];
                    var testFeatureFaulty  = parent.Features[TestContent.TestFeatures.FaultyWeb.Id];

                    // Act
                    var parentHealthy = FeatureParent.GetFeatureParent(testFeatureHealthy);
                    var parentFaulty  = FeatureParent.GetFeatureParent(testFeatureFaulty);
                    var parentRetrievedWithScopeHealthy = FeatureParent.GetFeatureParent(testFeatureHealthy, parentScope);
                    var parentRetrievedWithScopeFaulty  = FeatureParent.GetFeatureParent(testFeatureFaulty, parentScope);

                    // Assert
                    Assert.Equal(parent.Title, parentHealthy.DisplayName);
                    Assert.Equal(parent.ID, parentHealthy.Id);
                    Assert.Equal(parentUrl, parentHealthy.Url);
                    Assert.Equal(parentScope, parentHealthy.Scope);

                    Assert.Equal(parent.Title, parentFaulty.DisplayName);
                    Assert.Equal(parent.ID, parentFaulty.Id);
                    Assert.Equal(parentUrl, parentFaulty.Url);
                    Assert.Equal(parentScope, parentFaulty.Scope);

                    Assert.Equal(parent.Title, parentRetrievedWithScopeHealthy.DisplayName);
                    Assert.Equal(parent.ID, parentRetrievedWithScopeHealthy.Id);
                    Assert.Equal(parentUrl, parentRetrievedWithScopeHealthy.Url);
                    Assert.Equal(parentScope, parentRetrievedWithScopeHealthy.Scope);

                    Assert.Equal(parent.Title, parentRetrievedWithScopeFaulty.DisplayName);
                    Assert.Equal(parent.ID, parentRetrievedWithScopeFaulty.Id);
                    Assert.Equal(parentUrl, parentRetrievedWithScopeFaulty.Url);
                    Assert.Equal(parentScope, parentRetrievedWithScopeFaulty.Scope);
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// To set up a SharePoint hierarchy of web apps, site collections and webs, this method sets up the hierarchy tree
        /// </summary>
        /// <param name="parentOfThisParent">the parent container of this parent in the sharepoint hierarchy</param>
        /// <param name="parent">SharePoint container to add to hierarchy</param>
        /// <param name="hasChildren">if this container itself has children, new entry is created in hierarchy collection</param>
        private void AddParentToHierarchyAndParentsList(Guid parentOfThisParent, FeatureParent parent, bool hasChildren)
        {
            if (parent == null)
            {
                return;
            }

            // add to parents list
            Parents.Add(parent);

            //if (SharePointParentHierarchy.ContainsKey(parentOfThisParent))
            //{
            SharePointParentHierarchy[parentOfThisParent].Add(parent);
            //}


            if (hasChildren)
            {
                SharePointParentHierarchy.Add(parent.Id, new List <FeatureParent>());
            }
        }
        public void CanGetActivatedFeatureFromFarm()
        {
            // Arrange
            var parentScope = SPFeatureScope.Farm;
            // var parentUrl = TestContent.SharePointContainers.WebApplication.Url;


            SPWebService farm = SPWebService.ContentService;

            var parent = farm;

            // Act

            var testFeatureHealthy = parent.Features[TestContent.TestFeatures.HealthyFarm.Id];
            // web app features cannot easily be reproduced in faulty state
            // var testFeatureFaulty = parent.Features[TestContent.TestFeatures.FaultyFarm.Id];

            var featureParent = FeatureParent.GetFeatureParent(parent);


            var sharePointFeatureHealthy = ActivatedFeature.GetActivatedFeature(testFeatureHealthy);
            var sharePointFeatureRetrievedWithParentHealthy = ActivatedFeature.GetActivatedFeature(testFeatureHealthy, featureParent);

            // Assert
            Assert.Equal(TestContent.TestFeatures.HealthyFarm.Id, sharePointFeatureHealthy.Id);
            Assert.Equal(TestContent.TestFeatures.HealthyFarm.Name, sharePointFeatureHealthy.Name);
            Assert.Equal(featureParent.Url, sharePointFeatureHealthy.Parent.Url);
            Assert.Equal(TestContent.TestFeatures.HealthyFarm.Version, sharePointFeatureHealthy.Version);
            Assert.Equal(parentScope, sharePointFeatureHealthy.Scope);
            Assert.Equal(TestContent.TestFeatures.HealthyFarm.Faulty, sharePointFeatureHealthy.Faulty);

            Assert.Equal(TestContent.TestFeatures.HealthyFarm.Id, sharePointFeatureRetrievedWithParentHealthy.Id);
            Assert.Equal(TestContent.TestFeatures.HealthyFarm.Name, sharePointFeatureRetrievedWithParentHealthy.Name);
            Assert.Equal(featureParent.Url, sharePointFeatureRetrievedWithParentHealthy.Parent.Url);
            Assert.Equal(TestContent.TestFeatures.HealthyFarm.Version, sharePointFeatureRetrievedWithParentHealthy.Version);
            Assert.Equal(parentScope, sharePointFeatureRetrievedWithParentHealthy.Scope);
            Assert.Equal(TestContent.TestFeatures.HealthyFarm.Faulty, sharePointFeatureRetrievedWithParentHealthy.Faulty);
        }
        public void CanGetActivatedFeatureFromWebApp()
        {
            // Arrange
            var parentScope = SPFeatureScope.WebApplication;
            var parentUrl   = TestContent.SharePointContainers.WebApplication.Url;

            using (SPSite site = new SPSite(TestContent.SharePointContainers.SiCoInActive.Url))
            {
                SPWebApplication parent = site.WebApplication;

                // Act

                var testFeatureHealthy = parent.Features[TestContent.TestFeatures.HealthyWebApp.Id];
                // web app features cannot easily be reproduced in faulty state
                // var testFeatureFaulty = parent.Features[TestContent.TestFeatures.FaultyWebApp.Id];

                var featureParent = FeatureParent.GetFeatureParent(parent);


                var sharePointFeatureHealthy = ActivatedFeature.GetActivatedFeature(testFeatureHealthy);
                var sharePointFeatureRetrievedWithParentHealthy = ActivatedFeature.GetActivatedFeature(testFeatureHealthy, featureParent);

                // Assert
                Assert.Equal(TestContent.TestFeatures.HealthyWebApp.Id, sharePointFeatureHealthy.Id);
                Assert.Equal(TestContent.TestFeatures.HealthyWebApp.Name, sharePointFeatureHealthy.Name);
                Assert.Equal(featureParent.Url, sharePointFeatureHealthy.Parent.Url);
                Assert.Equal(TestContent.TestFeatures.HealthyWebApp.Version, sharePointFeatureHealthy.Version);
                Assert.Equal(parentScope, sharePointFeatureHealthy.Scope);
                Assert.Equal(TestContent.TestFeatures.HealthyWebApp.Faulty, sharePointFeatureHealthy.Faulty);

                Assert.Equal(TestContent.TestFeatures.HealthyWebApp.Id, sharePointFeatureRetrievedWithParentHealthy.Id);
                Assert.Equal(TestContent.TestFeatures.HealthyWebApp.Name, sharePointFeatureRetrievedWithParentHealthy.Name);
                Assert.Equal(featureParent.Url, sharePointFeatureRetrievedWithParentHealthy.Parent.Url);
                Assert.Equal(TestContent.TestFeatures.HealthyWebApp.Version, sharePointFeatureRetrievedWithParentHealthy.Version);
                Assert.Equal(parentScope, sharePointFeatureRetrievedWithParentHealthy.Scope);
                Assert.Equal(TestContent.TestFeatures.HealthyWebApp.Faulty, sharePointFeatureRetrievedWithParentHealthy.Faulty);
            }
        }
 public List <Feature> GetFeaturesOfLocation(FeatureParent location)
 {
     return(GetFeaturesOfLocation(location.Key));
 }
 private void AddSiteDetails(FeatureParent location)
 {
 }
Beispiel #19
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();
                            }
                        }
                    }
                }
            });
        }
 private void AddWebDetails(FeatureParent location)
 {
 }
        /// <summary>
        /// Record that a feature has been deactivated
        /// </summary>
        public void RecordFeatureDeactivation(object locobj, Guid featureId)
        {
            FeatureParent location = LocationManager.GetLocation(locobj);

            RecordFeatureDeactivationAtLocation(location, featureId);
        }