Exemplo n.º 1
0
        public LoadedDto LoadWebApps()
        {
            var spFarm = SpLocationHelper.GetFarm();

            var farmLocation = SpConverter.ToLocation(spFarm);

            // this variable will save all loaded information of all web applications
            var loadedElements = new LoadedDto(farmLocation);

            var spWebApps = SpLocationHelper.GetAllWebApplications();

            foreach (var wa in spWebApps)
            {
                var waLocation = wa.ToLocation(farmLocation.UniqueId);

                var activatedFeatures = wa.Features.ToActivatedFeatures(waLocation);

                // no non full trust farm features expected on scope web app
                // (sand boxed and add-in features are only scoped site and web)

                loadedElements.AddChild(waLocation, activatedFeatures, null);
            }

            return(loadedElements);
        }
Exemplo n.º 2
0
        public LoadedDto LoadFarm()
        {
            var loadedFarm = new LoadedDto(null);

            var farm = SpLocationHelper.GetFarm();

            var farmLocation = SpConverter.ToLocation(farm);

            var activatedFeatures = SpConverter.ToActivatedFeatures(farm.Features, farmLocation);

            // no non full trust farm features expected on scope farm
            // (sand boxed and add-in features are only scoped site and web)

            loadedFarm.AddChild(farmLocation, activatedFeatures, null);

            return(loadedFarm);
        }
Exemplo n.º 3
0
        public LoadedDto LoadFarm()
        {
            var loadedFarm = new LoadedDto(null);

            var location = demoRepository.SearchLocations(string.Empty, Scope.Farm, null).FirstOrDefault();

            if (location != null)
            {
                var activatedFeatures = GetDemoActivatedFeatures(location.Item);
                var definitions       = GetDemoFeatureDefinitions(location.Item);

                loadedFarm.AddChild(location.Item, activatedFeatures, definitions);

                return(loadedFarm);
            }

            return(null);
        }
Exemplo n.º 4
0
        public LoadedDto LoadWebAppChildren(Location location, bool elevatedPrivileges)
        {
            // this variable will save all loaded information of all web applications
            var loadedElements = new LoadedDto(location);

            var spWebApp = SpLocationHelper.GetWebApplication(location.Id);

            if (spWebApp == null)
            {
                // The web application might have got deleted!?
                // throw?
                return(null);
            }

            var siCos = spWebApp.Sites;

            foreach (SPSite spSite in siCos)
            {
                Location siteLocation;
                //try
                //{

                if (elevatedPrivileges)
                {
                    siteLocation = SpSiteElevation.SelectAsSystem(spSite, SpConverter.ToLocation, location.UniqueId);
                }
                else
                {
                    siteLocation = SpConverter.ToLocation(spSite, location.UniqueId);
                }

                // meaning that they are not installed in the farm, rather on site or web level
                IEnumerable <FeatureDefinition> nonFarmFeatureDefinitions;

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

                var activatedSiteFeatures = siteFeatureCollection.ToActivatedFeatures(siteLocation, out nonFarmFeatureDefinitions);

                loadedElements.AddChild(siteLocation, activatedSiteFeatures, nonFarmFeatureDefinitions);

                if (siteLocation.LockState != LockState.NoAccess && spSite != null && spSite.AllWebs != null)
                {
                    SPWebCollection allWebs;

                    if (elevatedPrivileges)
                    {
                        allWebs = SpSiteElevation.SelectAsSystem(spSite, SpLocationHelper.GetAllWebs);
                    }
                    else
                    {
                        allWebs = spSite.AllWebs;
                    }

                    foreach (SPWeb spWeb in allWebs)
                    {
                        var webLocation = SpConverter.ToLocation(spWeb, siteLocation.UniqueId);

                        nonFarmFeatureDefinitions = null;

                        SPFeatureCollection webFeatureCollection = SpFeatureHelper.GetFeatureCollection(spWeb, elevatedPrivileges);

                        var activatedWebFeatures = webFeatureCollection.ToActivatedFeatures(webLocation, out nonFarmFeatureDefinitions);

                        loadedElements.AddChild(webLocation, activatedWebFeatures, nonFarmFeatureDefinitions);

                        // https://blogs.technet.microsoft.com/stefan_gossner/2008/12/05/disposing-spweb-and-spsite-objects/
                        spWeb.Dispose();
                    }
                }

                spSite.Dispose();

                // This is the right place for debugging exception handling of lock state of site collections
                //}
                //catch (Exception Ex)
                //{

                //    throw Ex;
                //}
            }

            return(loadedElements);
        }