Example #1
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var folderHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull());
            var moduleFile = model.WithAssertAndCast <ModuleFileDefinition>("model", value => value.RequireNotNull());

            var folder = folderHost.CurrentLibraryFolder;
            var file   = GetFile(folderHost, moduleFile);

            if (childModelType == typeof(WebPartDefinition))
            {
                using (var webPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
                {
                    var webpartPageHost = new WebpartPageModelHost
                    {
                        HostFile                = file,
                        PageListItem            = file.Item,
                        SPLimitedWebPartManager = webPartManager
                    };

                    action(webpartPageHost);
                }
            }
            else
            {
                action(file);
            }
        }
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var folderModelHost  = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull());
            var webpartPageModel = model.WithAssertAndCast <WebPartPageDefinition>("model", value => value.RequireNotNull());

            //var list = listModelHost.HostList;
            var folder = folderModelHost.CurrentLibraryFolder;

            var targetFile = GetOrCreateNewWebPartFile(modelHost, folder, webpartPageModel);

            using (var webPartManager = targetFile.GetLimitedWebPartManager(PersonalizationScope.Shared))
            {
                var webpartPageHost = new WebpartPageModelHost
                {
                    HostFile                = targetFile,
                    PageListItem            = targetFile.Item,
                    SPLimitedWebPartManager = webPartManager
                };

                action(webpartPageHost);
            }
        }
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var folderModelHost  = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull());
            var webpartPageModel = model.WithAssertAndCast <WebPartPageDefinition>("model", value => value.RequireNotNull());

            //var list = listModelHost.HostList;
            var folder = folderModelHost.CurrentLibraryFolder;

            // Web part provision seems to put only the last web part on the page #869
            // https://github.com/SubPointSolutions/spmeta2/issues/869
            var targetFile = FindWebPartPage(folder, webpartPageModel);

            //var targetFile = GetOrCreateNewWebPartFile(modelHost, folder, webpartPageModel);

            using (var webPartManager = targetFile.GetLimitedWebPartManager(PersonalizationScope.Shared))
            {
                var webpartPageHost = new WebpartPageModelHost
                {
                    HostFile                = targetFile,
                    PageListItem            = targetFile.Item,
                    SPLimitedWebPartManager = webPartManager
                };

                action(webpartPageHost);
            }
        }
Example #4
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;

            var listModelHost        = modelHost.WithAssertAndCast <ListModelHost>("modelHost", value => value.RequireNotNull());
            var contentTypeLinkModel = model.WithAssertAndCast <ContentTypeLinkDefinition>("model", value => value.RequireNotNull());

            var list    = listModelHost.HostList;
            var context = list.Context;

            context.Load(list, l => l.ContentTypes);
            context.ExecuteQueryWithTrace();

            var listContentType = FindListContentType(list, contentTypeLinkModel);

            action(new ModelHostContext
            {
                Site        = listModelHost.HostSite,
                Web         = listModelHost.HostWeb,
                ContentType = listContentType
            });

            listContentType.Update(false);
            context.ExecuteQueryWithTrace();
        }
