Example #1
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);
            }
        }
    }
Example #2
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);
    }