Exemplo n.º 1
0
 public FileDeployer(ModelNode site, ModelNode web, ListDefinition rootNode, string sourcePath)
 {
     Site       = site;
     Web        = web;
     RootNode   = rootNode;
     SourcePath = sourcePath;
 }
Exemplo n.º 2
0
        public static ListDefinition GetListTestTemplate(SPListTemplateType listTemplateType, Action<ListDefinition> action)
        {
            var result = new ListDefinition
            {
                Title = string.Format("{0} test list", listTemplateType.ToString()),
                Url = string.Format("{0}testlist", listTemplateType.ToString()),
                TemplateType = (int)listTemplateType,
                Description = Guid.NewGuid().ToString(),
                ContentTypesEnabled = true
            };

            if (action != null) action(result);

            return result;
        }
        public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options)
        {
            var web = (reverseHost as ListReverseHost).HostWeb;
            var item = (reverseHost as ListReverseHost).HostList;

            var def = new ListDefinition();

            def.Title = item.Title;
            def.Description = item.Description;

            var listServerRelativeUrl = item.RootFolder.ServerRelativeUrl;

            if (!web.IsObjectPropertyInstantiated("ServerRelativeUrl"))
            {
                web.Context.Load(web, w => w.ServerRelativeUrl);
                web.Context.ExecuteQueryWithTrace();
            }

            var webServerRelativeUrl = web.ServerRelativeUrl;

            var listWebRelativeUrl = listServerRelativeUrl;

            // roort web / ?
            if (webServerRelativeUrl.Length > 1)
            {
                listWebRelativeUrl = listServerRelativeUrl.Replace(webServerRelativeUrl, string.Empty);
            }

            def.CustomUrl = UrlUtility.RemoveStartingSlash(listWebRelativeUrl);

            // TODO, fix for lists based on custom list templates
            def.TemplateType = item.BaseTemplate;

            def.ContentTypesEnabled = item.ContentTypesEnabled;

            def.Hidden = item.Hidden;
            //def.OnQuickLaunch = item.OnQuickLaunch;

            return new ListModelNode
            {
                Options = { RequireSelfProcessing = true },
                Value = def
            };
        }
Exemplo n.º 4
0
        private static void MapListProperties(SPList list, ListDefinition definition)
        {
            list.Title = definition.Title;

            // SPBug, again & again, must not be null
            list.Description = definition.Description ?? string.Empty;
            list.ContentTypesEnabled = definition.ContentTypesEnabled;

            if (!string.IsNullOrEmpty(definition.DraftVersionVisibility))
            {
                var draftOption = (DraftVisibilityType)Enum.Parse(typeof(DraftVisibilityType), definition.DraftVersionVisibility);
                list.DraftVersionVisibility = draftOption;
            }

            // IRM
            if (definition.IrmEnabled.HasValue)
                list.IrmEnabled = definition.IrmEnabled.Value;

            if (definition.IrmExpire.HasValue)
                list.IrmExpire = definition.IrmExpire.Value;

            if (definition.IrmReject.HasValue)
                list.IrmReject = definition.IrmReject.Value;

            // the rest
            if (definition.EnableAttachments.HasValue)
                list.EnableAttachments = definition.EnableAttachments.Value;

            if (definition.EnableFolderCreation.HasValue)
                list.EnableFolderCreation = definition.EnableFolderCreation.Value;

            if (definition.EnableMinorVersions.HasValue)
                list.EnableMinorVersions = definition.EnableMinorVersions.Value;

            if (definition.EnableModeration.HasValue)
                list.EnableModeration = definition.EnableModeration.Value;

            if (definition.EnableVersioning.HasValue)
                list.EnableVersioning = definition.EnableVersioning.Value;

            if (definition.ForceCheckout.HasValue)
                list.ForceCheckout = definition.ForceCheckout.Value;

            if (definition.Hidden.HasValue)
                list.Hidden = definition.Hidden.Value;

            if (definition.NoCrawl.HasValue)
                list.NoCrawl = definition.NoCrawl.Value;

            if (definition.OnQuickLaunch.HasValue)
                list.OnQuickLaunch = definition.OnQuickLaunch.Value;

            if (definition.MajorVersionLimit.HasValue)
                list.MajorVersionLimit = definition.MajorVersionLimit.Value;

            if (definition.MajorWithMinorVersionsLimit.HasValue)
                list.MajorWithMinorVersionsLimit = definition.MajorWithMinorVersionsLimit.Value;
        }