Example #5
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var siteModelHost  = modelHost.WithAssertAndCast <SiteModelHost>("model", value => value.RequireNotNull());
            var termStoreModel = model.WithAssertAndCast <TaxonomyTermStoreDefinition>("model", value => value.RequireNotNull());

            var termStore = FindTermStore(siteModelHost, termStoreModel);

            var termStoreModelHost = ModelHostBase.Inherit <TermStoreModelHost>(siteModelHost, context =>
            {
                context.HostTermStore = termStore;
            });

            action(termStoreModelHost);

            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Calling termStore.CommitAll()");

            termStore.CommitAll();
            termStore.Context.ExecuteQueryWithTrace();
        }
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var quickLaunchNode = model as NavigationNodeDefinitionBase;

            if (modelHost is WebModelHost)
            {
                CurrentWebModelHost = modelHost as WebModelHost;

                var webModelHost = modelHost.WithAssertAndCast <WebModelHost>("modelHost", value => value.RequireNotNull());
                var currentNode  = EnsureRootNavigationNode(webModelHost, quickLaunchNode);

                action(currentNode);
            }
            else if (modelHost is SPNavigationNode)
            {
                var node        = modelHost as SPNavigationNode;
                var currentNode = EnsurehNavigationNode(node, quickLaunchNode);

                action(currentNode);
            }
            else
            {
                action(modelHost);
            }
        }
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost as ModelHostBase;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;

            var listModelHost        = modelHost.WithAssertAndCast <ListModelHost>("modelHost", value => value.RequireNotNull());
            var contentTypeLinkModel = model.WithAssertAndCast <ContentTypeLinkDefinition>("model", value => value.RequireNotNull());

            var list = listModelHost.HostList;

            var contentType = list.ContentTypes[contentTypeLinkModel.ContentTypeName];

            var contentTypeLinkHost = ModelHostBase.Inherit <ContentTypeLinkModelHost>(modelHost, host =>
            {
                host.HostContentType = contentType;
                host.HostList        = list;
            });

            action(contentTypeLinkHost);

            if (contentTypeLinkHost.ShouldUpdateHost)
            {
                if (!contentType.ReadOnly)
                {
                    contentType.Update(false);
                }
            }
        }
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;

            var storeModelHost = modelHost.WithAssertAndCast <TermStoreModelHost>("modelHost", value => value.RequireNotNull());
            var groupModel     = model.WithAssertAndCast <TaxonomyTermGroupDefinition>("model", value => value.RequireNotNull());

            var context = storeModelHost.HostClientContext;

            var termStore    = storeModelHost.HostTermStore;
            var currentGroup = FindGroup(storeModelHost, groupModel);

            if (currentGroup == null && IsSharePointOnlineContext(context))
            {
                TryRetryService.TryWithRetry(() =>
                {
                    currentGroup = FindGroup(storeModelHost, groupModel);
                    return(currentGroup != null);
                });
            }

            if (currentGroup == null)
            {
                throw new SPMeta2Exception(string.Format("Cannot find a taxonomy group after provision"));
            }

            action(ModelHostBase.Inherit <TermGroupModelHost>(storeModelHost, host =>
            {
                host.HostTermStore = termStore;
                host.HostGroup     = currentGroup;
            }));
        }
Example #9
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;

            var webApplicationDefinition = model.WithAssertAndCast <WebApplicationDefinition>("model", value => value.RequireNotNull());

            if (modelHost is WebApplicationModelHost)
            {
                base.WithResolvingModelHost(modelHostContext);
                return;
            }

            var farmModelHost = modelHost.WithAssertAndCast <FarmModelHost>("modelHost", value => value.RequireNotNull());

            var webApps        = SPWebService.ContentService.WebApplications;
            var existingWebApp = FindWebApplication(webApplicationDefinition, webApps);

            if (existingWebApp == null)
            {
                throw new SPMeta2Exception(string.Format(
                                               "Cannot find web aplication by definition:[]",
                                               webApplicationDefinition));
            }

            var webAppModelHost = ModelHostBase.Inherit <WebApplicationModelHost>(farmModelHost, h =>
            {
                h.HostWebApplication = existingWebApp;
            });

            action(webAppModelHost);
        }
Example #10
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var securableObject = ExtractSecurableObject(modelHost);

            if (securableObject is SPSecurableObject)
            {
                var securityGroupLinkModel = model as SecurityGroupLinkDefinition;
                if (securityGroupLinkModel == null)
                {
                    throw new ArgumentException("model has to be SecurityGroupDefinition");
                }

                var web           = ExtractWeb(modelHost);
                var securityGroup = ResolveSecurityGroup(web, securityGroupLinkModel);

                var newModelHost = new SecurityGroupModelHost
                {
                    SecurableObject = securableObject as SPSecurableObject,
                    SecurityGroup   = securityGroup
                };

                action(newModelHost);
            }
            else
            {
                action(modelHost);
            }
        }
