public override IEnumerable <ReverseHostBase> ReverseHosts(ReverseHostBase parentHost, ReverseOptions options)
        {
            var result = new List <ListReverseHost>();

            var typedHost = parentHost.WithAssertAndCast <WebReverseHost>("reverseHost", value => value.RequireNotNull());

            var site = typedHost.HostSite;
            var web  = typedHost.HostWeb;

            var context = typedHost.HostClientContext;

            var items = web.Lists;

            //context.Load(items, i => i.Include(r => r.RootFolder, r => r.RootFolder.Properties));
            context.Load(items,
                         i => i.Include(r => r.RootFolder,
                                        r => r.Title,
                                        r => r.Description,
                                        r => r.Hidden,
                                        r => r.BaseTemplate,
                                        r => r.ContentTypesEnabled)

                         );
            context.ExecuteQueryWithTrace();

            result.AddRange(ApplyReverseFilters(items, options).ToArray().Select(i =>
            {
                return(ModelHostBase.Inherit <ListReverseHost>(parentHost, h =>
                {
                    h.HostList = i;
                }));
            }));

            return(result);
        }
Exemple #2
0
        public override IEnumerable <ReverseHostBase> ReverseHosts(ReverseHostBase parentHost, ReverseOptions options)
        {
            var result = new List <TaxonomyTermSetReverseHost>();

            var typedHost = parentHost.WithAssertAndCast <TaxonomyTermGroupReverseHost>("reverseHost", value => value.RequireNotNull());

            var context = typedHost.HostClientContext;

            var site      = typedHost.HostSite;
            var termGroup = typedHost.HostTermGroup;

            var items = termGroup.TermSets;

            context.Load(items);
            context.ExecuteQueryWithTrace();

            result.AddRange(ApplyReverseFilters(items, options).ToArray().Select(i =>
            {
                return(ModelHostBase.Inherit <TaxonomyTermSetReverseHost>(parentHost, h =>
                {
                    h.HostTermSet = i;
                }));
            }));

            return(result);
        }
Exemple #3
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);
        }
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> 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);
            }
        }
        public override IEnumerable <ReverseHostBase> ReverseHosts(ReverseHostBase parentHost, ReverseOptions options)
        {
            var result = new List <PropertyReverseHost>();

            PropertyValues items = null;

            if (parentHost is ListReverseHost)
            {
                items = (parentHost as ListReverseHost).HostList.RootFolder.Properties;
            }
            else if (parentHost is WebReverseHost)
            {
                items = (parentHost as WebReverseHost).HostWeb.AllProperties;
            }
            else if (parentHost is SiteReverseHost)
            {
                items = (parentHost as SiteReverseHost).HostSite.RootWeb.AllProperties;
            }

            var context = (parentHost as CSOMReverseHostBase).HostClientContext;

            context.Load(items);
            context.ExecuteQueryWithTrace();

            result.AddRange(ApplyReverseFilters(items.FieldValues.Keys, options).ToArray().Select(i =>
            {
                return(ModelHostBase.Inherit <PropertyReverseHost>(parentHost, h =>
                {
                    h.HostPropertyName = i;
                    h.HostPropertyValue = items[i];
                }));
            }));

            return(result);
        }
        public override IEnumerable <ReverseHostBase> ReverseHosts(ReverseHostBase parentHost, ReverseOptions options)
        {
            var result = new List <TaxonomyTermStoreReverseHost>();

            var typedHost = parentHost.WithAssertAndCast <SiteReverseHost>("reverseHost", value => value.RequireNotNull());

            var context = typedHost.HostClientContext;
            var site    = typedHost.HostSite;

            var session   = TaxonomySession.GetTaxonomySession(context);
            var termStore = session.GetDefaultSiteCollectionTermStore();

            context.Load(site);
            context.Load(termStore);

            context.ExecuteQueryWithTrace();

            result.AddRange(ApplyReverseFilters(new[] { site }, options).ToArray().Select(i =>
            {
                return(ModelHostBase.Inherit <TaxonomyTermStoreReverseHost>(parentHost, h =>
                {
                    h.HostTermStore = termStore;
                }));
            }));

            return(result);
        }
        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);
                }
            }
        }
