private StructuralNavigation GetStructuralNavigation(Web web, WebNavigationSettings navigationSettings, Boolean currentNavigation)
        {
            // By default avoid removing existing nodes
            var result = new StructuralNavigation {
                RemoveExistingNodes = false
            };

            Microsoft.SharePoint.Client.NavigationNodeCollection sourceNodes = currentNavigation ?
                                                                               web.Navigation.QuickLaunch : web.Navigation.TopNavigationBar;

            web.Context.Load(web, w => w.ServerRelativeUrl);
            web.Context.Load(sourceNodes);
            web.Context.ExecuteQueryRetry();

            if (!sourceNodes.ServerObjectIsNull.Value)
            {
                result.NavigationNodes.AddRange(from n in sourceNodes.AsEnumerable()
                                                select n.ToDomainModelNavigationNode(web));
            }
            return(result);
        }
        private void ProvisionStructuralNavigation(Web web, StructuralNavigation structuralNavigation, TokenParser parser, bool currentNavigation, PnPMonitoredScope scope)
        {
            // Determine the target structural navigation
            var navigationType = currentNavigation ?
                                 Enums.NavigationType.QuickLaunch :
                                 Enums.NavigationType.TopNavigationBar;

            // Remove existing nodes, if requested
            if (structuralNavigation.RemoveExistingNodes)
            {
                web.DeleteAllNavigationNodes(navigationType);
            }

            // Provision root level nodes, and children recursively
            ProvisionStructuralNavigationNodes(
                web,
                parser,
                navigationType,
                structuralNavigation.NavigationNodes,
                scope
                );
        }
Beispiel #3
0
        private void ProvisionSearchNavigation(Web web, StructuralNavigation structuralNavigation, TokenParser parser, bool clearNavigation, PnPMonitoredScope scope)
        {
            if (structuralNavigation != null)
            {
                if (structuralNavigation.RemoveExistingNodes || clearNavigation)
                {
                    if (!structuralNavigation.RemoveExistingNodes && !ClearWarningShown)
                    {
                        WriteMessage("You chose to override the template value RemoveExistingNodes=\"false\" by specifying ClearNavigation", ProvisioningMessageType.Warning);
                        ClearWarningShown = true;
                    }
                    web.DeleteAllNavigationNodes(Enums.NavigationType.SearchNav);
                }

                if (structuralNavigation.NavigationNodes.Any())
                {
                    var searchNav = web.LoadSearchNavigation();
                    foreach (var node in structuralNavigation.NavigationNodes)
                    {
                        var navNode = searchNav.Add(new NavigationNodeCreationInformation()
                        {
                            Title      = parser.ParseString(node.Title),
                            IsExternal = node.IsExternal,
                            Url        = parser.ParseString(node.Url),
                        });

                        if (node.Title.ContainsResourceToken())
                        {
                            navNode.LocalizeNavigationNode(web, node.Title, parser, scope);
                        }

                        web.Context.ExecuteQueryRetry();
                    }
                }
            }
            ProvisionStructuralNavigation(web, structuralNavigation, parser, Enums.NavigationType.SearchNav, clearNavigation, scope);
        }
 private void ProvisionCurrentStructuralNavigation(Web web, StructuralNavigation structuralNavigation, TokenParser parser)
 {
     ProvisionStructuralNavigation(web, structuralNavigation, parser, true);
 }
 private void ProvisionGlobalStructuralNavigation(Web web, StructuralNavigation structuralNavigation, TokenParser parser)
 {
     ProvisionStructuralNavigation(web, structuralNavigation, parser, false);
 }
 private void ProvisionCurrentStructuralNavigation(Web web, StructuralNavigation structuralNavigation, TokenParser parser, bool clearNavigation, PnPMonitoredScope scope)
 {
     ProvisionStructuralNavigation(web, structuralNavigation, parser, true, clearNavigation, scope);
 }
Beispiel #7
0
 private void ProvisionCurrentStructuralNavigation(Web web, StructuralNavigation structuralNavigation, TokenParser parser, bool clearNavigation, PnPMonitoredScope scope)
 {
     ProvisionStructuralNavigation(web, structuralNavigation, parser, Enums.NavigationType.QuickLaunch, clearNavigation, scope);
 }
Beispiel #8
0
 private void ProvisionGlobalStructuralNavigation(Web web, StructuralNavigation structuralNavigation, TokenParser parser, bool clearNavigation, PnPMonitoredScope scope)
 {
     ProvisionStructuralNavigation(web, structuralNavigation, parser, Enums.NavigationType.TopNavigationBar, clearNavigation, scope);
 }