Example #11
0
 /// <summary>
 /// Resolves a new model host per particular child definition type.
 /// </summary>
 /// <param name="context"></param>
 public virtual void WithResolvingModelHost(ModelHostResolveContext context)
 {
     WithResolvingModelHost(
         context.ModelHost,
         context.Model,
         context.ChildModelType,
         context.Action);
 }
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;

            var folderModelHost = modelHost as FolderModelHost;
            var definition      = model as PublishingPageDefinition;



            Folder folder = folderModelHost.CurrentListFolder;

            if (folder != null && definition != null)
            {
                var context     = folder.Context;
                var currentPage = GetCurrentPage(folderModelHost.CurrentList, folder, GetSafePageFileName(definition));

                if (typeof(WebPartDefinitionBase).IsAssignableFrom(childModelType) ||
                    childModelType == typeof(DeleteWebPartsDefinition))
                {
                    var listItemHost = ModelHostBase.Inherit <ListItemModelHost>(folderModelHost, itemHost =>
                    {
                        itemHost.HostFile = currentPage;
                        itemHost.HostList = folderModelHost.CurrentList;
                    });

                    action(listItemHost);

                    //currentListItem.Update();
                }
                else if (typeof(BreakRoleInheritanceDefinition).IsAssignableFrom(childModelType) ||
                         typeof(SecurityGroupLinkDefinition).IsAssignableFrom(childModelType))
                {
                    var currentListItem = currentPage.ListItemAllFields;
                    context.Load(currentListItem);
                    context.ExecuteQueryWithTrace();

                    var listItemHost = ModelHostBase.Inherit <ListItemModelHost>(folderModelHost, itemHost =>
                    {
                        itemHost.HostListItem = currentListItem;
                    });

                    action(listItemHost);
                }
                else
                {
                    action(currentPage);
                }

                //context.ExecuteQueryWithTrace();
            }
            else
            {
                action(modelHost);
            }
        }
Example #13
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;

            var parentWeb         = ExtractWeb(modelHost);
            var hostclientContext = ExtractHostClientContext(modelHost);
            var hostSite          = ExtractHostSite(modelHost);

            var webModel = model.WithAssertAndCast <WebDefinition>("model", value => value.RequireNotNull());

            var context = parentWeb.Context;

            context.Load(parentWeb, w => w.Url);
            //context.Load(parentWeb, w => w.RootFolder);
            context.Load(parentWeb, w => w.ServerRelativeUrl);
            context.ExecuteQueryWithTrace();

            var currentWebUrl = GetCurrentWebUrl(context, parentWeb, webModel);
            var currentWeb    = GetExistingWeb(hostSite, parentWeb, currentWebUrl);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = modelHostContext.ModelNode,
                Model            = null,
                EventType        = ModelEventType.OnModelHostResolving,
                Object           = parentWeb,
                ObjectType       = typeof(Web),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            var tmpWebModelHost = new WebModelHost
            {
                HostClientContext = hostclientContext,
                HostSite          = hostSite,
                HostWeb           = currentWeb
            };

            action(tmpWebModelHost);

            InvokeOnModelEvent(this, new ModelEventArgs
            {
                CurrentModelNode = modelHostContext.ModelNode,
                Model            = null,
                EventType        = ModelEventType.OnModelHostResolved,
                Object           = parentWeb,
                ObjectType       = typeof(Web),
                ObjectDefinition = model,
                ModelHost        = modelHost
            });

            currentWeb.Update();
            context.ExecuteQueryWithTrace();
        }
Example #14
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var folderHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull());
            var moduleFile = model.WithAssertAndCast <ModuleFileDefinition>("model", value => value.RequireNotNull());

            var web     = folderHost.CurrentWeb;
            var file    = ProcessFile(folderHost, moduleFile);
            var context = file.Context;

            if (childModelType == typeof(ListItemFieldValueDefinition))
            {
                var fileListItem = file.ListItemAllFields;

                context.Load(fileListItem, i => i.Id, i => i.ParentList);
                context.ExecuteQueryWithTrace();

                var list = fileListItem.ParentList;
                var item = list.GetItemById(fileListItem.Id);

                context.ExecuteQueryWithTrace();

                var listItemPropertyHost = new ListItemModelHost
                {
                    HostListItem = item
                };

                action(listItemPropertyHost);

                item.Update();

                context.ExecuteQueryWithTrace();
            }
            else if (childModelType == typeof(PropertyDefinition))
            {
                var propModelHost = new PropertyModelHost
                {
                    CurrentFile = file
                };

                action(propModelHost);

                context.ExecuteQueryWithTrace();
            }
            else
            {
                action(file);

                context.ExecuteQueryWithTrace();
            }
        }
Example #15
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var siteModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull());

            action(siteModelHost);
        }