Exemple #8
0
        public override IEnumerable <ReverseHostBase> ReverseHosts(ReverseHostBase parentHost, ReverseOptions options)
        {
            var result = new List <ContentTypeReverseHost>();

            var typedHost = parentHost.WithAssertAndCast <ContentTypeReverseHost>("reverseHost", value => value.RequireNotNull());

            var contentType = typedHost.HostContentType;
            var context     = typedHost.HostClientContext;

            var item = contentType;

            context.Load(item);

            context.Load(item, i => i.Fields);
            context.Load(item, i => i.FieldLinks);

            context.ExecuteQueryWithTrace();

            result.AddRange(ApplyReverseFilters(new[] { item }, options).ToArray().Select(i =>
            {
                return(ModelHostBase.Inherit <ContentTypeReverseHost>(parentHost, h =>
                {
                    h.HostContentType = i;
                }));
            }));

            return(result);
        }
Exemple #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>("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 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;
            }));
        }
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> 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.CurrentLibraryFolder;

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

            var context = folder.Context;

            var currentListItem = currentPage.ListItemAllFields;

            context.Load(currentListItem);
            context.ExecuteQueryWithTrace();

            if (typeof(WebPartDefinitionBase).IsAssignableFrom(childModelType))
            {
                var listItemHost = ModelHostBase.Inherit <ListItemModelHost>(folderModelHost, itemHost =>
                {
                    itemHost.HostListItem = currentListItem;
                });

                action(listItemHost);
            }

            context.ExecuteQueryWithTrace();
        }
        public override IEnumerable <ReverseHostBase> ReverseHosts(ReverseHostBase parentHost, ReverseOptions options)
        {
            var result = new List <ListReverseHost>();

            var typedHost = parentHost.WithAssertAndCast <ListReverseHost>("reverseHost", value => value.RequireNotNull());

            var list    = typedHost.HostList;
            var context = typedHost.HostClientContext;

            var folder = list.RootFolder;

            context.Load(list);
            context.Load(list, l => l.ContentTypes);
            context.Load(folder);
            context.Load(folder, f => f.UniqueContentTypeOrder);

            context.ExecuteQueryWithTrace();

            result.AddRange(ApplyReverseFilters(new[] { list }, options).ToArray().Select(i =>
            {
                return(ModelHostBase.Inherit <ListReverseHost>(parentHost, h =>
                {
                    h.HostList = i;
                }));
            }));

            return(result);
        }
        public override IEnumerable <ReverseHostBase> ReverseHosts(ReverseHostBase parentHost, ReverseOptions options)
        {
            var result = new List <WelcomePageReverseHost>();

            Folder hostFolder = null;

            if (parentHost is FolderReverseHost)
            {
                hostFolder = (parentHost as FolderReverseHost).HostFolder;
            }
            else if (parentHost is ListReverseHost)
            {
                hostFolder = (parentHost as ListReverseHost).HostList.RootFolder;
            }
            else if (parentHost is WebReverseHost)
            {
                hostFolder = (parentHost as WebReverseHost).HostWeb.RootFolder;
            }

            var context = (parentHost as CSOMReverseHostBase).HostClientContext;

            context.Load(hostFolder);
            context.ExecuteQueryWithTrace();

            result.AddRange(ApplyReverseFilters(new[] { hostFolder }, options).ToArray().Select(i =>
            {
                return(ModelHostBase.Inherit <WelcomePageReverseHost>(parentHost, h =>
                {
                    h.HostFolder = i;
                }));
            }));

            return(result);
        }
Exemple #14
0
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> action)
        {
            var folderModelHost       = modelHost as FolderModelHost;
            var webPartPageDefinition = model as WebPartPageDefinition;

            Folder folder = folderModelHost.CurrentLibraryFolder;

            if (folder != null && webPartPageDefinition != null)
            {
                var context     = folder.Context;
                var currentPage = GetCurrentWebPartPage(folderModelHost.CurrentList, folder, GetSafeWebPartPageFileName(webPartPageDefinition));

                var currentListItem = currentPage.ListItemAllFields;
                context.Load(currentListItem);
                context.ExecuteQueryWithTrace();

                if (typeof(WebPartDefinitionBase).IsAssignableFrom(childModelType))
                {
                    var listItemHost = ModelHostBase.Inherit <ListItemModelHost>(folderModelHost, itemHost =>
                    {
                        itemHost.HostListItem = currentListItem;
                    });

                    action(listItemHost);

                    //currentListItem.Update();
                }

                context.ExecuteQueryWithTrace();
            }
            else
            {
                action(modelHost);
            }
        }
        public override IEnumerable <ReverseHostBase> ReverseHosts(ReverseHostBase parentHost, ReverseOptions options)
        {
            var result = new List <SandboxSolutionReverseHost>();

            var typedHost = parentHost.WithAssertAndCast <SiteReverseHost>("reverseHost", value => value.RequireNotNull());

            var site    = typedHost.HostSite;
            var context = typedHost.HostClientContext;

            var solutionList = site.RootWeb.GetCatalog((int)ListTemplateType.SolutionCatalog);
            var items        = solutionList.RootFolder.Files;

            context.Load(items, i => i.Include(f => f.Name,
                                               f => f.ServerRelativeUrl,
                                               f => f.ListItemAllFields));
            context.ExecuteQueryWithTrace();

            result.AddRange(ApplyReverseFilters(items, options).ToArray().Select(i =>
            {
                return(ModelHostBase.Inherit <SandboxSolutionReverseHost>(parentHost, h =>
                {
                    h.HostSandboxSolutionFile = i;
                }));
            }));

            return(result);
        }