Beispiel #9
0
        public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
        {
            using (var scope = new PnPMonitoredScope(this.Name))
            {
                if (template.Navigation != null)
                {
                    if (!WebSupportsProvisionNavigation(web, template))
                    {
                        scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Navigation_Context_web_is_not_publishing);
                        return(parser);
                    }

                    // Check if this is not a noscript site as navigation features are not supported
                    bool isNoScriptSite = web.IsNoScriptSite();

                    // Retrieve the current web navigation settings
                    var navigationSettings = new WebNavigationSettings(web.Context, web);
                    web.Context.Load(navigationSettings, ns => ns.CurrentNavigation, ns => ns.GlobalNavigation);
                    web.Context.ExecuteQueryRetry();

                    navigationSettings.AddNewPagesToNavigation       = template.Navigation.AddNewPagesToNavigation;
                    navigationSettings.CreateFriendlyUrlsForNewPages = template.Navigation.CreateFriendlyUrlsForNewPages;

                    if (!isNoScriptSite)
                    {
                        navigationSettings.Update(TaxonomySession.GetTaxonomySession(web.Context));
                        web.Context.ExecuteQueryRetry();
                    }

                    if (template.Navigation.GlobalNavigation != null)
                    {
                        switch (template.Navigation.GlobalNavigation.NavigationType)
                        {
                        case GlobalNavigationType.Inherit:
                            navigationSettings.GlobalNavigation.Source = StandardNavigationSource.InheritFromParentWeb;
                            web.Navigation.UseShared = true;
                            break;

                        case GlobalNavigationType.Managed:
                            if (template.Navigation.GlobalNavigation.ManagedNavigation == null)
                            {
                                throw new ApplicationException(CoreResources.Provisioning_ObjectHandlers_Navigation_missing_global_managed_navigation);
                            }
                            navigationSettings.GlobalNavigation.Source      = StandardNavigationSource.TaxonomyProvider;
                            navigationSettings.GlobalNavigation.TermStoreId = Guid.Parse(parser.ParseString(template.Navigation.GlobalNavigation.ManagedNavigation.TermStoreId));
                            navigationSettings.GlobalNavigation.TermSetId   = Guid.Parse(parser.ParseString(template.Navigation.GlobalNavigation.ManagedNavigation.TermSetId));
                            web.Navigation.UseShared = false;
                            break;

                        case GlobalNavigationType.Structural:
                        default:
                            if (template.Navigation.GlobalNavigation.StructuralNavigation == null)
                            {
                                throw new ApplicationException(CoreResources.Provisioning_ObjectHandlers_Navigation_missing_global_structural_navigation);
                            }
                            navigationSettings.GlobalNavigation.Source = StandardNavigationSource.PortalProvider;
                            web.Navigation.UseShared = false;

                            break;
                        }

                        if (!isNoScriptSite)
                        {
                            navigationSettings.Update(TaxonomySession.GetTaxonomySession(web.Context));
                            web.Context.ExecuteQueryRetry();
                        }

                        // Need to set navigation nodes after update navigation settings
                        if (template.Navigation.GlobalNavigation.NavigationType == GlobalNavigationType.Structural)
                        {
                            ProvisionGlobalStructuralNavigation(web,
                                                                template.Navigation.GlobalNavigation.StructuralNavigation, parser, applyingInformation.ClearNavigation, scope);
                        }
                    }

                    if (template.Navigation.CurrentNavigation != null)
                    {
                        switch (template.Navigation.CurrentNavigation.NavigationType)
                        {
                        case CurrentNavigationType.Inherit:
                            navigationSettings.CurrentNavigation.Source = StandardNavigationSource.InheritFromParentWeb;
                            break;

                        case CurrentNavigationType.Managed:
                            if (template.Navigation.CurrentNavigation.ManagedNavigation == null)
                            {
                                throw new ApplicationException(CoreResources.Provisioning_ObjectHandlers_Navigation_missing_current_managed_navigation);
                            }
                            navigationSettings.CurrentNavigation.Source      = StandardNavigationSource.TaxonomyProvider;
                            navigationSettings.CurrentNavigation.TermStoreId = Guid.Parse(parser.ParseString(template.Navigation.CurrentNavigation.ManagedNavigation.TermStoreId));
                            navigationSettings.CurrentNavigation.TermSetId   = Guid.Parse(parser.ParseString(template.Navigation.CurrentNavigation.ManagedNavigation.TermSetId));
                            break;

                        case CurrentNavigationType.StructuralLocal:
                            if (!isNoScriptSite)
                            {
                                web.SetPropertyBagValue(NavigationShowSiblings, "false");
                            }
                            if (template.Navigation.CurrentNavigation.StructuralNavigation == null)
                            {
                                throw new ApplicationException(CoreResources.Provisioning_ObjectHandlers_Navigation_missing_current_structural_navigation);
                            }
                            navigationSettings.CurrentNavigation.Source = StandardNavigationSource.PortalProvider;

                            break;

                        case CurrentNavigationType.Structural:
                        default:
                            if (!isNoScriptSite)
                            {
                                web.SetPropertyBagValue(NavigationShowSiblings, "true");
                            }
                            if (template.Navigation.CurrentNavigation.StructuralNavigation == null)
                            {
                                throw new ApplicationException(CoreResources.Provisioning_ObjectHandlers_Navigation_missing_current_structural_navigation);
                            }
                            navigationSettings.CurrentNavigation.Source = StandardNavigationSource.PortalProvider;

                            break;
                        }

                        if (!isNoScriptSite)
                        {
                            navigationSettings.Update(TaxonomySession.GetTaxonomySession(web.Context));
                            web.Context.ExecuteQueryRetry();
                        }

                        // Need to set navigation nodes after update navigation settings
                        if (template.Navigation.CurrentNavigation.NavigationType == CurrentNavigationType.Structural ||
                            template.Navigation.CurrentNavigation.NavigationType == CurrentNavigationType.StructuralLocal)
                        {
                            ProvisionCurrentStructuralNavigation(web,
                                                                 template.Navigation.CurrentNavigation.StructuralNavigation, parser, applyingInformation.ClearNavigation, scope);
                        }
                    }

                    if (template.Navigation.SearchNavigation != null)
                    {
                        var structuralNavigation = new StructuralNavigation();
                        structuralNavigation.NavigationNodes.AddRange(template.Navigation.SearchNavigation.NavigationNodes);
                        structuralNavigation.RemoveExistingNodes = template.Navigation.SearchNavigation.RemoveExistingNodes;
                        ProvisionSearchNavigation(web, structuralNavigation, parser, applyingInformation.ClearNavigation, scope);
                    }
                }
            }

            return(parser);
        }
 private void ProvisionGlobalStructuralNavigation(Web web, StructuralNavigation structuralNavigation, TokenParser parser, PnPMonitoredScope scope)
 {
     ProvisionStructuralNavigation(web, structuralNavigation, parser, false, scope);
 }
        private StructuralNavigation GetStructuralNavigation(Web web, WebNavigationSettings navigationSettings, Boolean currentNavigation)
        {
            // By default avoid removing existing nodes
            var result = new StructuralNavigation { RemoveExistingNodes = false };
            Microsoft.SharePoint.Client.NavigationNodeCollection sourceNodes = currentNavigation ?
                web.Navigation.QuickLaunch : web.Navigation.TopNavigationBar;

            web.Context.Load(web, w => w.ServerRelativeUrl);
            web.Context.Load(sourceNodes);
            web.Context.ExecuteQueryRetry();

            result.NavigationNodes.AddRange(from n in sourceNodes.AsEnumerable()
                                            select n.ToDomainModelNavigationNode(web));

            return (result);
        }
        private void ProvisionStructuralNavigation(Web web, StructuralNavigation structuralNavigation, TokenParser parser, bool currentNavigation)
        {
            // Determine the target structural navigation
            var navigationType = currentNavigation ?
                Enums.NavigationType.QuickLaunch :
                Enums.NavigationType.TopNavigationBar;

            // Remove existing nodes, if requested
            if (structuralNavigation.RemoveExistingNodes)
            {
                web.DeleteAllNavigationNodes(navigationType);
            }

            // Provision root level nodes, and children recursively
            ProvisionStructuralNavigationNodes(
                web,
                parser,
                navigationType, 
                structuralNavigation.NavigationNodes
                );
        }
 private void ProvisionCurrentStructuralNavigation(Web web, StructuralNavigation structuralNavigation, TokenParser parser)
 {
     ProvisionStructuralNavigation(web, structuralNavigation, parser, true);
 }
 private void ProvisionGlobalStructuralNavigation(Web web, StructuralNavigation structuralNavigation, TokenParser parser)
 {
     ProvisionStructuralNavigation(web, structuralNavigation, parser, false);
 }