Example #16
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var folderModelHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull());
            var wikiPageModel   = model.WithAssertAndCast <WikiPageDefinition>("model", value => value.RequireNotNull());

            var web    = folderModelHost.CurrentList.ParentWeb;
            var folder = folderModelHost.CurrentListFolder;

            var currentPage = GetWikiPageFile(web, folder, wikiPageModel);

            var context = folder.Context;

            if (typeof(WebPartDefinitionBase).IsAssignableFrom(childModelType) ||
                childModelType == typeof(DeleteWebPartsDefinition))
            {
                var listItemHost = ModelHostBase.Inherit <ListItemModelHost>(folderModelHost, itemHost =>
                {
                    itemHost.HostFolder   = folderModelHost.CurrentListFolder;
                    itemHost.HostListItem = folderModelHost.CurrentListItem;
                    itemHost.HostFile     = currentPage;
                    itemHost.HostList     = folderModelHost.CurrentList;
                });

                action(listItemHost);
            }
            else if (
                typeof(BreakRoleInheritanceDefinition).IsAssignableFrom(childModelType) ||
                typeof(SecurityGroupLinkDefinition).IsAssignableFrom(childModelType))
            {
                var listItemHost = ModelHostBase.Inherit <ListItemModelHost>(folderModelHost, itemHost =>
                {
                    var currentListItem = currentPage.ListItemAllFields;
                    context.Load(currentListItem);
                    context.ExecuteQueryWithTrace();

                    itemHost.HostListItem = currentListItem;
                });

                action(listItemHost);
            }
            else
            {
                action(currentPage);
            }

            context.ExecuteQueryWithTrace();
        }
        public override void WithResolvingModelHost(ModelHostResolveContext context)
        {
            var farmAppModelHost = context.ModelHost.WithAssertAndCast <FarmModelHost>("modelHost", value => value.RequireNotNull());
            var definition       = context.Model.WithAssertAndCast <SecureStoreApplicationDefinition>("model", value => value.RequireNotNull());

            var currentObject = GetCurrentSecureStoreApplication(farmAppModelHost.HostFarm, definition);

            context.Action(new SecureStoreApplicationModelHost
            {
                HostFarm        = farmAppModelHost.HostFarm,
                HostSecureStore = currentObject
            });
        }
Example #18
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var folderModelHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull());
            var folderModel     = model.WithAssertAndCast <FolderDefinition>("model", value => value.RequireNotNull());

            if (folderModelHost.CurrentList != null && folderModelHost.CurrentList.BaseType == BaseType.DocumentLibrary)
            {
                var currentFolder = EnsureLibraryFolder(folderModelHost, folderModel);

                var newContext = ModelHostBase.Inherit <FolderModelHost>(folderModelHost, c =>
                {
                    c.CurrentList       = folderModelHost.CurrentList;
                    c.CurrentListFolder = currentFolder;
                    c.CurrentWeb        = folderModelHost.CurrentWeb;
                });

                action(newContext);

                currentFolder.Update();
                currentFolder.Context.ExecuteQueryWithTrace();
            }
            else if (folderModelHost.CurrentList != null && folderModelHost.CurrentList.BaseType != BaseType.DocumentLibrary)
            {
                var currentListItem = EnsureListFolder(folderModelHost, folderModel);

                var newContext = ModelHostBase.Inherit <FolderModelHost>(folderModelHost, c =>
                {
                    c.CurrentList     = folderModelHost.CurrentList;
                    c.CurrentListItem = currentListItem;
                    c.CurrentWeb      = folderModelHost.CurrentWeb;
                });

                action(newContext);

                // should be fine for 35 too, that's a parent update
#if !NET35
                currentListItem.Folder.Update();
                currentListItem.Context.ExecuteQueryWithTrace();
#endif
            }
            else
            {
                throw new NotImplementedException("model host is unklnown");
            }
        }
Example #19
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var definition = model.WithAssertAndCast <TaxonomyTermDefinition>("model", value => value.RequireNotNull());

            Term      currentTerm = null;
            Group     group       = null;
            TermSet   termSet     = null;
            TermStore termStore   = null;
            SPSite    hostSite    = null;

            if (modelHost is TermModelHost)
            {
                var h = (modelHost as TermModelHost);

                group     = h.HostGroup;
                termSet   = h.HostTermSet;
                termStore = h.HostTermStore;
                hostSite  = h.HostSite;

                currentTerm = FindTermInTerm(h.HostTerm, definition);
            }
            else if (modelHost is TermSetModelHost)
            {
                var h = (modelHost as TermSetModelHost);

                termStore = h.HostTermStore;
                group     = h.HostGroup;
                termSet   = h.HostTermSet;
                hostSite  = h.HostSite;

                currentTerm = FindTermInTermSet(h.HostTermSet, definition);
            }

            action(new TermModelHost
            {
                HostGroup     = group,
                HostTermSet   = termSet,
                HostTerm      = currentTerm,
                HostTermStore = termStore,
                HostSite      = hostSite
            });

            termStore.CommitAll();
        }