Exemplo n.º 5
0
        private static void MapListProperties(List list, ListDefinition definition)
        {
            list.Title = definition.Title;
            list.Description = definition.Description ?? string.Empty;
            list.ContentTypesEnabled = definition.ContentTypesEnabled;

            if (definition.Hidden.HasValue)
                list.Hidden = definition.Hidden.Value;

            if (!string.IsNullOrEmpty(definition.DraftVersionVisibility))
            {
                var draftOption = (DraftVisibilityType)Enum.Parse(typeof(DraftVisibilityType), definition.DraftVersionVisibility);
                list.DraftVersionVisibility = draftOption;
            }

            // IRM
            if (definition.IrmEnabled.HasValue)
                list.IrmEnabled = definition.IrmEnabled.Value;

            if (definition.IrmExpire.HasValue)
                list.IrmExpire = definition.IrmExpire.Value;

            if (definition.IrmReject.HasValue)
                list.IrmReject = definition.IrmReject.Value;

            // the rest
            if (definition.EnableAttachments.HasValue)
                list.EnableAttachments = definition.EnableAttachments.Value;

            if (definition.EnableFolderCreation.HasValue)
                list.EnableFolderCreation = definition.EnableFolderCreation.Value;

            if (definition.EnableMinorVersions.HasValue)
                list.EnableMinorVersions = definition.EnableMinorVersions.Value;

            if (definition.EnableModeration.HasValue)
                list.EnableModeration = definition.EnableModeration.Value;

            if (definition.EnableVersioning.HasValue)
                list.EnableVersioning = definition.EnableVersioning.Value;

            if (definition.ForceCheckout.HasValue)
                list.ForceCheckout = definition.ForceCheckout.Value;

            if (definition.Hidden.HasValue)
                list.Hidden = definition.Hidden.Value;

            if (definition.NoCrawl.HasValue)
                list.NoCrawl = definition.NoCrawl.Value;

            if (definition.OnQuickLaunch.HasValue)
                list.OnQuickLaunch = definition.OnQuickLaunch.Value;

            if (definition.MajorVersionLimit.HasValue)
            {
                /// CSOM is not supported yet as M2 s build with SP2013 SP1+ assemblies.
                /// https://officespdev.uservoice.com/forums/224641-general/suggestions/6016131-majorversionlimit-majorwithminorversionslimit-pr

                //list.MajorVersionLimit = definition.MajorVersionLimit.Value;
            }

            if (definition.MajorWithMinorVersionsLimit.HasValue)
            {
                /// CSOM is not supported yet as M2 s build with SP2013 SP1+ assemblies.
                /// https://officespdev.uservoice.com/forums/224641-general/suggestions/6016131-majorversionlimit-majorwithminorversionslimit-pr

                //list.MajorWithMinorVersionsLimit = definition.MajorWithMinorVersionsLimit.Value;
            }
        }
Exemplo n.º 6
0
        protected virtual ListTemplate ResolveListTemplate(WebModelHost host, ListDefinition listModel)
        {
            var context = host.HostClientContext;

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

            // internal names would be with '.STP', so just a little bit easier to define and find
            var templateName = listModel.TemplateName.ToUpper().Replace(".STP", string.Empty);

            TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Fetching all web.ListTemplates");

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

            var listTemplate = web.ListTemplates
                                  .FirstOrDefault(t => t.InternalName.ToUpper().Replace(".STP", string.Empty) == templateName);

            if (listTemplate == null)
            {
                TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall,
                    "Searching list template in Site.GetCustomListTemplates(web)");

                var customListTemplates = site.GetCustomListTemplates(web);
                context.Load(customListTemplates);
                context.ExecuteQueryWithTrace();

                listTemplate = customListTemplates
                                  .FirstOrDefault(t => t.InternalName.ToUpper().Replace(".STP", string.Empty) == templateName);
            }

            if (listTemplate == null)
            {
                throw new SPMeta2Exception(string.Format("Can't find custom list template with internal Name:[{0}]",
                    listModel.TemplateName));
            }
            return listTemplate;
        }
        public void Deploy_FoldersToList()
        {
            // Step 1, define security groups
            var customerIssues = new ListDefinition
            {
                Title = "Customer KPIs",
                Url = "CustomerKPI",
                Description = "Stores customer related KPIs.",
                TemplateType = BuiltInListTemplateTypeId.GenericList
            };

            var Year2010 = new FolderDefinition { Name = "2010" };
            var Year2011 = new FolderDefinition { Name = "2011" };
            var Year2012 = new FolderDefinition { Name = "2012" };

            var Q1 = new FolderDefinition { Name = "Q1" };
            var Q2 = new FolderDefinition { Name = "Q2" };
            var Q3 = new FolderDefinition { Name = "Q3" };
            var Q4 = new FolderDefinition { Name = "Q4" };

            // deploy web model - list and add content type links to list
            var webModel = SPMeta2Model
                             .NewWebModel(web =>
                             {
                                 web
                                     .AddList(customerIssues, list =>
                                     {
                                         list
                                             .AddFolder(Year2010, folder =>
                                             {
                                                 folder
                                                     .AddFolder(Q1)
                                                     .AddFolder(Q2)
                                                     .AddFolder(Q3)
                                                     .AddFolder(Q4);
                                             })
                                             .AddFolder(Year2011, folder =>
                                             {
                                                 folder
                                                     .AddFolder(Q1)
                                                     .AddFolder(Q2)
                                                     .AddFolder(Q3)
                                                     .AddFolder(Q4);
                                             })
                                             .AddFolder(Year2012, folder =>
                                             {
                                                 folder
                                                     .AddFolder(Q1)
                                                     .AddFolder(Q2)
                                                     .AddFolder(Q3)
                                                     .AddFolder(Q4);
                                             });
                                     });
                             });

            DeployWebModel(webModel);
        }
        public void Deploy_ListsViews()
        {
            // Step 1, define lists
            var customerClaims = new ListDefinition
            {
                Title = "Customer claims",
                Url = "CustomerClaims",
                Description = "Stores customer related claims.",
                TemplateType = BuiltInListTemplateTypeId.DocumentLibrary
            };


            var lastTenClaims = new ListViewDefinition
            {
                Title = "Last 10 claims",
                IsDefault = false,
                RowLimit = 10,
                Query = string.Format("<OrderBy><FieldRef Name='{0}' Ascending='FALSE' /></OrderBy>", BuiltInInternalFieldNames.Created),
                Fields = new System.Collections.ObjectModel.Collection<string>
                {
                    BuiltInInternalFieldNames.ID,
                    BuiltInInternalFieldNames.File_x0020_Type,
                    BuiltInInternalFieldNames.FileLeafRef,
                    BuiltInInternalFieldNames.Created,
                    BuiltInInternalFieldNames.Modified,
                    BuiltInInternalFieldNames.Author,
                }
            };

            var lastTenEditedClaims = new ListViewDefinition
            {
                Title = "Last 10 edited claims",
                IsDefault = false,
                RowLimit = 10,
                Query = string.Format("<OrderBy><FieldRef Name='{0}' Ascending='FALSE' /></OrderBy>", BuiltInInternalFieldNames.Modified),
                Fields = new System.Collections.ObjectModel.Collection<string>
                {
                    BuiltInInternalFieldNames.ID,
                    BuiltInInternalFieldNames.File_x0020_Type,
                    BuiltInInternalFieldNames.FileLeafRef,
                    BuiltInInternalFieldNames.Created,
                    BuiltInInternalFieldNames.Modified,
                    BuiltInInternalFieldNames.Author,
                }
            };

            // Step 2, define web model and artifact relationships - add feature to the web 
            var model = SPMeta2Model
                             .NewWebModel(web =>
                             {
                                 web
                                   .AddList(customerClaims, list =>
                                   {
                                       list
                                           .AddView(lastTenClaims)
                                           .AddView(lastTenEditedClaims);
                                   });
                             });

            // Step 3, deploy model
            DeployWebModel(model);
        }
