Exemplo n.º 1
0
        /// <summary>
        /// Reset web navigation to its default configuration. Disabled the term set as navigation term set.
        /// </summary>
        /// <param name="web">The web</param>
        /// <param name="settings">The managed navigation settings. Set null if you want to keep the associated termset unchanged</param>
        public void ResetWebNavigationToDefault(SPWeb web, ManagedNavigationInfo settings)
        {
            var taxonomySession = new TaxonomySession(web.Site);

            if (taxonomySession.TermStores.Count > 0)
            {
                if (settings != null)
                {
                    // Disable the navigation flag on the the term set
                    var termStore = taxonomySession.DefaultSiteCollectionTermStore;
                    var group     = this.taxonomyService.GetTermGroupFromStore(termStore, settings.TermGroup.Name);
                    var termSet   = this.taxonomyService.GetTermSetFromGroup(termStore, group, settings.TermSet.Label);

                    const string PropertyName = "_Sys_Nav_IsNavigationTermSet";
                    string       propertyValue;
                    if (termSet.CustomProperties.TryGetValue(PropertyName, out propertyValue))
                    {
                        termSet.DeleteCustomProperty(PropertyName);
                        termSet.TermStore.CommitAll();
                    }
                }

                var navigationSettings = new WebNavigationSettings(web);
                navigationSettings.ResetToDefaults();
                navigationSettings.Update(taxonomySession);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Reset web navigation to its default configuration. Disabled the term set as navigation term set.
        /// </summary>
        /// <param name="web">The web</param>
        /// <param name="settings">The managed navigation settings. Set null if you want to keep the associated termset unchanged</param>
        public void ResetWebNavigationToDefault(SPWeb web, ManagedNavigationInfo settings)
        {
            var taxonomySession = new TaxonomySession(web.Site);

            if (taxonomySession.TermStores.Count > 0)
            {
                if (settings != null)
                {
                    // Disable the navigation flag on the the term set
                    var termStore = settings.TermSet.ResolveParentTermStore(taxonomySession);
                    var group     = settings.TermSet.ResolveParentGroup(taxonomySession, web.Site);
                    var termSet   = this.taxonomyService.GetTermSetFromGroup(termStore, group, settings.TermSet.Label);

                    string propertyValue;
                    if (termSet.CustomProperties.TryGetValue(SystemIsNavigationTermSet, out propertyValue))
                    {
                        termSet.DeleteCustomProperty(SystemIsNavigationTermSet);
                        termStore.CommitAll();
                    }
                }

                var navigationSettings = new WebNavigationSettings(web);
                navigationSettings.ResetToDefaults();
                navigationSettings.Update(taxonomySession);
            }
        }
Exemplo n.º 3
0
    public void ConfigureTaxonomyNavigation()
    {
        using (SPSite site = new SPSite(TestConfig.ServerUrl))
        {
            using (SPWeb web = site.OpenWeb())
            {
                TaxonomySession taxonomySession = new TaxonomySession(site, updateCache: true);

                NavigationTermSet termSet = DemoUtilities.RecreateSampleNavTermSet(
                    this.TestContext, taxonomySession, web);

                // Clear any old settings.
                WebNavigationSettings webNavigationSettings = new WebNavigationSettings(web);
                webNavigationSettings.ResetToDefaults();
                webNavigationSettings.Update(taxonomySession);

                TaxonomyNavigation.FlushSiteFromCache(site);

                this.WaitForSync();

                // Verify the TermSet object is not running.
                NavigationTermSet actualTermSet;

                actualTermSet = TaxonomyNavigation.GetTermSetForWeb(web,
                                                                    StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider,
                                                                    includeInheritedSettings: true);

                Assert.IsTrue(actualTermSet == null);

                // Assign the new settings.
                webNavigationSettings = new WebNavigationSettings(web);

                // GlobalNavigation = top menu (aka "top nav")
                // CurrentNavigation = left menu (aka "quick launch")
                webNavigationSettings.GlobalNavigation.Source      = StandardNavigationSource.TaxonomyProvider;
                webNavigationSettings.GlobalNavigation.TermStoreId = termSet.TermStoreId;
                webNavigationSettings.GlobalNavigation.TermSetId   = termSet.Id;
                webNavigationSettings.Update(taxonomySession);

                TaxonomyNavigation.FlushSiteFromCache(site);

                this.WaitForSync();

                actualTermSet = TaxonomyNavigation.GetTermSetForWeb(web,
                                                                    StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider,
                                                                    includeInheritedSettings: true);

                Assert.AreEqual(termSet.Id, actualTermSet.Id);
            }
        }
    }
        /// Configures the web to use Taxonomy Navigation with the sample term set.
        public static NavigationTermSet SetUpSampleNavTermSet(TestContext testContext,
            TaxonomySession taxonomySession, SPWeb web)
        {
            NavigationTermSet termSet = RecreateSampleNavTermSet(testContext, taxonomySession, web);

            // Clear any old settings.
            WebNavigationSettings webNavigationSettings = new WebNavigationSettings(web);
            webNavigationSettings.ResetToDefaults();

            webNavigationSettings.GlobalNavigation.Source = StandardNavigationSource.TaxonomyProvider;
            webNavigationSettings.GlobalNavigation.TermStoreId = termSet.TermStoreId;
            webNavigationSettings.GlobalNavigation.TermSetId = termSet.Id;

            webNavigationSettings.CurrentNavigation.Source = StandardNavigationSource.TaxonomyProvider;
            webNavigationSettings.CurrentNavigation.TermStoreId = termSet.TermStoreId;
            webNavigationSettings.CurrentNavigation.TermSetId = termSet.Id;

            webNavigationSettings.Update(taxonomySession);

            TaxonomyNavigation.FlushSiteFromCache(web.Site);

            return termSet;
        }
Exemplo n.º 5
0
        /// Configures the web to use Taxonomy Navigation with the sample term set.
        public static NavigationTermSet SetUpSampleNavTermSet(TestContext testContext,
                                                              TaxonomySession taxonomySession, SPWeb web)
        {
            NavigationTermSet termSet = RecreateSampleNavTermSet(testContext, taxonomySession, web);

            // Clear any old settings.
            WebNavigationSettings webNavigationSettings = new WebNavigationSettings(web);

            webNavigationSettings.ResetToDefaults();

            webNavigationSettings.GlobalNavigation.Source      = StandardNavigationSource.TaxonomyProvider;
            webNavigationSettings.GlobalNavigation.TermStoreId = termSet.TermStoreId;
            webNavigationSettings.GlobalNavigation.TermSetId   = termSet.Id;

            webNavigationSettings.CurrentNavigation.Source      = StandardNavigationSource.TaxonomyProvider;
            webNavigationSettings.CurrentNavigation.TermStoreId = termSet.TermStoreId;
            webNavigationSettings.CurrentNavigation.TermSetId   = termSet.Id;

            webNavigationSettings.Update(taxonomySession);

            TaxonomyNavigation.FlushSiteFromCache(web.Site);

            return(termSet);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Reset web navigation to its default configuration. Disabled the term set as navigation term set.
        /// </summary>
        /// <param name="web">The web</param>
        /// <param name="settings">The managed navigation settings. Set null if you want to keep the associated termset unchanged</param>
        public void ResetWebNavigationToDefault(SPWeb web, ManagedNavigationInfo settings)
        {
            var taxonomySession = new TaxonomySession(web.Site);
            if (taxonomySession.TermStores.Count > 0)
            {
                if (settings != null)
                {
                    // Disable the navigation flag on the the term set
                    var termStore = taxonomySession.DefaultSiteCollectionTermStore;
                    var group = this.taxonomyService.GetTermGroupFromStore(termStore, settings.TermGroup.Name);
                    var termSet = this.taxonomyService.GetTermSetFromGroup(termStore, group, settings.TermSet.Label);

                    const string PropertyName = "_Sys_Nav_IsNavigationTermSet";
                    string propertyValue;
                    if (termSet.CustomProperties.TryGetValue(PropertyName, out propertyValue))
                    {
                        termSet.DeleteCustomProperty(PropertyName);
                        termSet.TermStore.CommitAll();
                    }
                }

                var navigationSettings = new WebNavigationSettings(web);
                navigationSettings.ResetToDefaults();
                navigationSettings.Update(taxonomySession);
            }
        }
Exemplo n.º 7
0
    public void ConfigureTaxonomyNavigation()
    {
        ClientContext   clientContext   = new ClientContext(TestConfig.ServerUrl);
        TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);

        taxonomySession.UpdateCache();

        NavigationTermSet termSet = DemoUtilities.RecreateSampleNavTermSet(
            this.TestContext, clientContext, taxonomySession, clientContext.Web);

        // Clear out any old settings
        WebNavigationSettings webNavigationSettings = new WebNavigationSettings(clientContext, clientContext.Web);

        webNavigationSettings.ResetToDefaults();
        webNavigationSettings.Update(taxonomySession);

        TaxonomyNavigation.FlushSiteFromCache(clientContext, clientContext.Site);
        clientContext.ExecuteQuery();

        this.WaitForSync();

        // Verify the TermSet is not running
        NavigationTermSet      actualTermSet;
        ExceptionHandlingScope scope = new ExceptionHandlingScope(clientContext);

        using (scope.StartScope())
        {
            using (scope.StartTry())
            {
                actualTermSet = TaxonomyNavigation.GetTermSetForWeb(clientContext, clientContext.Web,
                                                                    "GlobalNavigationTaxonomyProvider", includeInheritedSettings: true);
            }
            using (scope.StartCatch())
            {
            }
        }
        clientContext.ExecuteQuery();

        Assert.IsTrue(actualTermSet.ServerObjectIsNull.Value);

        // Assign the new settings
        webNavigationSettings = new WebNavigationSettings(clientContext, clientContext.Web);

        clientContext.Load(webNavigationSettings,
                           w => w.GlobalNavigation,
                           w => w.CurrentNavigation
                           );
        clientContext.Load(termSet,
                           ts => ts.TermStoreId,
                           ts => ts.Id
                           );
        clientContext.ExecuteQuery();

        // GlobalNavigation = top menu (aka "top nav")
        // CurrentNavigation = left menu (aka "quick launch")
        webNavigationSettings.GlobalNavigation.Source      = StandardNavigationSource.TaxonomyProvider;
        webNavigationSettings.GlobalNavigation.TermStoreId = termSet.TermStoreId;
        webNavigationSettings.GlobalNavigation.TermSetId   = termSet.Id;
        webNavigationSettings.Update(taxonomySession);

        TaxonomyNavigation.FlushSiteFromCache(clientContext, clientContext.Site);
        clientContext.ExecuteQuery();

        this.WaitForSync();

        actualTermSet = TaxonomyNavigation.GetTermSetForWeb(clientContext, clientContext.Web,
                                                            "GlobalNavigationTaxonomyProvider", includeInheritedSettings: true);
        clientContext.Load(actualTermSet, ts => ts.Id);
        clientContext.ExecuteQuery();

        Assert.AreEqual(termSet.Id, actualTermSet.Id);
    }
    public void ConfigureTaxonomyNavigation()
    {
        using (SPSite site = new SPSite(TestConfig.ServerUrl))
        {
            using (SPWeb web = site.OpenWeb())
            {
                TaxonomySession taxonomySession = new TaxonomySession(site, updateCache: true);

                NavigationTermSet termSet = DemoUtilities.RecreateSampleNavTermSet(
                    this.TestContext, taxonomySession, web);

                // Clear any old settings.
                WebNavigationSettings webNavigationSettings = new WebNavigationSettings(web);
                webNavigationSettings.ResetToDefaults();
                webNavigationSettings.Update(taxonomySession);

                TaxonomyNavigation.FlushSiteFromCache(site);

                this.WaitForSync();

                // Verify the TermSet object is not running.
                NavigationTermSet actualTermSet;

                actualTermSet = TaxonomyNavigation.GetTermSetForWeb(web,
                    StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider,
                    includeInheritedSettings: true);

                Assert.IsTrue(actualTermSet == null);

                // Assign the new settings.
                webNavigationSettings = new WebNavigationSettings(web);

                // GlobalNavigation = top menu (aka "top nav")
                // CurrentNavigation = left menu (aka "quick launch")
                webNavigationSettings.GlobalNavigation.Source = StandardNavigationSource.TaxonomyProvider;
                webNavigationSettings.GlobalNavigation.TermStoreId = termSet.TermStoreId;
                webNavigationSettings.GlobalNavigation.TermSetId = termSet.Id;
                webNavigationSettings.Update(taxonomySession);

                TaxonomyNavigation.FlushSiteFromCache(site);

                this.WaitForSync();

                actualTermSet = TaxonomyNavigation.GetTermSetForWeb(web,
                    StandardNavigationProviderNames.GlobalNavigationTaxonomyProvider,
                    includeInheritedSettings: true);

                Assert.AreEqual(termSet.Id, actualTermSet.Id);
            }
        }
    }
    public void ConfigureTaxonomyNavigation()
    {
        ClientContext clientContext = new ClientContext(TestConfig.ServerUrl);
        TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
        taxonomySession.UpdateCache();

        NavigationTermSet termSet = DemoUtilities.RecreateSampleNavTermSet(
            this.TestContext, clientContext, taxonomySession, clientContext.Web);

        // Clear out any old settings
        WebNavigationSettings webNavigationSettings = new WebNavigationSettings(clientContext, clientContext.Web);
        webNavigationSettings.ResetToDefaults();
        webNavigationSettings.Update(taxonomySession);

        TaxonomyNavigation.FlushSiteFromCache(clientContext, clientContext.Site);
        clientContext.ExecuteQuery();

        this.WaitForSync();

        // Verify the TermSet is not running
        NavigationTermSet actualTermSet;
        ExceptionHandlingScope scope = new ExceptionHandlingScope(clientContext);
        using (scope.StartScope())
        {
            using (scope.StartTry())
            {
                actualTermSet = TaxonomyNavigation.GetTermSetForWeb(clientContext, clientContext.Web,
                    "GlobalNavigationTaxonomyProvider", includeInheritedSettings: true);
            }
            using (scope.StartCatch())
            {
            }
        }
        clientContext.ExecuteQuery();

        Assert.IsTrue(actualTermSet.ServerObjectIsNull.Value);

        // Assign the new settings
        webNavigationSettings = new WebNavigationSettings(clientContext, clientContext.Web);

        clientContext.Load(webNavigationSettings,
            w => w.GlobalNavigation,
            w => w.CurrentNavigation
        );
        clientContext.Load(termSet,
            ts => ts.TermStoreId,
            ts => ts.Id
        );
        clientContext.ExecuteQuery();

        // GlobalNavigation = top menu (aka "top nav")
        // CurrentNavigation = left menu (aka "quick launch")
        webNavigationSettings.GlobalNavigation.Source = StandardNavigationSource.TaxonomyProvider;
        webNavigationSettings.GlobalNavigation.TermStoreId = termSet.TermStoreId;
        webNavigationSettings.GlobalNavigation.TermSetId = termSet.Id;
        webNavigationSettings.Update(taxonomySession);

        TaxonomyNavigation.FlushSiteFromCache(clientContext, clientContext.Site);
        clientContext.ExecuteQuery();

        this.WaitForSync();

        actualTermSet = TaxonomyNavigation.GetTermSetForWeb(clientContext, clientContext.Web,
            "GlobalNavigationTaxonomyProvider", includeInheritedSettings: true);
        clientContext.Load(actualTermSet, ts => ts.Id);
        clientContext.ExecuteQuery();

        Assert.AreEqual(termSet.Id, actualTermSet.Id);
    }
Exemplo n.º 10
0
        /// <summary>
        /// Reset web navigation to its default configuration. Disabled the term set as navigation term set.
        /// </summary>
        /// <param name="web">The web</param>
        /// <param name="settings">The managed navigation settings. Set null if you want to keep the associated termset unchanged</param>
        public void ResetWebNavigationToDefault(SPWeb web, ManagedNavigationInfo settings)
        {
            var taxonomySession = new TaxonomySession(web.Site);
            if (taxonomySession.TermStores.Count > 0)
            {
                if (settings != null)
                {
                    // Disable the navigation flag on the the term set
                    var termStore = settings.TermSet.ResolveParentTermStore(taxonomySession);
                    var group = settings.TermSet.ResolveParentGroup(taxonomySession, web.Site);
                    var termSet = this.taxonomyService.GetTermSetFromGroup(termStore, group, settings.TermSet.Label);

                    string propertyValue;
                    if (termSet.CustomProperties.TryGetValue(SystemIsNavigationTermSet, out propertyValue))
                    {
                        termSet.DeleteCustomProperty(SystemIsNavigationTermSet);
                        termStore.CommitAll();
                    }
                }

                var navigationSettings = new WebNavigationSettings(web);
                navigationSettings.ResetToDefaults();
                navigationSettings.Update(taxonomySession);
            }
        }