Exemple #1
0
        public static FeatureDefinition GetFeatureDefinition(
            ActivatedFeature activatedFeature, Location location)
        {
            if (activatedFeature != null)
            {
                FeatureDefinition fDef;

                if (activatedFeature.Faulty || activatedFeature.Definition == null)
                {
                    fDef = FeatureDefinitionFactory.GetFaultyDefinition(
                        activatedFeature.FeatureId,
                        location.Scope,
                        activatedFeature.Version,
                        activatedFeature.DefinitionInstallationScope
                        );
                }
                else
                {
                    fDef = activatedFeature.Definition;
                }

                fDef.ToggleActivatedFeature(activatedFeature, true);
                return(fDef);
            }
            else
            {
                //TODO Log unexpected definition not found
                return(null);
            }
        }
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);
        }
        private string ActivateFeature(FeatureDefinition feature, Location location, bool elevatedPrivileges, bool force
                                       , out ActivatedFeature activatedFeature)
        {
            var props = new Dictionary <string, string>()
            {
                { "demo activation 'elevatedPrivileges' setting", elevatedPrivileges.ToString() },
                { "demo activation 'force' setting", force.ToString() }
            };

            activatedFeature = Core.Factories.ActivatedFeatureFactory.GetActivatedFeature(
                feature.UniqueIdentifier
                , location.UniqueId
                , feature.DisplayName
                , false
                , props
                , DateTime.Now
                , feature.Version,
                feature.Version
                );



            demoRepository.AddActivatedFeature(activatedFeature);

            // wait 1 second in the demo
            System.Threading.Thread.Sleep(1000);

            return(string.Empty);
        }
Exemple #4
0
        public static ActivatedFeature GetActivatedFeature(
            string featureId,
            string locationId,
            string displayName,
            bool faulty,
            Dictionary <string, string> properties,
            DateTime timeActivated,
            Version version,
            Version definitionVersion,
            FeatureDefinitionScope featureDefinitionScope = FeatureDefinitionScope.Farm
            )
        {
            var activatedFeature = new ActivatedFeature(
                featureId,
                locationId,
                displayName,
                faulty,
                properties,
                timeActivated,
                version,
                definitionVersion,
                featureDefinitionScope);

            return(activatedFeature);
        }
Exemple #5
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();
                    }
                }
            }
        }
        public static string WebAppFeatureAction(
            FeatureDefinition feature,
            Location location,
            Func <SPFeatureCollection, Guid, bool, SPFeature> featureAction,
            bool force,
            out ActivatedFeature resultingFeature)
        {
            resultingFeature = null;

            try
            {
                var wa = SpLocationHelper.GetWebApplication(location.Id);

                var spResultingFeature = featureAction(wa.Features, feature.Id, force);

                if (spResultingFeature != null)
                {
                    resultingFeature = spResultingFeature.ToActivatedFeature(location);
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return(string.Empty);
        }
        // Following needs to be equal:
        // FeatureId, LocationId
        public void ActiveFeaturesWithSameFeatureIdAndLocationIdAreEqual()
        {
            // Arrange
            var referenceFeatureDefinition = FeatureDefinitionFactory.GetFeatureDefinition(
                Id, CompatibilityLevel,
                Description,
                DisplayName, Hidden,
                Name, Properties,
                Scope,
                Title,
                SolutionId, UiVersion,
                Version, DefinitioninstallationScope
                );

            ActivatedFeature referenceFeature = ActivatedFeatureFactory.GetActivatedFeature(
                Id,
                Locations.ActivatedRootWeb.Guid,
                referenceFeatureDefinition,
                Faulty, Properties, TimeActivated,
                Version, DefinitioninstallationScope
                );



            // Act

            var definitionDifferent = FeatureDefinitionFactory.GetFeatureDefinition(
                Id, CompatibilityLevel,
                null,
                null, HiddenDifferent,
                Name, null,
                Scope,
                null,
                Guid.Empty, null,
                null, DefinitioninstallationScope
                );

            var equalFeature = ActivatedFeatureFactory.GetActivatedFeature(
                Id,
                Locations.ActivatedRootWeb.Guid,
                definitionDifferent,
                FaultyDifferent, PropertiesDifferent, TimeActivatedDifferent,
                VersionDifferent, DefinitioninstallationScopeDifferent
                );

            var equalFeatureEmpty = ActivatedFeatureFactory.GetActivatedFeature(
                Id,
                Locations.ActivatedRootWeb.Guid,
                null,
                FaultyDifferent, null, DateTime.MinValue,
                null, null
                );

            // Assert

            Assert.Equal(referenceFeature, equalFeature);

            Assert.Equal(referenceFeature, equalFeatureEmpty);
        }
        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);
                }
            }
        }
        // Following needs to be equal:
        // FeatureId, Compatibility level, Name, Scope, DefinitioninstallationScope
        public void DefinitionsWithSameFeatureIdCompLevelNameAndScopeAreEqual()
        {
            // Arrange
            var referenceFeature = FeatureDefinitionFactory.GetFeatureDefinition(
                Id, CompatibilityLevel,
                Description,
                DisplayName, Hidden,
                Name, Properties,
                Scope,
                Title,
                SolutionId, UiVersion,
                Version, DefinitioninstallationScope
                );

            ActivatedFeature ActiveFeature1 = ActivatedFeatureFactory.GetActivatedFeature(
                Id,
                Locations.ActivatedRootWeb.Guid,
                referenceFeature,
                Faulty, null, DateTime.Now,
                Version
                );

            referenceFeature.ToggleActivatedFeature(ActiveFeature1, true);

            // Act
            var equalFeature = FeatureDefinitionFactory.GetFeatureDefinition(
                Id, CompatibilityLevel,
                DescriptionDifferent,
                DisplayNameDifferent, HiddenDifferent,
                Name, PropertiesDifferent,
                Scope,
                TitleDifferent,
                SolutionIdDifferent, UiVersionDifferent,
                VersionDifferent, DefinitioninstallationScope
                );

            // Assert

            Assert.Equal(referenceFeature, equalFeature);

            // Act
            var equalFeatureEmpty = FeatureDefinitionFactory.GetFeatureDefinition(
                Id, CompatibilityLevel,
                null,
                null, HiddenDifferent,
                Name, null,
                Scope,
                null,
                Guid.Empty, null,
                null, DefinitioninstallationScope
                );

            // Assert

            Assert.Equal(referenceFeature, equalFeatureEmpty);
        }
