protected virtual NavigationNode LookupNavigationNode(NavigationNodeCollection nodes,
                                                              NavigationNodeDefinitionBase definition)
        {
            var context = nodes.Context;

            context.Load(nodes);
            context.ExecuteQueryWithTrace();

            var currentNode = nodes
                              .OfType <NavigationNode>()
                              .FirstOrDefault(n => !string.IsNullOrEmpty(n.Title) && (n.Title.ToUpper() == definition.Title.ToUpper()));

            if (currentNode == null)
            {
                var url = ResolveTokenizedUrl(CurrentModelHost, definition);

                url = HttpUtility.UrlKeyValueDecode(url);

                currentNode = nodes
                              .OfType <NavigationNode>()
                              .FirstOrDefault(n => !string.IsNullOrEmpty(n.Url) && (n.Url.ToUpper().EndsWith(url.ToUpper())));
            }

            return(currentNode);
        }
Exemple #2
0
 protected virtual void ProcessLocalization(NavigationNode obj, NavigationNodeDefinitionBase definition)
 {
     ProcessGenericLocalization(obj, new Dictionary <string, List <ValueForUICulture> >
     {
         { "TitleResource", definition.TitleResource }
     });
 }
        private NavigationNode EnsureNavigationNode(NavigationNodeModelHost navigationNodeModelHost,
                                                    NavigationNodeDefinitionBase quickLaunchNode)
        {
            var navigationNode = navigationNodeModelHost.HostNavigationNode;
            var quickLaunch    = navigationNode.Children;

            var context = navigationNodeModelHost.HostWeb.Context;

            context.Load(quickLaunch);
            context.ExecuteQueryWithTrace();

            var existingNode = LookupNavigationNode(quickLaunch, quickLaunchNode);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = existingNode,
                ObjectType       = typeof(NavigationNode),
                ObjectDefinition = quickLaunchNode,
                ModelHost        = navigationNodeModelHost
            });

            if (existingNode == null)
            {
                existingNode = quickLaunch.Add(new NavigationNodeCreationInformation
                {
                    Title      = quickLaunchNode.Title,
                    IsExternal = quickLaunchNode.IsExternal,
                    Url        = ResolveTokenizedUrl(navigationNodeModelHost.HostClientContext, quickLaunchNode),
                    AsLastNode = true
                });

                context.ExecuteQueryWithTrace();
            }

            existingNode.Title     = quickLaunchNode.Title;
            existingNode.Url       = ResolveTokenizedUrl(navigationNodeModelHost.HostClientContext, quickLaunchNode);
            existingNode.IsVisible = quickLaunchNode.IsVisible;

            ProcessLocalization(existingNode, quickLaunchNode);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = existingNode,
                ObjectType       = typeof(NavigationNode),
                ObjectDefinition = quickLaunchNode,
                ModelHost        = navigationNodeModelHost
            });

            existingNode.Update();

            context.ExecuteQueryWithTrace();

            return(existingNode);
        }
        protected NavigationNode GetRootNavigationNode(
            WebModelHost webModelHost,
            NavigationNodeDefinitionBase quickLaunchModel)
        {
            NavigationNodeCollection quickLaunch = null;
            var result = GetRootNavigationNode(webModelHost, quickLaunchModel, out quickLaunch);

            return(result);
        }
 protected virtual void ProcessLocalization(SPNavigationNode obj, NavigationNodeDefinitionBase definition)
 {
     if (definition.TitleResource.Any())
     {
         foreach (var locValue in definition.TitleResource)
         {
             LocalizationService.ProcessUserResource(obj, obj.TitleResource, locValue);
         }
     }
 }
        private SPNavigationNode EnsureRootNavigationNode(WebModelHost webModelHost, NavigationNodeDefinitionBase rootNode)
        {
            var web = webModelHost.HostWeb;

            var quickLaunch  = GetNavigationNodeCollection(web);
            var existingNode = LookupNavigationNode(quickLaunch, rootNode);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = existingNode,
                ObjectType       = typeof(SPNavigationNode),
                ObjectDefinition = rootNode,
                ModelHost        = webModelHost
            });

            if (existingNode == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new navigation node");

                existingNode = new SPNavigationNode(rootNode.Title, ResolveTokenizedUrl(webModelHost, rootNode), rootNode.IsExternal);
                quickLaunch.AddAsLast(existingNode);
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing navigation node");
            }

            existingNode.Title     = rootNode.Title;
            existingNode.Url       = ResolveTokenizedUrl(webModelHost, rootNode);
            existingNode.IsVisible = rootNode.IsVisible;

            ProcessProperties(existingNode, rootNode);
            ProcessLocalization(existingNode, rootNode);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = existingNode,
                ObjectType       = typeof(SPNavigationNode),
                ObjectDefinition = rootNode,
                ModelHost        = webModelHost
            });

            existingNode.Update();

            return(existingNode);
        }
        protected SPNavigationNode LookupNodeForHost(object modelHost, NavigationNodeDefinitionBase definition)
        {
            if (modelHost is WebModelHost)
            {
                return(LookupNavigationNode(GetNavigationNodeCollection((modelHost as WebModelHost).HostWeb), definition));
            }
            else if (modelHost is SPNavigationNode)
            {
                return(LookupNavigationNode((modelHost as SPNavigationNode).Children, definition));
            }

            throw new ArgumentException("modelHost needs to be SPWeb");
        }
        protected NavigationNode GetNavigationNode(
            NavigationNodeModelHost navigationNodeModelHost,
            NavigationNodeDefinitionBase quickLaunchNode)
        {
            var navigationNode = navigationNodeModelHost.HostNavigationNode;
            var quickLaunch    = navigationNode.Children;

            var context = navigationNodeModelHost.HostWeb.Context;

            context.Load(quickLaunch);
            context.ExecuteQueryWithTrace();

            var existingNode = LookupNavigationNode(quickLaunch, quickLaunchNode);

            return(existingNode);
        }
        protected virtual string ResolveTokenizedUrl(WebModelHost webModelHost, NavigationNodeDefinitionBase rootNode)
        {
            var urlValue = rootNode.Url;

            TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original Url: [{0}]", urlValue);

            var newUrlValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
            {
                Value   = urlValue,
                Context = webModelHost.HostWeb
            }).Value;

            TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced Url: [{0}]", newUrlValue);

            return(newUrlValue);
        }
 protected virtual void ProcessProperties(SPNavigationNode existingNode, NavigationNodeDefinitionBase quickLaunchNode)
 {
     if (quickLaunchNode.Properties != null && quickLaunchNode.Properties.Any())
     {
         foreach (var prop in quickLaunchNode.Properties)
         {
             if (existingNode.Properties.ContainsKey(prop.Key))
             {
                 existingNode.Properties[prop.Key] = prop.Value;
             }
             else
             {
                 existingNode.Properties.Add(prop.Key, prop.Value);
             }
         }
     }
 }
        protected NavigationNode GetRootNavigationNode(
            WebModelHost webModelHost,
            NavigationNodeDefinitionBase navigationNodeModel, out NavigationNodeCollection rootNavigationNodes)
        {
            var web     = webModelHost.HostWeb;
            var context = webModelHost.HostWeb.Context;

            rootNavigationNodes = GetNavigationNodeCollection(web);

            context.Load(rootNavigationNodes);
            context.ExecuteQueryWithTrace();

            // TODO, crazy URL matching to find 'resolved URL'

            var existingNode = rootNavigationNodes.OfType <NavigationNode>()
                               .FirstOrDefault(n => n.Url.ToUpper().EndsWith(navigationNodeModel.Url.ToUpper()));

            return(existingNode);
        }
        protected virtual SPNavigationNode LookupNavigationNode(SPNavigationNodeCollection nodes, NavigationNodeDefinitionBase definition)
        {
            var currentNode = nodes
                              .OfType <SPNavigationNode>()
                              .FirstOrDefault(n => !string.IsNullOrEmpty(n.Title) && (n.Title.ToUpper() == definition.Title.ToUpper()));

            if (currentNode == null)
            {
                var url = ResolveTokenizedUrl(CurrentWebModelHost, definition);

                currentNode = nodes
                              .OfType <SPNavigationNode>()
                              .FirstOrDefault(n => !string.IsNullOrEmpty(n.Url) && (n.Url.ToUpper().EndsWith(url.ToUpper())));
            }

            return(currentNode);
        }
        protected virtual NavigationNode LookupNavigationNode(NavigationNodeCollection nodes, NavigationNodeDefinitionBase definition)
        {
            var context = nodes.Context;

            context.Load(nodes);
            context.ExecuteQueryWithTrace();

            var currentNode = nodes
                              .OfType <NavigationNode>()
                              .FirstOrDefault(n => !string.IsNullOrEmpty(n.Title) && (n.Title.ToUpper() == definition.Title.ToUpper()));

            if (currentNode == null)
            {
                currentNode = nodes
                              .OfType <NavigationNode>()
                              .FirstOrDefault(n => !string.IsNullOrEmpty(n.Url) && (n.Url.ToUpper().EndsWith(definition.Url.ToUpper())));
            }

            return(currentNode);
        }
        private NavigationNode EnsureRootNavigationNode(
            WebModelHost webModelHost,
            NavigationNodeDefinitionBase navigationNodeModel)
        {
            NavigationNodeCollection quickLaunch = null;

            var context = webModelHost.HostWeb.Context;

            var existingNode = GetRootNavigationNode(webModelHost, navigationNodeModel, out quickLaunch);
            var previousNode = quickLaunch.Count > 0 ? quickLaunch.Last() : null;

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = existingNode,
                ObjectType       = typeof(NavigationNode),
                ObjectDefinition = navigationNodeModel,
                ModelHost        = webModelHost
            });

            if (existingNode == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new navigation node");

                existingNode = quickLaunch.Add(new NavigationNodeCreationInformation
                {
                    Title        = navigationNodeModel.Title,
                    IsExternal   = navigationNodeModel.IsExternal,
                    Url          = navigationNodeModel.Url,
                    PreviousNode = previousNode
                });

                context.ExecuteQueryWithTrace();
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing navigation node");
            }

            existingNode.Title     = navigationNodeModel.Title;
            existingNode.Url       = navigationNodeModel.Url;
            existingNode.IsVisible = navigationNodeModel.IsVisible;

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = existingNode,
                ObjectType       = typeof(NavigationNode),
                ObjectDefinition = navigationNodeModel,
                ModelHost        = webModelHost
            });

            existingNode.Update();

            context.ExecuteQueryWithTrace();

            return(existingNode);
        }
        private SPNavigationNode EnsurehNavigationNode(SPNavigationNode navigationNode, NavigationNodeDefinitionBase quickLaunchNode)
        {
            var topNavigationNode = navigationNode.Children;
            var existingNode      = LookupNavigationNode(topNavigationNode, quickLaunchNode);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = existingNode,
                ObjectType       = typeof(SPNavigationNode),
                ObjectDefinition = quickLaunchNode,
                ModelHost        = navigationNode
            });

            if (existingNode == null)
            {
                existingNode = new SPNavigationNode(quickLaunchNode.Title, ResolveTokenizedUrl(CurrentWebModelHost, quickLaunchNode), quickLaunchNode.IsExternal);
                topNavigationNode.AddAsLast(existingNode);
            }

            existingNode.Title     = quickLaunchNode.Title;
            existingNode.Url       = ResolveTokenizedUrl(CurrentWebModelHost, quickLaunchNode);
            existingNode.IsVisible = quickLaunchNode.IsVisible;

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = existingNode,
                ObjectType       = typeof(SPNavigationNode),
                ObjectDefinition = quickLaunchNode,
                ModelHost        = navigationNode
            });

            existingNode.Update();

            return(existingNode);
        }
 protected virtual string ResolveTokenizedUrl(WebModelHost webModelHost, NavigationNodeDefinitionBase rootNode)
 {
     return(ResolveTokenizedUrl(webModelHost, rootNode.Url));
 }
 protected virtual string ResolveTokenizedUrl(CSOMModelHostBase context, NavigationNodeDefinitionBase rootNode)
 {
     return(ResolveTokenizedUrl(context, rootNode.Url));
 }