Exemplo n.º 9
0
        private void MapListProperties(List list, ListDefinition definition)
        {
            list.Title = definition.Title;
            list.Description = definition.Description ?? string.Empty;
            list.ContentTypesEnabled = definition.ContentTypesEnabled;

            if (definition.Hidden.HasValue)
                list.Hidden = definition.Hidden.Value;

            if (!string.IsNullOrEmpty(definition.DraftVersionVisibility))
            {
                var draftOption = (DraftVisibilityType)Enum.Parse(typeof(DraftVisibilityType), definition.DraftVersionVisibility);
                list.DraftVersionVisibility = draftOption;
            }

            // IRM
            if (definition.IrmEnabled.HasValue)
                list.IrmEnabled = definition.IrmEnabled.Value;

            if (definition.IrmExpire.HasValue)
                list.IrmExpire = definition.IrmExpire.Value;

            if (definition.IrmReject.HasValue)
                list.IrmReject = definition.IrmReject.Value;

            // the rest
            if (definition.EnableAttachments.HasValue)
                list.EnableAttachments = definition.EnableAttachments.Value;

            if (definition.EnableFolderCreation.HasValue)
                list.EnableFolderCreation = definition.EnableFolderCreation.Value;

            if (definition.EnableMinorVersions.HasValue)
                list.EnableMinorVersions = definition.EnableMinorVersions.Value;

            if (definition.EnableModeration.HasValue)
                list.EnableModeration = definition.EnableModeration.Value;

            if (definition.EnableVersioning.HasValue)
                list.EnableVersioning = definition.EnableVersioning.Value;

            if (definition.ForceCheckout.HasValue)
                list.ForceCheckout = definition.ForceCheckout.Value;

            if (definition.Hidden.HasValue)
                list.Hidden = definition.Hidden.Value;

            if (definition.NoCrawl.HasValue)
                list.NoCrawl = definition.NoCrawl.Value;

            if (definition.OnQuickLaunch.HasValue)
                list.OnQuickLaunch = definition.OnQuickLaunch.Value;

            if (definition.MajorVersionLimit.HasValue)
            {
                // CSOM is not supported yet as M2 s build with SP2013 SP1+ assemblies.
                // https://officespdev.uservoice.com/forums/224641-general/suggestions/6016131-majorversionlimit-majorwithminorversionslimit-pr

                //list.MajorVersionLimit = definition.MajorVersionLimit.Value;
            }

            if (definition.MajorWithMinorVersionsLimit.HasValue)
            {
                // CSOM is not supported yet as M2 s build with SP2013 SP1+ assemblies.
                // https://officespdev.uservoice.com/forums/224641-general/suggestions/6016131-majorversionlimit-majorwithminorversionslimit-pr

                //list.MajorWithMinorVersionsLimit = definition.MajorWithMinorVersionsLimit.Value;
            }

            if (!string.IsNullOrEmpty(definition.DocumentTemplateUrl))
            {
                var urlValue = definition.DocumentTemplateUrl;

                urlValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = urlValue,
                    Context = list.Context,
                }).Value;

                if (!urlValue.StartsWith("/")
                    && !urlValue.StartsWith("http:")
                    && !urlValue.StartsWith("https:"))
                {
                    urlValue = "/" + urlValue;
                }

                list.DocumentTemplateUrl = urlValue;
            }

            ProcessLocalization(list, definition);
        }
