public object Resolve(object source, Dictionary <string, IResolver> resolvers = null, bool recursive = false)
        {
            Array result = null;

            Object modelSource = source as Model.StructuralNavigation;

            if (modelSource == null)
            {
                modelSource = source as Model.NavigationNode;
            }

            if (modelSource != null)
            {
                Model.NavigationNodeCollection sourceNodes = modelSource.GetPublicInstancePropertyValue("NavigationNodes") as Model.NavigationNodeCollection;
                if (sourceNodes != null)
                {
                    var navigationNodeTypeName = $"{PnPSerializationScope.Current?.BaseSchemaNamespace}.NavigationNode, {PnPSerializationScope.Current?.BaseSchemaAssemblyName}";
                    var navigationNodeType     = Type.GetType(navigationNodeTypeName, true);

                    result = Array.CreateInstance(navigationNodeType, sourceNodes.Count);

                    resolvers = new Dictionary <string, IResolver>
                    {
                        { $"{navigationNodeType}.NavigationNode1", new NavigationNodeFromModelToSchemaTypeResolver() }
                    };

                    for (Int32 c = 0; c < sourceNodes.Count; c++)
                    {
                        var targetNodeItem = Activator.CreateInstance(navigationNodeType);
                        PnPObjectsMapper.MapProperties(sourceNodes[c], targetNodeItem, resolvers, recursive);

                        result.SetValue(targetNodeItem, c);
                    }
                }
            }

            return(result);
        }
        private void ProvisionStructuralNavigationNodes(Web web, TokenParser parser, Enums.NavigationType navigationType, Model.NavigationNodeCollection nodes, String parentNodeTitle = null)
        {
            foreach (var node in nodes)
            {
                web.AddNavigationNode(
                    node.Title,
                    new Uri(parser.ParseString(node.Url), UriKind.RelativeOrAbsolute),
                    parentNodeTitle,
                    navigationType,
                    node.IsExternal);

                ProvisionStructuralNavigationNodes(
                    web,
                    parser,
                    navigationType,
                    node.NavigationNodes,
                    node.Title);
            }
        }
        private void ProvisionStructuralNavigationNodes(Web web, TokenParser parser, Enums.NavigationType navigationType, Model.NavigationNodeCollection nodes, PnPMonitoredScope scope, string parentNodeTitle = null)
        {
            foreach (var node in nodes)
            {
                var navNode = web.AddNavigationNode(
                    parser.ParseString(node.Title),
                    new Uri(parser.ParseString(node.Url), UriKind.RelativeOrAbsolute),
                    parser.ParseString(parentNodeTitle),
                    navigationType,
                    node.IsExternal);

                ProvisionStructuralNavigationNodes(
                    web,
                    parser,
                    navigationType,
                    node.NavigationNodes,
                    scope,
                    parser.ParseString(node.Title));

#if !SP2013
                if (node.Title.ContainsResourceToken())
                {
                    navNode.LocalizeNavigationNode(web, node.Title, parser, scope);
                }
#endif
            }
        }
Example #4
0
        private void ProvisionStructuralNavigationNodes(Web web, TokenParser parser, Enums.NavigationType navigationType, Model.NavigationNodeCollection nodes, PnPMonitoredScope scope, string parentNodeTitle = null, string l1ParentNodeTitle = null)
        {
            foreach (var node in nodes)
            {
                try
                {
                    string fileUrl = ReplaceFileUniqueToken(web, parser.ParseString(node.Url));

                    var navNode = web.AddNavigationNode(
                        parser.ParseString(node.Title),
                        new Uri(fileUrl, UriKind.RelativeOrAbsolute),
                        parser.ParseString(parentNodeTitle),
                        navigationType,
                        node.IsExternal,
                        l1ParentNodeTitle: l1ParentNodeTitle
                        );

#if !SP2013
                    if (node.Title.ContainsResourceToken())
                    {
                        navNode.LocalizeNavigationNode(web, node.Title, parser, scope);
                    }
#endif
                }
                catch (ServerException ex)
                {
                    // If the SharePoint link doesn't exist, provision it as external link
                    // when we provision as external link, the server side URL validation won't kick-in
                    // This handles the "no such file or url found" error

                    WriteMessage(String.Format(CoreResources.Provisioning_ObjectHandlers_Navigation_Link_Provisioning_Failed_Retry, node.Title), ProvisioningMessageType.Warning);

                    if (ex.ServerErrorCode == -2130247147)
                    {
                        try
                        {
                            string fileUrl = ReplaceFileUniqueToken(web, parser.ParseString(node.Url));
                            var    navNode = web.AddNavigationNode(
                                parser.ParseString(node.Title),
                                new Uri(fileUrl, UriKind.RelativeOrAbsolute),
                                parser.ParseString(parentNodeTitle),
                                navigationType,
                                true,
                                l1ParentNodeTitle: l1ParentNodeTitle
                                );
                        }
                        catch (Exception innerEx)
                        {
                            WriteMessage(String.Format(CoreResources.Provisioning_ObjectHandlers_Navigation_Link_Provisioning_Failed, innerEx.Message), ProvisioningMessageType.Warning);
                        }
                    }
                    else
                    {
                        WriteMessage(String.Format(CoreResources.Provisioning_ObjectHandlers_Navigation_Link_Provisioning_Failed, ex.Message), ProvisioningMessageType.Warning);
                    }
                }

                ProvisionStructuralNavigationNodes(
                    web,
                    parser,
                    navigationType,
                    node.NavigationNodes,
                    scope,
                    parser.ParseString(node.Title),
                    parentNodeTitle
                    );
            }
        }