public override void DeployModel(object modelHost, DefinitionBase model)
        {
            var host       = modelHost.WithAssertAndCast <WebModelHost>("modelHost", value => value.RequireNotNull());
            var definition = model.WithAssertAndCast <DeleteQuickLaunchNavigationNodesDefinition>("model", value => value.RequireNotNull());

            var spObject = host.HostWeb;
            var assert   = ServiceFactory.AssertService.NewAssert(definition, spObject);

            assert.ShouldBeEqual((p, s, d) =>
            {
                var srcProp = s.GetExpressionValue(m => m.NavigationNodes);

                // we should not find any matched
                // they should have been already deleted by the model handler
                var nodesCollection = GetNavigationNodeCollection(spObject);

                var matches = DeleteNavigationNodesService.FindMatches(
                    nodesCollection.OfType <SPNavigationNode>().ToArray(),
                    definition,
                    url =>
                {
                    return(ResolveTokenizedUrl(host, url));
                });

                var isValid = matches.Count == 0;

                return(new PropertyValidationResult
                {
                    Tag = p.Tag,
                    Src = srcProp,
                    Dst = null,
                    IsValid = isValid
                });
            });
        }
Ejemplo n.º 2
0
        private void DeployDefinition(object modelHost, WebModelHost typedModelHost, DeleteQuickLaunchNavigationNodesDefinition typedDefinition)
        {
            var web     = typedModelHost.HostWeb;
            var context = web.Context;

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioning,
                Object           = web,
                ObjectType       = typeof(Web),
                ObjectDefinition = typedDefinition,
                ModelHost        = modelHost
            });

            if (typedDefinition.NavigationNodes != null && typedDefinition.NavigationNodes.Any())
            {
                var nodesCollection = GetNavigationNodeCollection(web);

                context.Load(nodesCollection);
                context.ExecuteQueryWithTrace();

                DeleteNavigationNodesService.DeleteNodesByMatch(typedDefinition, nodesCollection, url =>
                {
                    return(ResolveTokenizedUrl(typedModelHost, url));
                });
            }

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = null,
                Model            = null,
                EventType        = ModelEventType.OnProvisioned,
                Object           = web,
                ObjectType       = typeof(Web),
                ObjectDefinition = typedDefinition,
                ModelHost        = modelHost
            });
        }