Exemplo n.º 10
0
        public static void AddListContentTypeFieldLink(ClientContext ctx, ListDefinition listDef, ContentTypeDefinition contentTypeDef, Field spField)
        {
            var listContentTypes = ctx.Web.Lists.GetByTitle(listDef.Title).ContentTypes;
            ctx.Load(listContentTypes);
            ctx.ExecuteQuery();

            ContentType contentType = listContentTypes.FindByName(contentTypeDef.Name);
            FieldLinkCollection flColl = contentType.FieldLinks;
            ctx.Load(spField, inc => inc.Id);
            ctx.Load(contentType);
            ctx.Load(flColl);
            ctx.ExecuteQuery();

            FieldLink fLink = flColl.SingleOrDefault(f => f.Id == spField.Id);
            if (fLink == null)
            {
                flColl.Add(new FieldLinkCreationInformation() { Field = spField });
                contentType.Update(false);
                ctx.ExecuteQuery();
            }
        }
        private static ModelNode GetTestModel()
        {
            var approvedDocuments = new ListViewDefinition
            {
                Title = "Approved Documents",
                Fields = new Collection<string>
            {
            BuiltInInternalFieldNames.ID,
            BuiltInInternalFieldNames.FileLeafRef
            }
            };

            var inProgressDocuments = new ListViewDefinition
            {
                Title = "In Progress Documents",
                Fields = new Collection<string>
            {
            BuiltInInternalFieldNames.ID,
            BuiltInInternalFieldNames.FileLeafRef
            }
            };

            var documentLibrary = new ListDefinition
            {
                Title = "CustomerDocuments",
                Description = "A customr document library.",
                TemplateType = BuiltInListTemplateTypeId.DocumentLibrary,
                Url = "CustomerDocuments"
            };

            var model = SPMeta2Model.NewWebModel(web =>
            {
                web.AddList(documentLibrary, list =>
                {
                    list.AddListView(approvedDocuments);
                    list.AddListView(inProgressDocuments);

                });
            });

            return model;
        }
Exemplo n.º 12
0
        private static SPList GetListByUrl(SPWeb web, ListDefinition listModel)
        {
            SPList result;

            try
            {
                var targetListUrl = SPUrlUtility.CombineUrl(web.Url, listModel.GetListUrl());
                result = web.GetList(targetListUrl);
            }
            catch
            {
                result = null;
            }

            return result;
        }
Exemplo n.º 13
0
        protected virtual SPListTemplate ResolveListTemplate(SPWeb web, ListDefinition listModel)
        {
            // internal names would be with '.STP', so just a little bit easier to define and find
            var templateName = listModel.TemplateName.ToUpper().Replace(".STP", string.Empty);

            var listTemplate = web.ListTemplates
                .OfType<SPListTemplate>()
                .FirstOrDefault(t => t.InternalName.ToUpper().Replace(".STP", string.Empty) == templateName);

            if (listTemplate == null)
            {
                TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall,
                    "Searching list template in Site.GetCustomListTemplates(web)");

                var customListTemplates = web.Site.GetCustomListTemplates(web);
                listTemplate = customListTemplates
                    .OfType<SPListTemplate>()
                    .FirstOrDefault(t => t.InternalName.ToUpper().Replace(".STP", string.Empty) == templateName);
            }

            if (listTemplate == null)
            {
                throw new SPMeta2Exception(string.Format("Can't find custom list template with internal Name:[{0}]",
                    listModel.TemplateName));
            }
            return listTemplate;
        }