Exemple #16
0
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> action)
        {
            var webModelHost = modelHost.WithAssertAndCast <WebModelHost>("modelHost", value => value.RequireNotNull());
            var webModel     = model.WithAssertAndCast <WebDefinition>("model", value => value.RequireNotNull());

            var parentWeb = GetParentWeb(webModelHost);

            var context = parentWeb.Context;

            context.Load(parentWeb, w => w.RootFolder);
            context.Load(parentWeb, w => w.ServerRelativeUrl);
            context.ExecuteQuery();

            var currentWebUrl = GetCurrentWebUrl(context, parentWeb, webModel);

            using (var webContext = new ClientContext(currentWebUrl))
            {
                var tmpWebContext = webContext;

                webContext.Credentials = context.Credentials;
                var tmpWebModelHost = ModelHostBase.Inherit <WebModelHost>(webModelHost,
                                                                           webHost =>
                {
                    webHost.HostWeb = tmpWebContext.Web;
                });

                action(tmpWebModelHost);
            }
        }
        public override IEnumerable <ReverseHostBase> ReverseHosts(ReverseHostBase parentHost, ReverseOptions options)
        {
            var result = new List <FieldReverseHost>();

            var siteHost = parentHost as SiteReverseHost;
            var webHost  = parentHost as WebReverseHost;

            var site    = siteHost.HostSite;
            var context = siteHost.HostClientContext;

            FieldCollection items = null;

            if (webHost != null)
            {
                items = webHost.HostWeb.Fields;
            }
            else
            {
                items = siteHost.HostSite.RootWeb.Fields;
            }

            var typedItems = GetTypedFields(context, items);

            result.AddRange(ApplyReverseFilters(typedItems, options).ToArray().Select(i =>
            {
                return(ModelHostBase.Inherit <FieldReverseHost>(parentHost, h =>
                {
                    h.Field = i;
                }));
            }));

            return(result);
        }
        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);
            }
        }
Exemple #19
0
        public static void DeployListModel(this SSOMProvisionService modelHost, SPList list, ModelNode model)
        {
            var listHost = ModelHostBase.Inherit <ListModelHost>(WebModelHost.FromWeb(list.ParentWeb), h =>
            {
                h.HostList = list;
            });

            modelHost.DeployModel(listHost, model);
        }
        public static void DeployListModel(this CSOMProvisionService modelHost, ClientContext context, List list, ModelNode model)
        {
            var listHost = ModelHostBase.Inherit <ListModelHost>(WebModelHost.FromClientContext(context), h =>
            {
                h.HostList = list;
            });

            modelHost.DeployModel(listHost, model);
        }
Exemple #21
0
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> 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);
            }
        }
Exemple #22
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();
        }