Exemple #10
0
        /// <summary>
        /// provides the information for the activated feature
        /// </summary>
        /// <param name="taskId">reference to task id</param>
        /// <param name="locationReferenceId">where did action take place</param>
        /// <param name="activatedFeature">the activated feature</param>
        /// <param name="error">was activation successful?</param>
        public FeatureActivationCompleted(
            Guid taskId
            , string locationReferenceId
            , ActivatedFeature activatedFeature
            )

            : base(taskId, locationReferenceId)
        {
            ActivatedFeature = activatedFeature;
        }
        /// <summary>
        /// provides the information for the upgraded feature
        /// </summary>
        /// <param name="taskId">reference to task id</param>
        /// <param name="locationReferenceId">where did action take place</param>
        /// <param name="upgradedFeature">the upgraded feature</param>
        /// <param name="error">was activation successful?</param>
        public FeatureUpgradeCompleted(
            Guid taskId
            , string locationReferenceId
            , ActivatedFeature upgradedFeature
            )

            : base(taskId, locationReferenceId)
        {
            UpgradedFeature = upgradedFeature;
        }
        /// <summary>
        /// provides the loaded location including child locations
        /// </summary>
        /// <param name="taskId">reference to task id</param>
        /// <param name="locationReference">where did action take place</param>
        /// <param name="activatedFeature">the activated feature</param>
        /// <param name="error">was activation successful?</param>
        public FeatureActivationCompleted(
            Guid taskId
            , Guid locationReference
            , ActivatedFeature activatedFeature
            , string error = null
            )

            : base(taskId, locationReference, error)
        {
            ActivatedFeature = activatedFeature;
        }
Exemple #13
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 #14
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 #15
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);
        }
        public string ActivateFeature(FeatureDefinition feature, Location location, bool elevatedPrivileges, bool force
                                      , out ActivatedFeature activatedFeature)
        {
            activatedFeature = Core.Factories.ActivatedFeatureFactory.GetActivatedFeature(
                feature.Id
                , location.Id
                , feature
                , false
                , null
                , DateTime.Now
                , feature.Version
                );

            demoActivatedFeatures.Add(activatedFeature);
            return(string.Empty);
        }
Exemple #17
0
        public string AddActivatedFeature(ActivatedFeature feature)
        {
            ActivatedFeature featureToAdd;

            featureToAdd = ActivatedFeatures.FirstOrDefault(f => f == feature);

            if (featureToAdd == null)
            {
                ActivatedFeatures.Add(feature);
                return(null);
            }
            else
            {
                return(string.Format("Problem in Repository. Could not add. Activated Feature already existed in repository with id '{0}' in location '{1}' - Please 'Reload'", feature.FeatureId, feature.LocationId));
            }
        }