Exemplo n.º 14
0
        private SPList GetOrCreateList(
            object modelHost,
            SPWeb web, ListDefinition listModel)
        {
            var result = GetListByUrl(web, listModel);

            if (result == null)
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingNewObject, "Processing new list");

                var listId = default(Guid);

                // "SPBug", there are two ways to create lists 
                // (1) by TemplateName (2) by TemplateType 
                if (listModel.TemplateType > 0)
                {
                    TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Creating list by TemplateType: [{0}]", listModel.TemplateType);

                    //listId = web.Lists.Add(listModel.Url, listModel.Description ?? string.Empty, (SPListTemplateType)listModel.TemplateType);
                    listId = web.Lists.Add(
                                    listModel.Title,
                                    listModel.Description ?? string.Empty,
                                    listModel.GetListUrl(),
                                    string.Empty,
                                    (int)listModel.TemplateType,
                                    string.Empty);
                }
                else if (!string.IsNullOrEmpty(listModel.TemplateName))
                {
                    TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Creating list by TemplateName: [{0}]", listModel.TemplateName);

                    TraceService.Verbose((int)LogEventId.ModelProvisionCoreCall, "Searching list template in web.ListTemplates");
                    var listTemplate = ResolveListTemplate(web, listModel);

                    listId = web.Lists.Add(
                                   listModel.Title,
                                   listModel.Description ?? string.Empty,
                                   listModel.GetListUrl(),
                                   listTemplate.FeatureId.ToString(),
                                   (int)listTemplate.Type,
                                   listTemplate.DocumentTemplate);
                }
                else
                {
                    throw new ArgumentException("TemplateType or TemplateName must be defined");
                }

                result = web.Lists[listId];

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model = null,
                    EventType = ModelEventType.OnProvisioning,
                    Object = result,
                    ObjectType = typeof(SPList),
                    ObjectDefinition = listModel,
                    ModelHost = modelHost
                });
            }
            else
            {
                TraceService.Information((int)LogEventId.ModelProvisionProcessingExistingObject, "Processing existing list");

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

            return result;
        }
Exemplo n.º 15
0
 public FileDeployerCacheable(ModelNode site, ModelNode web, ListDefinition rootNode, string sourcePath,
     IHashStore<string> provisionCache)
     : base(site, web, rootNode, sourcePath)
 {
     ProvisionCache = provisionCache;
 }
Exemplo n.º 16
0
 protected virtual void ProcessLocalization(List obj, ListDefinition definition)
 {
     ProcessGenericLocalization(obj, new Dictionary<string, List<ValueForUICulture>>
     {
         { "TitleResource", definition.TitleResource },
         { "DescriptionResource", definition.DescriptionResource },
     });
 }
Exemplo n.º 17
0
        private void MapListProperties(List list, ListDefinition definition)
        {
            var context = list.Context;

            list.Title = definition.Title;
            list.Description = definition.Description ?? string.Empty;
            list.ContentTypesEnabled = definition.ContentTypesEnabled;

            if (definition.Hidden.HasValue)
                list.Hidden = definition.Hidden.Value;

            if (!string.IsNullOrEmpty(definition.DraftVersionVisibility))
            {
                var draftOption = (DraftVisibilityType)Enum.Parse(typeof(DraftVisibilityType), definition.DraftVersionVisibility);
                list.DraftVersionVisibility = draftOption;
            }

            // IRM
            if (definition.IrmEnabled.HasValue)
                list.IrmEnabled = definition.IrmEnabled.Value;

            if (definition.IrmExpire.HasValue)
                list.IrmExpire = definition.IrmExpire.Value;

            if (definition.IrmReject.HasValue)
                list.IrmReject = definition.IrmReject.Value;

            // the rest
            if (definition.EnableAttachments.HasValue)
                list.EnableAttachments = definition.EnableAttachments.Value;

            if (definition.EnableFolderCreation.HasValue)
                list.EnableFolderCreation = definition.EnableFolderCreation.Value;

            if (definition.EnableMinorVersions.HasValue)
                list.EnableMinorVersions = definition.EnableMinorVersions.Value;

            if (definition.EnableModeration.HasValue)
                list.EnableModeration = definition.EnableModeration.Value;

            if (definition.EnableVersioning.HasValue)
                list.EnableVersioning = definition.EnableVersioning.Value;

            if (definition.ForceCheckout.HasValue)
                list.ForceCheckout = definition.ForceCheckout.Value;

            if (definition.Hidden.HasValue)
                list.Hidden = definition.Hidden.Value;

            if (definition.NoCrawl.HasValue)
                list.NoCrawl = definition.NoCrawl.Value;

            if (definition.OnQuickLaunch.HasValue)
                list.OnQuickLaunch = definition.OnQuickLaunch.Value;

            if (definition.MajorVersionLimit.HasValue)
            {
                if (ReflectionUtils.HasProperty(list, "MajorVersionLimit"))
                {
                    context.AddQuery(new ClientActionSetProperty(list, "MajorVersionLimit", definition.MajorVersionLimit.Value));
                }
                else
                {
                    TraceService.Critical((int)LogEventId.ModelProvisionCoreCall,
                        string.Format(
                            "CSOM runtime doesn't have [{0}] methods support. Update CSOM runtime to a new version. Provision is skipped",
                            string.Join(", ", "MajorVersionLimit")));
                }
            }

            if (definition.MajorWithMinorVersionsLimit.HasValue)
            {
                if (ReflectionUtils.HasProperty(list, "MajorWithMinorVersionsLimit"))
                {
                    context.AddQuery(new ClientActionSetProperty(list, "MajorWithMinorVersionsLimit", definition.MajorWithMinorVersionsLimit.Value));
                }
                else
                {
                    TraceService.Critical((int)LogEventId.ModelProvisionCoreCall,
                        string.Format(
                            "CSOM runtime doesn't have [{0}] methods support. Update CSOM runtime to a new version. Provision is skipped",
                            string.Join(", ", "MajorWithMinorVersionsLimit")));
                }
            }

            if (!string.IsNullOrEmpty(definition.DocumentTemplateUrl))
            {
                var urlValue = definition.DocumentTemplateUrl;

                urlValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = urlValue,
                    Context = list.Context,
                }).Value;

                if (!urlValue.StartsWith("/")
                    && !urlValue.StartsWith("http:")
                    && !urlValue.StartsWith("https:"))
                {
                    urlValue = "/" + urlValue;
                }

                list.DocumentTemplateUrl = urlValue;
            }

            ProcessLocalization(list, definition);
        }
        public void Deploy_Lists()
        {
            // Step 1, define lists
            var customerDocuments = new ListDefinition
            {
                Title = "Customer documents",
                Url = "CustomerDocs",
                Description = "Stores customer related documents.",
                TemplateType = BuiltInListTemplateTypeId.DocumentLibrary
            };

            var customerTasks = new ListDefinition
            {
                Title = "Customer tasks",
                Url = "CustomerTasks",
                Description = "Stores customer related tasks.",
                TemplateType = BuiltInListTemplateTypeId.TasksWithTimelineAndHierarchy
            };

            // Step 2, define web model and artifact relationships - add feature to the web 
            var model = SPMeta2Model
                             .NewWebModel(web =>
                             {
                                 web
                                   .AddList(customerDocuments)
                                   .AddList(customerTasks);
                             });

            // Step 3, deploy model
            DeployWebModel(model);
        }