Example #20
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;

            var web = ExtractWeb(modelHost);

            var site = web.Site;
            var contentTypeDefinition = model as ContentTypeDefinition;

            if (site != null && contentTypeDefinition != null)
            {
                var contentTypeId = new SPContentTypeId(contentTypeDefinition.GetContentTypeId());

                // SPBug, it has to be new SPWeb for every content type operation inside feature event handler
                using (var tmpRootWeb = site.OpenWeb(web.ID))
                {
                    var targetContentType = tmpRootWeb.ContentTypes[contentTypeId];

                    if (childModelType == typeof(ModuleFileDefinition))
                    {
                        action(new FolderModelHost
                        {
                            CurrentContentType       = targetContentType,
                            CurrentContentTypeFolder = targetContentType.ResourceFolder
                        });
                    }
                    else
                    {
                        action(ModelHostBase.Inherit <ContentTypeModelHost>(modelHost as ModelHostBase, host =>
                        {
                            host.HostContentType = targetContentType;
                        }));
                    }

                    if (!targetContentType.ReadOnly)
                    {
                        targetContentType.Update(true);
                    }

                    tmpRootWeb.Update();
                }
            }
            else
            {
                action(modelHost);
            }
        }
Example #21
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost as CSOMModelHostBase;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;

            var listModelHost        = modelHost.WithAssertAndCast <ListModelHost>("modelHost", value => value.RequireNotNull());
            var contentTypeLinkModel = model.WithAssertAndCast <ContentTypeLinkDefinition>("model", value => value.RequireNotNull());

            var list    = listModelHost.HostList;
            var context = list.Context;

            //context.Load(list, l => l.ContentTypes);
            context.Load(list, l => l.ContentTypes.Include(
                             ct => ct.Id,
                             ct => ct.Name,
                             ct => ct.ReadOnly,

                             ct => ct.Parent.Id
                             ));

            context.ExecuteQueryWithTrace();

            var contentType = FindListContentType(list, contentTypeLinkModel);

            var contentTypeLinkHost = ModelHostBase.Inherit <ContentTypeLinkModelHost>(modelHost, host =>
            {
                host.HostContentType  = contentType;
                host.HostList         = list;
                host.ShouldUpdateHost = true;
            });

            action(contentTypeLinkHost);

            if (contentTypeLinkHost.ShouldUpdateHost)
            {
                if (!contentType.ReadOnly)
                {
                    contentType.Update(false);
                }
            }

            context.ExecuteQueryWithTrace();
        }
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;

            var listModelHost        = modelHost.WithAssertAndCast <ListModelHost>("modelHost", value => value.RequireNotNull());
            var contentTypeLinkModel = model.WithAssertAndCast <ContentTypeLinkDefinition>("model", value => value.RequireNotNull());

            var list = listModelHost.HostList;

            var contentType = list.ContentTypes[contentTypeLinkModel.ContentTypeName];

            action(contentType);

            contentType.Update(false);
        }
Example #23
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var   webDefinition = model as WebDefinition;
            SPWeb parentWeb     = null;

            if (modelHost is SiteModelHost)
            {
                parentWeb = (modelHost as SiteModelHost).HostSite.RootWeb;
            }

            if (modelHost is WebModelHost)
            {
                parentWeb = (modelHost as WebModelHost).HostWeb;
            }

            using (var currentWeb = GetOrCreateWeb(parentWeb, webDefinition, false))
            {
                if (childModelType == typeof(ModuleFileDefinition))
                {
                    var folderModelHost = new FolderModelHost
                    {
                        CurrentWeb       = currentWeb,
                        CurrentWebFolder = currentWeb.RootFolder,
                    };

                    action(folderModelHost);
                }
                else
                {
                    action(new WebModelHost
                    {
                        HostWeb = currentWeb
                    });
                }

                currentWeb.Update();
            }
        }
Example #24
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var definition = model.WithAssertAndCast <RootWebDefinition>("model", value => value.RequireNotNull());

            var currentObject = GetCurrentObject(modelHost, definition);

            action(new WebModelHost
            {
                HostWeb = currentObject
            });

            currentObject.Update();
        }
