コード例 #1
0
        protected SPFieldLink FindExistingFieldLink(SPContentType contentType, ContentTypeFieldLinkDefinition fieldLinkModel)
        {
            if (fieldLinkModel.FieldId.HasValue)
            {
                return(contentType.FieldLinks
                       .OfType <SPFieldLink>()
                       .FirstOrDefault(l => l.Id == fieldLinkModel.FieldId));
            }
            else if (!string.IsNullOrEmpty(fieldLinkModel.FieldInternalName))
            {
                return(contentType.FieldLinks
                       .OfType <SPFieldLink>()
                       .FirstOrDefault(l => l.Name.ToUpper() == fieldLinkModel.FieldInternalName.ToUpper()));
            }

            throw new ArgumentException("FieldId or FieldInternalName must be defined");
        }
コード例 #2
0
        public override ModelNode ReverseSingleHost(object reverseHost, ReverseOptions options)
        {
            var item = (reverseHost as ContentTypeFieldLinkReverseHost).HostFieldLink;

            var def = new ContentTypeFieldLinkDefinition();

            def.FieldInternalName = item.Name;
            def.FieldId           = item.Id;

            def.Hidden   = item.Hidden;
            def.Required = item.Required;

            return(new ContentTypeFieldLinkModelNode
            {
                Options = { RequireSelfProcessing = true },
                Value = def
            });
        }
コード例 #3
0
        private SPField FindField(SPFieldCollection fields, ContentTypeFieldLinkDefinition listFieldLinkModel)
        {
            if (listFieldLinkModel.FieldId.HasGuidValue())
            {
                return(fields
                       .OfType <SPField>()
                       .FirstOrDefault(f => f.Id == listFieldLinkModel.FieldId.Value));
            }

            if (!string.IsNullOrEmpty(listFieldLinkModel.FieldInternalName))
            {
                return(fields
                       .OfType <SPField>()
                       .FirstOrDefault(f => f.InternalName.ToUpper() == listFieldLinkModel.FieldInternalName.ToUpper()));
            }

            throw new ArgumentException("FieldId or FieldInternalName should be defined");
        }
コード例 #4
0
        public void Can_Reverse_Site_ContentType_FieldLinks()
        {
            var model = SPMeta2Model.NewSiteModel(site =>
            {
                site.AddRandomContentType(ct =>
                {
                    // the definition id verification won't match on different ID/Name
                    // both should be there
                    var randomField = new ContentTypeFieldLinkDefinition
                    {
                        FieldInternalName = "CellPhone",
                        FieldId           = BuiltInFieldId.CellPhone
                    };

                    ct.AddContentTypeFieldLink(randomField);
                });

                site.AddRandomContentType();
            });

            DeployReverseAndTestModel(model);
        }
コード例 #5
0
        protected FieldLink FindExistingFieldLink(ContentType contentType, ContentTypeFieldLinkDefinition contentTypeFieldLinkModel)
        {
            var context = contentType.Context;

            context.Load(contentType);
            context.Load(contentType, c => c.FieldLinks);

            context.ExecuteQueryWithTrace();

            if (contentTypeFieldLinkModel.FieldId.HasGuidValue())
            {
                return(contentType.FieldLinks
                       .ToList()
                       .FirstOrDefault(l => l.Id == contentTypeFieldLinkModel.FieldId.Value));
            }
            else if (!string.IsNullOrEmpty(contentTypeFieldLinkModel.FieldInternalName))
            {
                return(contentType.FieldLinks
                       .ToList()
                       .FirstOrDefault(l => l.Name.ToUpper() == contentTypeFieldLinkModel.FieldInternalName.ToUpper()));
            }

            throw new ArgumentException("FieldId or FieldInternalName must be defined");
        }
コード例 #6
0
 public static TModelNode AddContentTypeFieldLink <TModelNode>(this TModelNode model, ContentTypeFieldLinkDefinition definition,
                                                               Action <ContentTypeFieldLinkModelNode> action)
     where TModelNode : ModelNode, IContentTypeFieldLinkHostModelNode, new()
 {
     return(model.AddTypedDefinitionNode(definition, action));
 }
コード例 #7
0
 public static TModelNode AddContentTypeFieldLink <TModelNode>(this TModelNode model, ContentTypeFieldLinkDefinition definition)
     where TModelNode : ModelNode, IContentTypeFieldLinkHostModelNode, new()
 {
     return(AddContentTypeFieldLink(model, definition, null));
 }
コード例 #8
0
 public static ModelNode AddContentTypeFieldLink(this ModelNode model, ContentTypeFieldLinkDefinition definition, Action <ModelNode> action)
 {
     return(model.AddDefinitionNode(definition, action));
 }
コード例 #9
0
 public static ModelNode AddContentTypeFieldLink(this ModelNode model, ContentTypeFieldLinkDefinition definition)
 {
     return(AddContentTypeFieldLink(model, definition, null));
 }
コード例 #10
0
 protected SPField FindAvailableField(SPWeb web, ContentTypeFieldLinkDefinition listFieldLinkModel)
 {
     return(FindField(web.AvailableFields, listFieldLinkModel));
 }
コード例 #11
0
        private Field FindField(FieldCollection fields, ContentTypeFieldLinkDefinition listFieldLinkModel)
        {
            var context = fields.Context;

            var scope = new ExceptionHandlingScope(context);

            Field field = null;

            if (listFieldLinkModel.FieldId.HasGuidValue())
            {
                var id = listFieldLinkModel.FieldId.Value;

                using (scope.StartScope())
                {
                    using (scope.StartTry())
                    {
                        fields.GetById(id);
                    }

                    using (scope.StartCatch())
                    {
                    }
                }
            }
            else if (!string.IsNullOrEmpty(listFieldLinkModel.FieldInternalName))
            {
                var fieldInternalName = listFieldLinkModel.FieldInternalName;

                using (scope.StartScope())
                {
                    using (scope.StartTry())
                    {
                        fields.GetByInternalNameOrTitle(fieldInternalName);
                    }

                    using (scope.StartCatch())
                    {
                    }
                }
            }

            context.ExecuteQueryWithTrace();

            if (!scope.HasException)
            {
                if (listFieldLinkModel.FieldId.HasGuidValue())
                {
                    field = fields.GetById(listFieldLinkModel.FieldId.Value);
                }
                else if (!string.IsNullOrEmpty(listFieldLinkModel.FieldInternalName))
                {
                    field = fields.GetByInternalNameOrTitle(listFieldLinkModel.FieldInternalName);
                }

                context.Load(field);
                context.Load(field, f => f.SchemaXml);

                context.ExecuteQueryWithTrace();
            }

            return(field);
        }