Exemplo n.º 19
0
 public static ModelNode AddHostList(this ModelNode model, ListDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNodeWithOptions(definition, action, ModelNodeOptions.New().NoSelfProcessing());
 }
        public void Deploy_ContentTypesToList()
        {
            // Step 1, define security groups
            var contractsList = new ListDefinition
            {
                Title = "Customer contracts",
                Url = "CustomerContracts",
                Description = "Stores customer related contracts.",
                TemplateType = BuiltInListTemplateTypeId.DocumentLibrary,
                ContentTypesEnabled = true
            };

            var standardContract = new ContentTypeDefinition
            {
                Id = new Guid("49fbbb62-f8cd-4372-94a0-756e55a8945e"),
                Name = "Standard Contract",
                ParentContentTypeId = BuiltInContentTypeId.Document,
                Group = SampleConsts.DefaultMetadataGroup
            };

            var legacyContract = new ContentTypeDefinition
            {
                Id = new Guid("ba049ddb-962a-4b8e-80a0-2bd10a6c4a88"),
                Name = "Legacy Contract",
                ParentContentTypeId = BuiltInContentTypeId.Document,
                Group = SampleConsts.DefaultMetadataGroup
            };

            // Step 2, define web model and artifact relationships - add security groups t the web 
            // Deploy site model first - content types to site
            var siteModel = SPMeta2Model
                             .NewSiteModel(site =>
                             {
                                 site
                                     .AddContentType(standardContract)
                                     .AddContentType(legacyContract);
                             });

            DeploySiteModel(siteModel);

            // deploy web model - list and add content type links to list
            var webModel = SPMeta2Model
                             .NewWebModel(web =>
                             {
                                 web
                                     .AddList(contractsList, list =>
                                     {
                                         list
                                             .AddContentTypeLink(standardContract)
                                             .AddContentTypeLink(legacyContract);
                                     });
                             });

            DeployWebModel(webModel);
        }
Exemplo n.º 21
0
        private static List LoadCurrentList(Web web, ListDefinition listModel)
        {
            var context = web.Context;

            List currentList = null;

            #pragma warning disable 618
            var listUrl = UrlUtility.CombineUrl(web.ServerRelativeUrl, listModel.GetListUrl());
            #pragma warning restore 618

            Folder folder;

            var scope = new ExceptionHandlingScope(context);

            using (scope.StartScope())
            {
                using (scope.StartTry())
                {
                    folder = web.GetFolderByServerRelativeUrl(listUrl);
                    context.Load(folder);
                }

                using (scope.StartCatch())
                {

                }
            }

            context.ExecuteQueryWithTrace();

            if (!scope.HasException && folder != null && folder.ServerObjectIsNull != true)
            {
            #if !NET35
                folder = web.GetFolderByServerRelativeUrl(listUrl);

                context.Load(folder.Properties);
                context.ExecuteQueryWithTrace();

                var listId = new Guid(folder.Properties["vti_listname"].ToString());
                var list = web.Lists.GetById(listId);

                context.Load(list);

                if (listModel.IndexedRootFolderPropertyKeys.Any())
                {
                    context.Load(list, l => l.RootFolder.Properties);
                }

                context.ExecuteQueryWithTrace();

                currentList = list;

            #endif

            #if NET35

                // SP2010 CSOM hack
                // http://impl.com/questions/4284722/sharepoint-2010-client-object-model-get-a-list-item-from-a-url

                var listQuery = from list in web.Lists
                                where list.RootFolder.ServerRelativeUrl == listUrl
                                select list;

                var queryResult = context.LoadQuery(listQuery);
                context.ExecuteQueryWithTrace();

                var resultList = queryResult.FirstOrDefault();

                currentList = resultList;
            #endif
            }

            return currentList;
        }
