Example #1
0
        private StructuralNavigation GetStructuralNavigation(Web web, WebNavigationSettings navigationSettings, Enums.NavigationType navigationType, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
        {
            // By default avoid removing existing nodes
            var result = new StructuralNavigation {
                RemoveExistingNodes = false
            };

            Microsoft.SharePoint.Client.NavigationNodeCollection sourceNodes = navigationType == Enums.NavigationType.QuickLaunch ?
                                                                               web.Navigation.QuickLaunch : navigationType == Enums.NavigationType.TopNavigationBar ? web.Navigation.TopNavigationBar : web.LoadSearchNavigation();

            if (sourceNodes == null)
            {
                return(result);
            }

            var clientContext = web.Context;

            clientContext.Load(web, w => w.ServerRelativeUrl, w => w.Language);
            clientContext.Load(sourceNodes);
            clientContext.ExecuteQueryRetry();
            var defaultCulture = new CultureInfo((int)web.Language);

            if (!sourceNodes.ServerObjectIsNull.Value)
            {
                result.NavigationNodes.AddRange(from n in sourceNodes.AsEnumerable()
                                                select n.ToDomainModelNavigationNode(web, creationInfo.PersistMultiLanguageResources, defaultCulture));

                if (creationInfo.PersistMultiLanguageResources)
                {
                    //need to get nodes and children for any other then default language
                    foreach (var language in template.SupportedUILanguages.Where(c => c.LCID != defaultCulture.LCID))
                    {
                        var currentCulture = new CultureInfo(language.LCID);
                        clientContext.Load(web, w => w.ServerRelativeUrl);
                        clientContext.Load(sourceNodes);
                        var acceptLanguage = clientContext.PendingRequest.RequestExecutor.WebRequest.Headers["Accept-Language"];
                        clientContext.PendingRequest.RequestExecutor.WebRequest.Headers["Accept-Language"] = currentCulture.Name;
                        clientContext.ExecuteQueryRetry();

                        if (!sourceNodes.ServerObjectIsNull.Value)
                        {
                            //we dont need to add to result - just extract Titles - to List as we need to
                            var alternateLang = (from n in sourceNodes.AsEnumerable()
                                                 select n.ToDomainModelNavigationNode(web, creationInfo.PersistMultiLanguageResources, currentCulture)).ToList();
                        }

                        clientContext.PendingRequest.RequestExecutor.WebRequest.Headers["Accept-Language"] = acceptLanguage;
                    }
                }
            }
            return(result);
        }
        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);
        }