Exemple #23
0
        public override IEnumerable <ReverseHostBase> ReverseHosts(ReverseHostBase parentHost, ReverseOptions options)
        {
            TraceService.Information((int)ReverseLogEventId.ReverseHostsStart, "Processing web reverse host start");

            var result = new List <WebReverseHost>();

            Web web = null;

            if (parentHost is WebReverseHost)
            {
                web = (parentHost as WebReverseHost).HostWeb;
            }
            else if (parentHost is SiteReverseHost)
            {
                web = (parentHost as SiteReverseHost).HostWeb;
            }

            var rootWeb = (parentHost as SiteReverseHost).HostSite.RootWeb;
            var context = (parentHost as CSOMReverseHostBase).HostClientContext;


            //if (!web.IsObjectPropertyInstantiated("ServerRelativeUrl"))
            //{
            //    context.Load(web, w => w.ServerRelativeUrl);
            //    context.Load(rootWeb, w => w.ServerRelativeUrl);

            //    context.ExecuteQueryWithTrace();
            //}

            //var isRootWeb = web.ServerRelativeUrl == rootWeb.ServerRelativeUrl;

            //if (UseRootWebOnly && isRootWeb)
            //{
            //    return new[] { parentHost };
            //}

            var items = web.Webs;

            context.Load(items);
            context.ExecuteQueryWithTrace();

            result.AddRange(ApplyReverseFilters(items, options).ToArray().Select(i =>
            {
                return(ModelHostBase.Inherit <WebReverseHost>(parentHost, h =>
                {
                    h.HostWeb = i;
                }));
            }));

            TraceService.Information((int)ReverseLogEventId.ReverseHostsStart, "Processing web reverse host end");

            return(result);
        }
        public override void DeployListModel(ModelNode model)
        {
            foreach (var webUrl in WebUrls)
            {
                ContainerTraceUtils.WriteLine(string.Format("[INF]    Running on web: [{0}]", webUrl));

                WithCSOMContext(webUrl, context =>
                {
                    for (var provisionGeneration = 0;
                         provisionGeneration < ProvisionGenerationCount;
                         provisionGeneration++)
                    {
                        List list = null;

                        try
                        {
                            list = context.Web.QueryAndGetListByTitle("Site Pages");
                        }
                        catch (Exception ex) { }

                        if (list == null)
                        {
                            try
                            {
                                list = context.Web.QueryAndGetListByTitle("Pages");
                            }
                            catch (Exception ex) { }
                        }

                        if (list == null)
                        {
                            throw new SPMeta2Exception("Cannot find host list");
                        }

                        if (EnableDefinitionProvision)
                        {
                            _provisionService.DeployListModel(context, list, model);
                        }

                        if (EnableDefinitionValidation)
                        {
                            var listHost = ModelHostBase.Inherit <ListModelHost>(WebModelHost.FromClientContext(context), h =>
                            {
                                h.HostList = list;
                            });

                            _validationService.DeployModel(listHost, model);
                        }
                    }
                });
            }
        }
Exemple #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.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");
            }
        }
Exemple #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);

            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);
            }
        }
Exemple #27
0
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> action)
        {
            var siteModelHost = modelHost.WithAssertAndCast <SiteModelHost>("modelHost", value => value.RequireNotNull());
            var definition    = model.WithAssertAndCast <RootWebDefinition>("model", value => value.RequireNotNull());

            var currentObject = GetCurrentObject(siteModelHost, definition);

            var rootModelHost = ModelHostBase.Inherit <WebModelHost>(siteModelHost, host =>
            {
                host.HostWeb = currentObject;
            });

            action(rootModelHost);

            currentObject.Update();
            currentObject.Context.ExecuteQuery();
        }
Exemple #28
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 IEnumerable <ReverseHostBase> ReverseHosts(ReverseHostBase parentHost, ReverseOptions options)
        {
            var result = new List <WebPartPageReverseHost>();

            var typedHost = parentHost.WithAssertAndCast <SiteReverseHost>("reverseHost", value => value.RequireNotNull());

            var site    = typedHost.HostSite;
            var context = typedHost.HostClientContext;

            Folder hostFolder = null;

            if (parentHost is FolderReverseHost)
            {
                hostFolder = (parentHost as FolderReverseHost).HostFolder;
            }
            else if (parentHost is ListReverseHost)
            {
                hostFolder = (parentHost as ListReverseHost).HostList.RootFolder;
            }
            else
            {
                throw new SPMeta2ReverseException(
                          string.Format("Unsupported host:[{0}]", parentHost.GetType()));
            }

            // TODO, query only web part pages
            var items = hostFolder.Files;

            context.Load(items, i => i.Include(
                             t => t.ListItemAllFields,
                             t => t.Name,
                             t => t.ServerRelativeUrl,
                             t => t.Title));
            context.ExecuteQueryWithTrace();

            result.AddRange(ApplyReverseFilters(items, options).ToArray().Select(i =>
            {
                return(ModelHostBase.Inherit <WebPartPageReverseHost>(parentHost, h =>
                {
                    h.HostWebPartPageFile = i;
                }));
            }));

            return(result);
        }
Exemple #30
0
        public override void WithResolvingModelHost(object modelHost, DefinitionBase model, Type childModelType, Action <object> 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.CurrentLibraryFolder = 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);

                currentListItem.Folder.Update();
                currentListItem.Context.ExecuteQueryWithTrace();
            }
            else
            {
                throw new NotImplementedException("model host is unklnown");
            }
        }