Exemplo n.º 22
0
        private void MapListProperties(object modelHost,  List list, ListDefinition definition)
        {
            var csomModelHost = modelHost.WithAssertAndCast<CSOMModelHostBase>("modelHost", value => value.RequireNotNull());

            var context = list.Context;

            list.Title = definition.Title;
            list.Description = definition.Description ?? string.Empty;
            list.ContentTypesEnabled = definition.ContentTypesEnabled;

            if (definition.Hidden.HasValue)
                list.Hidden = definition.Hidden.Value;

            if (!string.IsNullOrEmpty(definition.DraftVersionVisibility))
            {
                var draftOption = (DraftVisibilityType)Enum.Parse(typeof(DraftVisibilityType), definition.DraftVersionVisibility);
                list.DraftVersionVisibility = draftOption;
            }

            #if !NET35
            // IRM
            if (definition.IrmEnabled.HasValue)
                list.IrmEnabled = definition.IrmEnabled.Value;

            if (definition.IrmExpire.HasValue)
                list.IrmExpire = definition.IrmExpire.Value;

            if (definition.IrmReject.HasValue)
                list.IrmReject = definition.IrmReject.Value;

            #endif

            // the rest
            if (definition.EnableAttachments.HasValue)
                list.EnableAttachments = definition.EnableAttachments.Value;

            if (definition.EnableFolderCreation.HasValue)
                list.EnableFolderCreation = definition.EnableFolderCreation.Value;

            if (definition.EnableMinorVersions.HasValue)
                list.EnableMinorVersions = definition.EnableMinorVersions.Value;

            if (definition.EnableModeration.HasValue)
                list.EnableModeration = definition.EnableModeration.Value;

            if (definition.EnableVersioning.HasValue)
                list.EnableVersioning = definition.EnableVersioning.Value;

            if (definition.ForceCheckout.HasValue)
                list.ForceCheckout = definition.ForceCheckout.Value;

            if (definition.Hidden.HasValue)
                list.Hidden = definition.Hidden.Value;

            if (definition.NoCrawl.HasValue)
                list.NoCrawl = definition.NoCrawl.Value;

            if (definition.OnQuickLaunch.HasValue)
                list.OnQuickLaunch = definition.OnQuickLaunch.Value;

            if (definition.MajorVersionLimit.HasValue)
            {
                if (ReflectionUtils.HasProperty(list, "MajorVersionLimit"))
                {
                    context.AddQuery(new ClientActionSetProperty(list, "MajorVersionLimit", definition.MajorVersionLimit.Value));
                }
                else
                {
                    TraceService.Critical((int)LogEventId.ModelProvisionCoreCall,
                        string.Format(
                            "CSOM runtime doesn't have [{0}] methods support. Update CSOM runtime to a new version. Provision is skipped",
                            string.Join(", ", new string[] { "MajorVersionLimit" })));
                }
            }

            if (definition.MajorWithMinorVersionsLimit.HasValue)
            {
                if (ReflectionUtils.HasProperty(list, "MajorWithMinorVersionsLimit"))
                {
                    context.AddQuery(new ClientActionSetProperty(list, "MajorWithMinorVersionsLimit", definition.MajorWithMinorVersionsLimit.Value));
                }
                else
                {
                    TraceService.Critical((int)LogEventId.ModelProvisionCoreCall,
                        string.Format(
                            "CSOM runtime doesn't have [{0}] methods support. Update CSOM runtime to a new version. Provision is skipped",
                            string.Join(", ", new string[] { "MajorWithMinorVersionsLimit" })));
                }
            }

            if (!string.IsNullOrEmpty(definition.DocumentTemplateUrl))
            {
                var urlValue = definition.DocumentTemplateUrl;

                urlValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
                {
                    Value = urlValue,
                    Context = csomModelHost
                }).Value;

                if (!urlValue.StartsWith("/")
                    && !urlValue.StartsWith("http:")
                    && !urlValue.StartsWith("https:"))
                {
                    urlValue = "/" + urlValue;
                }

                list.DocumentTemplateUrl = urlValue;
            }

            ProcessLocalization(list, definition);

            #if !NET35
            if (definition.IndexedRootFolderPropertyKeys.Any())
            {
                var props = list.RootFolder.Properties;

                // may not be there at all
                var indexedPropertyValue = props.FieldValues.Keys.Contains("vti_indexedpropertykeys")
                                            ? ConvertUtils.ToStringAndTrim(props["vti_indexedpropertykeys"])
                                            : string.Empty;

                var currentIndexedProperties = IndexedPropertyUtils.GetDecodeValueForSearchIndexProperty(indexedPropertyValue);

                // setup property bag
                foreach (var indexedProperty in definition.IndexedRootFolderPropertyKeys)
                {
                    // indexed prop should exist in the prop bag
                    // otherwise it won't be saved by SharePoint (ILSpy / Refletor to see the logic)
                    // http://rwcchen.blogspot.com.au/2014/06/sharepoint-2013-indexed-property-keys.html

                    var propName = indexedProperty.Name;
                    var propValue = string.IsNullOrEmpty(indexedProperty.Value)
                                            ? string.Empty
                                            : indexedProperty.Value;

                    props[propName] = propValue;
                }

                // merge and setup indexed prop keys, preserve existing props
                foreach (var indexedProperty in definition.IndexedRootFolderPropertyKeys)
                {
                    if (!currentIndexedProperties.Contains(indexedProperty.Name))
                        currentIndexedProperties.Add(indexedProperty.Name);
                }

                props["vti_indexedpropertykeys"] = IndexedPropertyUtils.GetEncodedValueForSearchIndexProperty(currentIndexedProperties);
                list.RootFolder.Update();
            }
            #endif
        }
