private static string GetContentTypeId(ContentTypeDefinition contentType)
        {
            if (contentType.Id != default(Guid))
            {
                // for content types like
                // 0x010100339210063E00144CBB5EFF79F55FE57400D05BFCF30398485FBBD6D5BB034AFF74
                // 0x010100339210063E00144CBB5EFF79F55FE57400D05BFCF30398485FBBD6D5BB034AFF74008FA22F0260524AF78AF78C349553F22E

                return contentType.ParentContentTypeId + "00" + contentType.Id.ToString(ContentTypeGuidFormatString).ToUpper();
            }

            if (!string.IsNullOrEmpty(contentType.IdNumberValue))
            {
                // for content types like
                // 0x010100339210063E00144CBB5EFF79F55FE574 
                // 0x010100339210063E00144CBB5EFF79F55FE57401 
                // 0x010100339210063E00144CBB5EFF79F55FE5740101

                return contentType.ParentContentTypeId + contentType.IdNumberValue;
            }

            // TODO
            // however, validation system for model definition are going to be implemented
            throw new ArgumentException("Either Id or IdNumberValue have to be specified for content type model");
        }
        public void Deploy_NewContentType()
        {
            // Step 1, define content type
            var customerContentType = new ContentTypeDefinition
            {
                Id = new Guid("26470917-fbbf-413b-9eb3-537f74797e4e"),
                Name = "Important Customer",
                Description = "An important client to work with.",
                ParentContentTypeId = BuiltInContentTypeId.Item,
                Group = SampleConsts.DefaultMetadataGroup
            };

            var customerDocumentContentType = new ContentTypeDefinition
            {
                Id = new Guid("3faaa80e-0780-47d9-bc4e-ff767e11bd4a"),
                Name = "Important Customer",
                Description = "An important client to work with.",
                ParentContentTypeId = BuiltInContentTypeId.Item,
                Group = SampleConsts.DefaultMetadataGroup
            };

            // Step 2, define site model and artifact relationships - add content type to the site 
            var model = SPMeta2Model
                             .NewSiteModel(site =>
                             {
                                 site
                                     .AddContentType(customerContentType)
                                     .AddContentType(customerDocumentContentType);
                             });

            // Step 3, deploy model
            DeploySiteModel(model);
        }
 public static ModelNode AddContentTypeLink(this ModelNode model, ContentTypeDefinition definition, Action<ModelNode> action)
 {
     return AddContentTypeLink(model, new ContentTypeLinkDefinition
     {
         ContentTypeId = definition.GetContentTypeId(),
         ContentTypeName = definition.Name
     }, action);
 }
        public static ContentTypeDefinition GetContentTypeTestTemplate(string name, string parentContentTypeId, Action<ContentTypeDefinition> action)
        {
            var result = new ContentTypeDefinition
            {
                Id = Guid.NewGuid(),
                Name = name,
                ParentContentTypeId = parentContentTypeId,
                Description = Guid.NewGuid().ToString("N"),
                Group = ModelConsts.DefaultFieldGroup
            };

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

            return result;
        }
 public static ModelNode AddContentTypeLink(this ModelNode model, ContentTypeDefinition definition)
 {
     return AddContentTypeLink(model, definition, null);
 }
        protected virtual void ProcessLocalization(SPContentType obj, ContentTypeDefinition definition)
        {
            if (definition.NameResource.Any())
            {
                foreach (var locValue in definition.NameResource)
                    LocalizationService.ProcessUserResource(obj, obj.NameResource, locValue);
            }

            if (definition.DescriptionResource.Any())
            {
                foreach (var locValue in definition.DescriptionResource)
                    LocalizationService.ProcessUserResource(obj, obj.DescriptionResource, locValue);
            }
        }
 protected virtual void ProcessLocalization(ContentType obj, ContentTypeDefinition definition)
 {
     ProcessGenericLocalization(obj, new Dictionary<string, List<ValueForUICulture>>
     {
         { "NameResource", definition.NameResource },
         { "DescriptionResource", definition.DescriptionResource },
     });
 }
 public static bool IsChildOf(this ContentTypeDefinition childContentTypeDefinition,
     ContentTypeDefinition parentContentTypeDefinition)
 {
     return IsChildOf(childContentTypeDefinition.GetContentTypeId(), parentContentTypeDefinition.GetContentTypeId());
 }
 public static ModelNode AddContentType(this ModelNode model, ContentTypeDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNode(definition, action);
 }
 public static ModelNode AddHostContentType(this ModelNode model, ContentTypeDefinition definition, Action<ModelNode> action)
 {
     return model.AddDefinitionNodeWithOptions(definition, action, ModelNodeOptions.New().NoSelfProcessing());
 }
        private void ProcessFormProperties(ContentType targetContentType, ContentTypeDefinition contentTypeModel)
        {
            if (!string.IsNullOrEmpty(contentTypeModel.NewFormUrl))
                targetContentType.NewFormUrl = contentTypeModel.NewFormUrl;

            if (!string.IsNullOrEmpty(contentTypeModel.NewFormTemplateName))
                targetContentType.NewFormTemplateName = contentTypeModel.NewFormTemplateName;

            if (!string.IsNullOrEmpty(contentTypeModel.EditFormUrl))
                targetContentType.EditFormUrl = contentTypeModel.EditFormUrl;

            if (!string.IsNullOrEmpty(contentTypeModel.EditFormTemplateName))
                targetContentType.EditFormTemplateName = contentTypeModel.EditFormTemplateName;

            if (!string.IsNullOrEmpty(contentTypeModel.DisplayFormUrl))
                targetContentType.DisplayFormUrl = contentTypeModel.DisplayFormUrl;

            if (!string.IsNullOrEmpty(contentTypeModel.DisplayFormTemplateName))
                targetContentType.DisplayFormTemplateName = contentTypeModel.DisplayFormTemplateName;
        }
        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);
        }
        public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options)
        {
            var item = (reverseHost as ContentTypeReverseHost).HostContentType;

            var def = new ContentTypeDefinition();

            def.Name = item.Name;
            def.Hidden = item.Hidden;
            def.Group = item.Group;

            def.ReadOnly = item.ReadOnly;
            def.Sealed = item.Sealed;

            def.Description = item.Description;

            var id = ExtractContentTypeIdAsGuid(item);

            if (id.HasValue)
            {
                def.Id = id.Value;

                // 32 - GUID + 2 as '00' glue
                def.ParentContentTypeId = item.StringId.Substring(0, item.StringId.Length - 34);
            }

            def.Group = item.Group;

            return new ContentTypeModelNode
            {
                Options = { RequireSelfProcessing = true },
                Value = def
            };
        }
 public static ListModelNode M2ProjectPrefixSetDefaultListContentType(this ListModelNode node, ContentTypeDefinition contentTypeDefinition)
 {
     return M2ProjectPrefixSetDefaultListContentType(node, contentTypeDefinition.Name);
 }
Beispiel #15
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();
            }
        }
 public static ListModelNode IntrSetDefaultListContentType(this ListModelNode node, ContentTypeDefinition contentTypeDefinition)
 {
     return IntrSetDefaultListContentType(node, contentTypeDefinition.Name);
 }