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);
            }
        }
        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);
            }
        }
        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();
        }
        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 listModelHost = modelHost.WithAssertAndCast<FolderModelHost>("modelHost", value => value.RequireNotNull());

            var folder = listModelHost.CurrentLibraryFolder;
            var publishingPageModel = model.WithAssertAndCast<PublishingPageDefinition>("model", value => value.RequireNotNull());

            var targetPage = FindPublishingPage(folder, publishingPageModel);

            ModuleFileModelHandler.WithSafeFileOperation(listModelHost.CurrentLibrary, folder,
                targetPage.Url,
                GetSafePublishingPageFileName(publishingPageModel),
                Encoding.UTF8.GetBytes(PublishingPageTemplates.RedirectionPageMarkup),
                false,
                null,
                afterFile =>
                {
                    using (var webPartManager = afterFile.GetLimitedWebPartManager(PersonalizationScope.Shared))
                    {
                        var webpartPageHost = new WebpartPageModelHost
                        {
                            HostFile = afterFile,
                            PageListItem = targetPage,
                            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 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 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 #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 siteModelHost = modelHost.WithAssertAndCast<SiteModelHost>("modelHost", value => value.RequireNotNull());

            action(siteModelHost);
        }
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 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();
        }
Example #11
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");
            }
        }
        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
            });
        }
        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();
        }
        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);
        }
        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();
        }
        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 SPWen 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(targetContentType);
                    }

                    targetContentType.Update(true);
                    tmpRootWeb.Update();
                }
            }
            else
            {
                action(modelHost);
            }
        }
        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
            });
        }
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 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 #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 folderModelHost = modelHost.WithAssertAndCast<FolderModelHost>("modelHost", value => value.RequireNotNull());
            var folderModel = model.WithAssertAndCast<FolderDefinition>("model", value => value.RequireNotNull());

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

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

                action(newContext);

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

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

                action(newContext);

                if (newContext.ShouldUpdateHost)
                    currentListItem.Update();
            }
        }
        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 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);
            }
        }
        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 webModelHost = modelHost.WithAssertAndCast<SiteModelHost>("modelHost", value => value.RequireNotNull());

            var web = webModelHost.HostSite.RootWeb;
            var securityGroupModel = model as SecurityGroupDefinition;

            if (web != null && securityGroupModel != null)
            {
                var context = web.Context;

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

                var currentGroup = FindSecurityGroupByTitle(web.SiteGroups, securityGroupModel.Name);

                var host = ModelHostBase.Inherit<SecurityGroupModelHost>(modelHost, h =>
                {
                    h.SecurableObject = web;
                    h.SecurityGroup = currentGroup;
                });

                //action(new ModelHostContext
                action(host);

                currentGroup.Update();
                context.ExecuteQueryWithTrace();
            }
            else
            {
                action(modelHost);
            }
        }
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 farmModelHost = modelHost as FarmModelHost;

            action(farmModelHost);

            if (farmModelHost.ShouldUpdateHost)
            {
                var count = 0;

                while (count < ConcurrencyUpdateAttempts)
                {
                    try
                    {
                        farmModelHost.HostFarm.Update();
                        farmModelHost.HostFarm = SPFarm.Local;

                        break;
                    }
                    catch (SPUpdatedConcurrencyException)
                    {
                        count++;
                        if (count > ConcurrencyUpdateAttempts)
                        {
                            throw;
                        }
                    }
                }
            }

            farmModelHost.HostFarm = SPFarm.Local;
        }
        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 listItemModel = model.WithAssertAndCast<ListItemDefinition>("model", value => value.RequireNotNull());

            SPListItem item = null;
            SPList list = null;

            if (modelHost is ListModelHost)
            {
                list = (modelHost as ListModelHost).HostList;
                var rootFolder = (modelHost as ListModelHost).HostList.RootFolder;

                item = EnsureListItem(list, rootFolder, listItemModel);
            }
            else if (modelHost is FolderModelHost)
            {
                // suppose it is a list, ir must be
                list = (modelHost as FolderModelHost).CurrentList;
                var rootFolder = (modelHost as FolderModelHost).CurrentListItem.Folder;

                item = EnsureListItem(list, rootFolder, listItemModel);
            }

            // naaaaah, just gonna get a new one list item
            // keep it simple and safe, really really really safe with all that SharePoint stuff...
            var currentItem = list.GetItemById(item.ID);

            action(currentItem);

            currentItem.Update();
        }
        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 #26