Exemplo n.º 23
0
 public static ModelNode AddList(this ModelNode model, ListDefinition definition)
 {
     return AddList(model, definition, null);
 }
Exemplo n.º 24
0
        private static List LoadCurrentList(Web web, ListDefinition listModel)
        {
            var context = web.Context;

            List currentList = null;

            var listUrl = UrlUtility.CombineUrl(web.ServerRelativeUrl, listModel.GetListUrl());

            Folder folder = null;

            var scope = new ExceptionHandlingScope(context);

            using (scope.StartScope())
            {
                using (scope.StartTry())
                {
                    folder = web.GetFolderByServerRelativeUrl(listUrl);
                    context.Load(folder);
                }

                using (scope.StartCatch())
                {

                }
            }

            context.ExecuteQueryWithTrace();

            if (!scope.HasException && folder != null && folder.ServerObjectIsNull != true)
            {
                folder = web.GetFolderByServerRelativeUrl(listUrl);
                context.Load(folder.Properties);
                context.ExecuteQueryWithTrace();

                var listId = new Guid(folder.Properties["vti_listname"].ToString());
                var list = web.Lists.GetById(listId);

                context.Load(list);
                context.ExecuteQueryWithTrace();

                currentList = list;
            }

            return currentList;
        }
Exemplo n.º 25
0
 public static ModelNode AddList(this ModelNode model, ListDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }
Exemplo n.º 26
0
        private void TestModuleFileDeploymentToList(ListDefinition list)
        {
            var blogSite = ModelGeneratorService.GetRandomDefinition<WebDefinition>(def =>
            {
                def.WebTemplate = BuiltInWebTemplates.Collaboration.Blog;
            });

            var model = SPMeta2Model
                .NewWebModel(web =>
                {
                    web.AddWeb(blogSite, blogWeb =>
                    {
                        blogWeb.AddList(list, rndList =>
                        {
                            rndList.AddModuleFile(new ModuleFileDefinition
                            {
                                FileName = "AllItems.aspx",
                                Content = Encoding.Default.GetBytes(PageTemplates.CustomAllItemsPage),
                                Overwrite = true
                            });

                            rndList.AddWelcomePage(new WelcomePageDefinition
                            {
                                Url = "AllItems.aspx"
                            });
                        });
                    });

                });

            TestModels(new  ModelNode[] { model });
        }
Exemplo n.º 27
0
        private SPList GetOrCreateList(
            object modelHost,
            SPWeb web, ListDefinition listModel)
        {
            var result = GetListByUrl(web, listModel);

            if (result == null)
            {
                var listId = default(Guid);

                // "SPBug", there are two ways to create lists
                // (1) by TemplateName (2) by TemplateType
                if (listModel.TemplateType > 0)
                {
                    listId = web.Lists.Add(listModel.Url, listModel.Description,
                        (SPListTemplateType)listModel.TemplateType);
                }
                else if (!string.IsNullOrEmpty(listModel.TemplateName))
                {
                    // TODO, add some validation
                    var listTemplate = web.ListTemplates[listModel.TemplateName];

                    web.Lists.Add(listModel.Url, listModel.Description, listTemplate);
                }
                else
                {
                    throw new ArgumentException("TemplateType or TemplateName must be defined");
                }

                result = web.Lists[listId];

                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model = null,
                    EventType = ModelEventType.OnProvisioning,
                    Object = result,
                    ObjectType = typeof(SPList),
                    ObjectDefinition = listModel,
                    ModelHost = modelHost
                });
            }
            else
            {
                InvokeOnModelEvent(this, new ModelEventArgs
                {
                    CurrentModelNode = null,
                    Model = null,
                    EventType = ModelEventType.OnProvisioning,
                    Object = result,
                    ObjectType = typeof(SPList),
                    ObjectDefinition = listModel,
                    ModelHost = modelHost
                });
            }

            return result;
        }