Exemple #18
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 #19
0
        // Following needs to be equal:
        // FeatureId, LocationId
        public void ActiveFeaturesWithDifferentFeatureIdOrLocationIdAreNotEqual()
        {
            // Arrange
            var referenceFeatureDefinition = FeatureDefinitionFactory.GetFeatureDefinition(
                Id, CompatibilityLevel,
                Description,
                DisplayName, Hidden,
                Name, Properties,
                Scope,
                Title,
                SolutionId, UiVersion,
                Version
                );

            ActivatedFeature referenceFeature = ActivatedFeatureFactory.GetActivatedFeature(
                referenceFeatureDefinition.UniqueIdentifier,
                SolutionId.ToString(),
                referenceFeatureDefinition.DisplayName,
                Faulty, Properties, TimeActivated,
                Version, referenceFeatureDefinition.Version
                );


            // Act
            var notEqualFeatureId = ActivatedFeatureFactory.GetActivatedFeature(
                IdDifferent.ToString(),
                SolutionId.ToString(),
                referenceFeatureDefinition.DisplayName,
                Faulty, Properties, TimeActivated,
                Version, referenceFeatureDefinition.Version
                );

            var notEqualLocationId = ActivatedFeatureFactory.GetActivatedFeature(
                referenceFeatureDefinition.UniqueIdentifier,
                SolutionIdDifferent.ToString(),
                referenceFeatureDefinition.DisplayName,
                Faulty, Properties, TimeActivated,
                Version, referenceFeatureDefinition.Version
                );

            // Assert

            Assert.NotEqual(referenceFeature, notEqualFeatureId);
            Assert.NotEqual(referenceFeature, notEqualLocationId);
        }
        internal static List <ActivatedFeature> SelectedRowsToActivatedFeature(CheckedItemCollection selectedRows)
        {
            if (selectedRows == null || selectedRows.Count == 1)
            {
                Log.Warning("No activated features selected!");
                return(null);
            }

            var convertedRows = new List <ActivatedFeature>();

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

            return(convertedRows);
        }