0
        //public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action<object> action)
        //override with
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost = modelHostContext.ModelHost;
            var model = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action = modelHostContext.Action;

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

            var web = webModelHost.HostWeb;
            var listDefinition = model as ListDefinition;
            var context = web.Context;

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

            if (web != null && listDefinition != null)
            {
                var list = LoadCurrentList(web, listDefinition);

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

                var listModelHost = ModelHostBase.Inherit<ListModelHost>(webModelHost, c =>
                {
                    c.HostList = list;
                });

                if (childModelType == typeof(ListViewDefinition))
                {
                    context.Load<List>(list, l => l.Views);
                    context.ExecuteQueryWithTrace();

                    action(listModelHost);
                }
                else if (childModelType == typeof(ModuleFileDefinition))
                {
                    context.Load<List>(list, l => l.RootFolder);
                    context.Load<List>(list, l => l.BaseType);

                    context.ExecuteQueryWithTrace();

                    var folderModelHost = ModelHostBase.Inherit<FolderModelHost>(webModelHost, itemHost =>
                    {
                        itemHost.CurrentWeb = web;
                        itemHost.CurrentList = list;
                    });

                    if (list.BaseType == BaseType.DocumentLibrary)
                    {
                        folderModelHost.CurrentListFolder = list.RootFolder;
                    }
                    else
                    {
                        folderModelHost.CurrentListFolder = list.RootFolder;
                        folderModelHost.CurrentListItem = null;
                    }

                    action(folderModelHost);
                }
                else if (childModelType == typeof(FolderDefinition))
                {
                    context.Load<List>(list, l => l.RootFolder);
                    context.Load<List>(list, l => l.BaseType);

                    context.ExecuteQueryWithTrace();

                    var folderModelHost = ModelHostBase.Inherit<FolderModelHost>(webModelHost, itemHost =>
                    {
                        itemHost.CurrentWeb = web;
                        itemHost.CurrentList = list;
                    });

                    if (list.BaseType == BaseType.DocumentLibrary)
                    {
                        folderModelHost.CurrentListFolder = list.RootFolder;
                    }
                    else
                    {
                        folderModelHost.CurrentListFolder = list.RootFolder;
                        folderModelHost.CurrentListItem = null;
                    }

                    action(folderModelHost);
                }
                //else if (childModelType == typeof(SP2013WorkflowSubscriptionDefinition))
                //{
                //    var sp2013WorkflowSubscriptionModelHost =
                //        ModelHostBase.Inherit<SP2013WorkflowSubscriptionModelHost>(webModelHost, host =>
                //        {
                //            host.HostList = list;
                //        });

                //    action(sp2013WorkflowSubscriptionModelHost);
                //}
                else if (typeof(PageDefinitionBase).IsAssignableFrom(childModelType))
                {
                    context.Load<List>(list, l => l.RootFolder);
                    context.Load<List>(list, l => l.BaseType);

                    context.ExecuteQueryWithTrace();

                    var folderModelHost = ModelHostBase.Inherit<FolderModelHost>(webModelHost, itemHost =>
                    {
                        itemHost.CurrentWeb = web;
                        itemHost.CurrentList = list;
                    });

                    if (list.BaseType == BaseType.DocumentLibrary)
                    {
                        folderModelHost.CurrentListFolder = list.RootFolder;
                    }
                    else
                    {
                        folderModelHost.CurrentListFolder = list.RootFolder;
                    }

                    action(folderModelHost);
                }
                else
                {
                    action(listModelHost);
                }

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

                if (listModelHost.ShouldUpdateHost)
                    list.Update();
            }
            else
            {
                action(modelHost);
            }
        }
Example #27
0
        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 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
            };

            if (childModelType == typeof (ModuleFileDefinition))
            {
                var folderModelHost = ModelHostBase.Inherit<FolderModelHost>(modelHost, m =>
                {
                    m.CurrentWeb = currentWeb;
                    m.CurrentWebFolder = currentWeb.RootFolder; ;
                });

                action(folderModelHost);
            }
            else
            {
                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();
        }
        public override void WithResolvingModelHost(ModelHostResolveContext modelHostContext)
        {
            var modelHost = modelHostContext.ModelHost;
            var model = modelHostContext.Model;
            var childModelType = modelHostContext.ChildModelType;
            var action = modelHostContext.Action;

            var site = ExtractSite(modelHost);
            var web = ExtractWeb(modelHost);

            var mdHHost = modelHost as CSOMModelHostBase;

            var contentTypeModel = model as ContentTypeDefinition;

            if (web != null && contentTypeModel != null)
            {
                var context = web.Context;

                var id = contentTypeModel.GetContentTypeId();
                var currentContentType = web.ContentTypes.GetById(id);

                context.ExecuteQueryWithTrace();

                if (childModelType == typeof(ModuleFileDefinition))
                {
                    TraceService.Information((int)LogEventId.ModelProvisionCoreCall, "Resolving content type resource folder for ModuleFileDefinition");

                    var serverRelativeFolderUrl = ExtractResourceFolderServerRelativeUrl(web, context, currentContentType);

                    var ctFolder = web.GetFolderByServerRelativeUrl(serverRelativeFolderUrl);
                    context.ExecuteQueryWithTrace();

                    var folderModelHost = ModelHostBase.Inherit<FolderModelHost>(mdHHost, host =>
                    {
                        host.CurrentContentType = currentContentType;
                        host.CurrentContentTypeFolder = ctFolder;
                    });

                    action(folderModelHost);
                }
                else
                {
                    action(new ModelHostContext
                    {
                        Site = site,
                        Web = web,
                        ContentType = currentContentType
                    });
                }

                TraceService.Information((int)LogEventId.ModelProvisionCoreCall, "Calling currentContentType.Update(true)");
                currentContentType.Update(true);

                context.ExecuteQueryWithTrace();
            }
            else
            {
                action(modelHost);
            }
        }
        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 #30
0
        public override void WithResolvingModelHost(ModelHostResolveContext context)
        {
            base.WithResolvingModelHost(context);

            ForceInvalidateSite((context.ModelHost as SiteModelHost).HostSite);
        }