Example #25
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var folderModelHost = modelHost.WithAssertAndCast <FolderModelHost>("modelHost", value => value.RequireNotNull());
            var folderModel     = model.WithAssertAndCast <FolderDefinition>("model", value => value.RequireNotNull());

            if (folderModelHost.CurrentLibrary != null)
            {
                var currentFolder = FindCurrentLibraryFolder(folderModelHost, folderModel);

                var newContext = new FolderModelHost
                {
                    CurrentLibrary       = folderModelHost.CurrentLibrary,
                    CurrentLibraryFolder = currentFolder
                };

                action(newContext);

                currentFolder.Update();
            }
            else if (folderModelHost.CurrentList != null)
            {
                var currentListItem = FindCurrentListFolder(folderModelHost, folderModel);

                var newContext = new FolderModelHost
                {
                    CurrentList     = folderModelHost.CurrentList,
                    CurrentListItem = currentListItem
                };

                action(newContext);

                if (newContext.ShouldUpdateHost)
                {
                    currentListItem.Update();
                }
            }
        }
Example #26
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var web = ExtractWeb(modelHost);

            if (web != null)
            {
                string securityGroupName;

                if (model is SecurityGroupLinkDefinition)
                {
                    securityGroupName = (model as SecurityGroupLinkDefinition).SecurityGroupName;
                }
                else if (model is SecurityGroupDefinition)
                {
                    securityGroupName = (model as SecurityGroupDefinition).Name;
                }
                else
                {
                    throw new ArgumentException("model has to be SecurityGroupDefinition or SecurityGroupLinkDefinition");
                }

                var securityGroup = web.SiteGroups[securityGroupName];

                var newModelHost = new SecurityGroupModelHost
                {
                    SecurityGroup   = securityGroup,
                    SecurableObject = modelHost as SPSecurableObject
                };

                action(newModelHost);
            }
            else
            {
                action(modelHost);
            }
        }
Example #27
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var storeModelHost = modelHost.WithAssertAndCast <TermStoreModelHost>("modelHost", value => value.RequireNotNull());
            var groupModel     = model.WithAssertAndCast <TaxonomyTermGroupDefinition>("model", value => value.RequireNotNull());

            var termStore    = storeModelHost.HostTermStore;
            var currentGroup = FindGroup(storeModelHost, groupModel);

            action(new TermGroupModelHost
            {
                HostTermStore = termStore,
                HostGroup     = currentGroup
            });
        }
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var siteModelHost  = modelHost.WithAssertAndCast <SiteModelHost>("model", value => value.RequireNotNull());
            var termStoreModel = model.WithAssertAndCast <TaxonomyTermStoreDefinition>("model", value => value.RequireNotNull());

            var termStore = FindTermStore(siteModelHost, termStoreModel);

            action(new TermStoreModelHost
            {
                HostSite      = siteModelHost.HostSite,
                HostTermStore = termStore
            });

            termStore.CommitAll();
        }
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var securableObject = ExtractSecurableObject(modelHost);

            if (securableObject is SecurableObject)
            {
                var securityGroupLinkModel = model as SecurityGroupLinkDefinition;
                if (securityGroupLinkModel == null)
                {
                    throw new ArgumentException("model has to be SecurityGroupDefinition");
                }

                var web = GetWebFromSPSecurableObject(securableObject as SecurableObject);

                var context = web.Context;

                context.Load(web, w => w.SiteGroups);
                context.ExecuteQueryWithTrace();

                Group securityGroup = ResolveSecurityGroup(securityGroupLinkModel, web, context);

                var newModelHost = new SecurityGroupModelHost
                {
                    SecurableObject = securableObject,
                    SecurityGroup   = securityGroup
                };

                action(newModelHost);
            }
            else
            {
                action(modelHost);
            }
        }
Example #30
0
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost      = modelHostContext.ModelHost;
            var model          = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action         = modelHostContext.Action;


            var quickLaunchNode = model as NavigationNodeDefinitionBase;

            if (modelHost is WebModelHost)
            {
                var webModelHost = modelHost as WebModelHost;
                var currentNode  = EnsureRootNavigationNode(webModelHost, quickLaunchNode);

                var nodeHost = ModelHostBase.Inherit <NavigationNodeModelHost>(webModelHost, host =>
                {
                    host.HostNavigationNode = currentNode;
                });

                action(nodeHost);
            }
            else if (modelHost is NavigationNodeModelHost)
            {
                var nodeModelHost = modelHost as NavigationNodeModelHost;
                var currentNode   = EnsureNavigationNode(nodeModelHost, quickLaunchNode);

                var nodeHost = ModelHostBase.Inherit <NavigationNodeModelHost>(nodeModelHost, host =>
                {
                    host.HostNavigationNode = currentNode;
                });

                action(nodeHost);
            }
            else
            {
                action(modelHost);
            }
        }