Exemple #21
0
        /// <summary>
        /// Get a feature definition based on an activated feature, even from a faulty one
        /// </summary>
        /// <param name="feature">an activated Feature</param>
        /// <returns>A FeatureDefinition with current feature already added</returns>
        /// <remarks>
        /// ActivatedFeature is better than SPFeature, because it already handled the faulty feature issues
        /// </remarks>
        public static FeatureDefinition GetFeatureDefinition(ActivatedFeature feature)
        {
            if (feature == null)
            {
                throw new ArgumentNullException("Parameter 'feature'");
            }

            var fd = new FeatureDefinition()
            {
                Id         = feature.Id,
                Name       = feature.Name,
                Scope      = feature.Scope,
                Faulty     = feature.Faulty,
                Definition = feature.Definition
            };

            fd.ActivatedFeatures.Add(feature);

            return(fd);
        }
        public static DetailViewModel ToDetailViewModel(this ActivatedFeature vm)
        {
            string displayName = vm.DisplayName;

            var items = new List <KeyValuePair <string, string> >();


            items.Add(new KeyValuePair <string, string>(nameof(vm.DisplayName), vm.DisplayName));
            items.Add(new KeyValuePair <string, string>(nameof(vm.FeatureId), vm.FeatureId.ToString()));
            items.Add(new KeyValuePair <string, string>(nameof(vm.LocationId), vm.LocationId.ToString()));
            items.Add(new KeyValuePair <string, string>(nameof(vm.Definition.Scope), vm.Definition.Scope.ToString()));
            items.Add(new KeyValuePair <string, string>(nameof(vm.TimeActivated), vm.TimeActivated.ToString()));
            items.Add(new KeyValuePair <string, string>(nameof(vm.Version), vm.Version.ToString()));
            items.Add(new KeyValuePair <string, string>(nameof(vm.Faulty), vm.Faulty.ToString()));
            items.Add(new KeyValuePair <string, string>(nameof(Properties), PropertiesToString(vm.Properties)));

            var dvm = new DetailViewModel(displayName, items);

            return(dvm);
        }
        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 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 static string SiteFeatureAction(
            FeatureDefinition feature,
            Location location,
            Func <SPFeatureCollection, Guid, bool, SPFeature> featureAction,
            bool elevatedPrivileges, bool force,
            out ActivatedFeature resultingFeature)
        {
            resultingFeature = null;

            SPSite spSite = null;

            try
            {
                spSite = SpLocationHelper.GetSite(location);

                SPFeatureCollection featureCollection = SpFeatureHelper.GetFeatureCollection(spSite, elevatedPrivileges);

                var spResultingFeature = featureAction(featureCollection, feature.Id, force);

                if (spResultingFeature != null)
                {
                    resultingFeature = spResultingFeature.ToActivatedFeature(location);
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            finally
            {
                if (spSite != null)
                {
                    spSite.Dispose();
                }
            }

            return(string.Empty);
        }
Exemple #26
0
        public void AddActivatedFeature(SPFeature feature)
        {
            if (feature == null)
            {
                return;
            }

            try
            {
                var activatedFeature = ActivatedFeature.GetActivatedFeature(feature);

                // update activated features
                this.ActivatedFeatures.Add(activatedFeature);


                // update featureDefinition (and its activated instances)
                var featureDef = this.FeatureDefinitions.FirstOrDefault(fd => fd.Id == activatedFeature.Id);

                if (featureDef != null)
                {
                    // add activated feature to feature definition
                    featureDef.ActivatedFeatures.Add(activatedFeature);
                }
                else
                {
                    // fyi - if we get here, we have most likely a group of faulty features ...

                    // create feature definition and add features
                    var newFeatureDef = FeatureDefinition.GetFeatureDefinition(activatedFeature);
                    this.FeatureDefinitions.Add(newFeatureDef);
                    Log.Warning("Unexpected - Feature Definition of activated Feature was not available - please Reload");
                }
            }
            catch (Exception ex)
            {
                Log.Error("Error when trying to add new feature to InMemorySharePointDb", ex);
            }
        }
Exemple #27
0
        public static ActivatedFeature GetActivatedFeature(
            Guid featureId,
            Guid locationId,
            FeatureDefinition definition,
            bool faulty,
            Dictionary <string, string> properties,
            DateTime timeActivated,
            Version version,
            string definitionInstallationScope = "Farm"
            )
        {
            var activatedFeature = new ActivatedFeature(
                featureId,
                locationId,
                definition,
                faulty,
                properties,
                timeActivated,
                version,
                definitionInstallationScope);

            return(activatedFeature);
        }
 public string AddActivatedFeature([NotNull] ActivatedFeature feature)
 {
     return(store.AddActivatedFeature(feature));
 }
        /// <summary>
        /// Generate ActivatedFeature
        /// </summary>
        /// <param name="spFeature"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public static ActivatedFeature GetActivatedFeature(SPFeature spFeature, FeatureParent parent = null)
        {
            if (spFeature == null)
            {
                return(null);
            }

            // create preliminary feature with default values ...
            ActivatedFeature af = new ActivatedFeature()
            {
                Id                = Guid.Empty,
                Version           = new Version("0.0.0.0"),
                Parent            = parent,
                SharePointFeature = spFeature,
                Name              = "undefined",
                Faulty            = false
            };

            // in case of faulty features, many of these settings can not be set
            // therefore, every property is set in try / catch statement

            // ID
            try
            {
                af.Id = spFeature.DefinitionId;
            }
            catch (Exception ex)
            {
                if (af.Name.Equals("undefined"))
                {
                    af.Name = ex.Message;
                }
                af.Faulty = true;
            }

            // Version
            try
            {
                af.TimeActivated = spFeature.TimeActivated;
            }
            catch (Exception ex)
            {
                if (af.Name.Equals("undefined"))
                {
                    af.Name = ex.Message;
                }
                af.Faulty = true;
            }

            // Version
            try
            {
                af.Version = spFeature.Version;
            }
            catch (Exception ex)
            {
                if (af.Name.Equals("undefined"))
                {
                    af.Name = ex.Message;
                }
                af.Faulty = true;
            }

            // Parent
            try
            {
                af.Parent = parent == null?FeatureParent.GetFeatureParent(spFeature) : parent;
            }
            catch (Exception ex)
            {
                if (af.Name.Equals("undefined"))
                {
                    af.Name = ex.Message;
                }
                af.Faulty = true;
            }

            // SharePointFeature is already set on initialization of af
            // Name
            try
            {
                var def = spFeature.Definition;

                if (def != null)
                {
                    af.Name = def.DisplayName;
                }
                else
                {
                    af.Name   = string.Format(Common.Constants.Text.UndefinedActivatedFeature, af.Id);
                    af.Faulty = true;
                }
            }
            catch (Exception ex)
            {
                if (af.Name.Equals("undefined"))
                {
                    af.Name = ex.Message;
                }
                af.Faulty = true;
            }

            return(af);
        }
Exemple #30
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();
                            }
                        }
                    }
                }
            });
        }