예제 #1
0
        static void Main(string[] args)
        {
            // Step 1, define site field
            var customerField = new FieldDefinition
            {
                Id = new Guid("26470917-fbbf-413b-9eb3-537f74797e4e"),
                Title = "Customer Name",
                InternalName = "cstm_CustomerName",
                Description = "Name of the target customer.",
                Group = "Hello SPMeta2",
                FieldType = BuiltInFieldTypes.Text
            };

            // Step 2, define site model and artifact relationships - add field to the site 
            var siteModel = SPMeta2Model
                             .NewSiteModel(site =>
                             {
                                 site.AddField(customerField);
                             });

            // Step 3, deploy model via CSOM
            using (var clientContext = new ClientContext(SampleConsts.CSOM_SiteUrl))
            {
                var csomProvisionService = new CSOMProvisionService();
                csomProvisionService.DeployModel(SPMeta2.CSOM.ModelHosts.SiteModelHost.FromClientContext(clientContext), siteModel);
            }

            // Step 4, deploy model via SSOM
            using (var site = new SPSite(SampleConsts.SSOM_SiteUrl))
            {
                var csomProvisionService = new SSOMProvisionService();
                csomProvisionService.DeployModel(SPMeta2.SSOM.ModelHosts.SiteModelHost.FromSite(site), siteModel);
            }
        }
        protected override void CustomFieldTypeValidation(AssertPair<FieldDefinition, Field> assert, Field spObject, FieldDefinition definition)
        {
            var typedObject = spObject.Context.CastTo<FieldLookup>(spObject);
            var typedDefinition = definition.WithAssertAndCast<LookupFieldDefinition>("model", value => value.RequireNotNull());

            // https://github.com/SubPointSolutions/spmeta2/issues/310
            // AllowMultipleValues - TRUE - LookupMulti
            // AllowMultipleValues - FALSE - Lookup
            assert.ShouldBeEqual((p, s, d) =>
            {
                var srcProp = s.GetExpressionValue(m => m.FieldType);
                var dstProp = d.GetExpressionValue(m => d.TypeAsString);

                var isValid = typedDefinition.AllowMultipleValues
                    ? typedObject.TypeAsString == "LookupMulti"
                    : typedObject.TypeAsString == "Lookup";

                return new PropertyValidationResult
                {
                    Tag = p.Tag,
                    Src = srcProp,
                    Dst = dstProp,
                    IsValid = isValid
                };
            });
        }
예제 #3
0
        protected override void ProcessFieldProperties(SPField field, FieldDefinition fieldModel)
        {
            // let base setting be setup
            base.ProcessFieldProperties(field, fieldModel);

            var typedField = field as SPFieldUser;
            var typedFieldModel = fieldModel.WithAssertAndCast<UserFieldDefinition>("model", value => value.RequireNotNull());

            typedField.AllowDisplay = typedFieldModel.AllowDisplay;
            typedField.Presence = typedFieldModel.Presence;
            typedField.AllowMultipleValues = typedFieldModel.AllowMultipleValues;

            if (!string.IsNullOrEmpty(typedFieldModel.SelectionMode))
                typedField.SelectionMode = (SPFieldUserSelectionMode)Enum.Parse(typeof(SPFieldUserSelectionMode), typedFieldModel.SelectionMode);

            if (typedFieldModel.SelectionGroup.HasValue)
            {
                typedField.SelectionGroup = typedFieldModel.SelectionGroup.Value;
            }
            else if (!string.IsNullOrEmpty(typedFieldModel.SelectionGroupName))
            {
                var group = GetCurrentWeb().SiteGroups.OfType<SPGroup>().FirstOrDefault(g => g.Name.ToUpper() == typedFieldModel.SelectionGroupName.ToUpper());
                typedField.SelectionGroup = group.ID;
            }
        }
        protected override void PostProcessDefinitionTemplate(FieldDefinition def)
        {
            base.PostProcessDefinitionTemplate(def);

            def.Indexed = true;
            def.DefaultValue = defaultValue;
        }
        public void Deploy_NewSiteField()
        {
            // Step 1, define site field
            var customerNameField = new FieldDefinition
            {
                Id = new Guid("26470917-fbbf-413b-9eb3-537f74797e4e"),
                Title = "Customer Name",
                InternalName = "cstm_CustomerName",
                Description = "Name of the target customer.",
                Group = SampleConsts.DefaultMetadataGroup,
                FieldType = BuiltInFieldTypes.Text
            };

            var customerDescriptionField = new FieldDefinition
             {
                 Id = new Guid("26470917-fbbf-413b-9eb3-537f74797e4e"),
                 Title = "Customer Description",
                 InternalName = "cstm_CustomerDescription",
                 Description = "Description of the target customer.",
                 Group = SampleConsts.DefaultMetadataGroup,
                 FieldType = BuiltInFieldTypes.Note
             };

            // Step 2, define site model and artifact relationships - add field to the site 
            var model = SPMeta2Model
                             .NewSiteModel(site =>
                             {
                                 site
                                     .AddField(customerNameField)
                                     .AddField(customerDescriptionField);
                             });

            // Step 3, deploy model
            DeploySiteModel(model);
        }
예제 #6
0
        protected override void ProcessFieldProperties(Field field, FieldDefinition fieldModel)
        {
            var typedFieldModel = fieldModel.WithAssertAndCast<NoteFieldDefinition>("model", value => value.RequireNotNull());

            // the XML update goes first
            // then the rest of the normal props with base.ProcessFieldProperties(field, fieldModel);
            // then specific to NoteField props
            // as crazy as it sounds

            // RichTextMode  update
            // https://github.com/SubPointSolutions/spmeta2/issues/673
            if (!string.IsNullOrEmpty(typedFieldModel.RichTextMode))
            {
                var fieldXml = XDocument.Parse(field.SchemaXml);
                fieldXml.Root.SetAttribute("RichTextMode", typedFieldModel.RichTextMode);

                field.SchemaXml = fieldXml.ToString();
            }

            // let base setting be setup
            base.ProcessFieldProperties(field, fieldModel);

            var typedField = field.Context.CastTo<FieldMultiLineText>(field);

            typedField.NumberOfLines = typedFieldModel.NumberOfLines;
            typedField.AppendOnly = typedFieldModel.AppendOnly;
            typedField.RichText = typedFieldModel.RichText;
        }
 public static ModelNode AddContentTypeFieldLink(this ModelNode model, FieldDefinition definition, Action<ModelNode> action)
 {
     return AddContentTypeFieldLink(model, new ContentTypeFieldLinkDefinition
     {
         FieldId = definition.Id
     }, action);
 }
        protected override void PostProcessFieldDefinitionInstance(FieldDefinition def, FieldReverseHost typedReverseHost, ReverseOptions options)
        {
            var context = typedReverseHost.HostClientContext;

            var typedField = context.CastTo<FieldLookup>(typedReverseHost.Field);
            var typedDef = def.WithAssertAndCast<LookupFieldDefinition>("modelHost", m => m.RequireNotNull());

            typedDef.AllowMultipleValues = typedField.AllowMultipleValues;

            if (typedDef.AllowMultipleValues)
                typedDef.FieldType = BuiltInFieldTypes.LookupMulti;
            else
                typedDef.FieldType = BuiltInFieldTypes.Lookup;

            //typedDef.AppendOnly = typedField.AppendOnly;
            //typedDef.RichText = typedField.RichText;

            //typedDef.NumberOfLines = typedField.NumberOfLines;

            //var xml = XDocument.Parse(typedField.SchemaXml);
            //var fieldXml = xml.Root;

            //var unlimValue = ConvertUtils.ToBool(fieldXml.GetAttributeValue("UnlimitedLengthInDocumentLibrary"));
            //typedDef.UnlimitedLengthInDocumentLibrary = unlimValue.HasValue ? unlimValue.Value : false;

            //var richTextMode = ConvertUtils.ToString(fieldXml.GetAttributeValue("RichTextMode"));
            //typedDef.RichTextMode = richTextMode;
        }
        protected override void ProcessFieldProperties(Field field, FieldDefinition fieldModel)
        {
            var site = HostSite;
            var context = site.Context;

            // let base setting be setup
            base.ProcessFieldProperties(field, fieldModel);

            var typedField = field.Context.CastTo<FieldLookup>(field);
            var typedFieldModel = fieldModel.WithAssertAndCast<DependentLookupFieldDefinition>("model", value => value.RequireNotNull());

            var primaryLookupField = GetPrimaryField(typedFieldModel);

            typedField.Context.Load(primaryLookupField);
            typedField.Context.ExecuteQueryWithTrace();

            if (string.IsNullOrEmpty(typedField.PrimaryFieldId))
            {
                typedField.PrimaryFieldId = primaryLookupField.Id.ToString();
            }
            typedField.ReadOnlyField = true;

            if (!string.IsNullOrEmpty(typedFieldModel.RelationshipDeleteBehavior))
            {
                var value = (RelationshipDeleteBehaviorType)Enum.Parse(typeof(RelationshipDeleteBehaviorType), typedFieldModel.RelationshipDeleteBehavior);
                typedField.RelationshipDeleteBehavior = value;
            }

            // unsupported in CSOM yet
            //dependentLookupField.UnlimitedLengthInDocumentLibrary = primaryLookupField.UnlimitedLengthInDocumentLibrary;
            typedField.Direction = primaryLookupField.Direction;
        }
예제 #10
0
        protected override void ProcessFieldProperties(SPField field, FieldDefinition fieldModel)
        {
            // let base setting be setup
            base.ProcessFieldProperties(field, fieldModel);

            if (!string.IsNullOrEmpty(fieldModel.ValidationMessage))
                field.ValidationMessage = fieldModel.ValidationMessage;

            if (!string.IsNullOrEmpty(fieldModel.ValidationFormula))
                field.ValidationFormula = fieldModel.ValidationFormula;


            var typedFieldModel = fieldModel.WithAssertAndCast<DateTimeFieldDefinition>("model", value => value.RequireNotNull());
            var typedField = field as SPFieldDateTime;

            if (!string.IsNullOrEmpty(typedFieldModel.CalendarType))
                typedField.CalendarType = (SPCalendarType)Enum.Parse(typeof(SPCalendarType), typedFieldModel.CalendarType);

            if (!string.IsNullOrEmpty(typedFieldModel.DisplayFormat))
                typedField.DisplayFormat = (SPDateTimeFieldFormatType)Enum.Parse(typeof(SPDateTimeFieldFormatType), typedFieldModel.DisplayFormat);

#if !NET35
            if (!string.IsNullOrEmpty(typedFieldModel.FriendlyDisplayFormat))
                typedField.FriendlyDisplayFormat = (SPDateTimeFieldFriendlyFormatType)Enum.Parse(typeof(SPDateTimeFieldFriendlyFormatType), typedFieldModel.FriendlyDisplayFormat);
#endif
        }
        protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
        {
            base.ProcessSPFieldXElement(fieldTemplate, fieldModel);

            var typedFieldModel = fieldModel.WithAssertAndCast<SummaryLinkFieldDefinition>("model", value => value.RequireNotNull());

            //fieldTemplate.SetAttribute(BuiltInFieldAttributes.Format, typedFieldModel.EditFormat);
        }
        protected override void ProcessFieldProperties(SPField field, FieldDefinition fieldModel)
        {
            // let base setting be setup
            base.ProcessFieldProperties(field, fieldModel);

            var typedFieldModel = fieldModel.WithAssertAndCast<SummaryLinkFieldDefinition>("model", value => value.RequireNotNull());
            var typedField = field as SummaryLinkField;
        }
        public void CanSerializeAndDeserializeXML()
        {
            var obj = new FieldDefinition();
            var service = new DefaultXMLSerializationService();

            var strValue = service.Serialize(obj);
            service.Deserialize(obj.GetType(), strValue);
        }
예제 #14
0
        protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
        {
            base.ProcessSPFieldXElement(fieldTemplate, fieldModel);

            var typedFieldModel = fieldModel.WithAssertAndCast<CurrencyFieldDefinition>("model", value => value.RequireNotNull());

            fieldTemplate.SetAttribute(BuiltInFieldAttributes.LCID, typedFieldModel.CurrencyLocaleId);
        }
예제 #15
0
        private static void ProcessCommonProperties(SPField siteField, FieldDefinition fieldModel)
        {
            siteField.Title = fieldModel.Title;
            siteField.Group = fieldModel.Group;

            // SPBug, description cannot be null
            siteField.Description = fieldModel.Description ?? string.Empty;
        }
        protected override void PostProcessFieldDefinitionInstance(FieldDefinition def, FieldReverseHost typedReverseHost, ReverseOptions options)
        {
            var context = typedReverseHost.HostClientContext;

            var typedField = context.CastTo<FieldText>(typedReverseHost.Field);
            var typedDef = def.WithAssertAndCast<TextFieldDefinition>("modelHost", m => m.RequireNotNull());

            typedDef.MaxLength = typedField.MaxLength;
        }
예제 #17
0
        protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
        {
            base.ProcessSPFieldXElement(fieldTemplate, fieldModel);

            var typedFieldModel = fieldModel.WithAssertAndCast<ComputedFieldDefinition>("model", value => value.RequireNotNull());

            if (typedFieldModel.EnableLookup.HasValue)
                fieldTemplate.SetAttribute(BuiltInFieldAttributes.EnableLookup, typedFieldModel.EnableLookup.ToString().ToUpper());
        }
예제 #18
0
        protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
        {
            base.ProcessSPFieldXElement(fieldTemplate, fieldModel);

            var typedFieldModel = fieldModel.WithAssertAndCast<ImageFieldDefinition>("model", value => value.RequireNotNull());

            // TODO
            //fieldTemplate.SetAttribute(BuiltInFieldAttributes.RichText, typedFieldModel.RichText.ToString().ToUpper());
        }
예제 #19
0
        protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
        {
            base.ProcessSPFieldXElement(fieldTemplate, fieldModel);

            var typedFieldModel = fieldModel.WithAssertAndCast<TextFieldDefinition>("model", value => value.RequireNotNull());

            if (typedFieldModel.MaxLength.HasValue)
                fieldTemplate.SetAttribute(BuiltInFieldAttributes.MaxLength, typedFieldModel.MaxLength.Value);
        }
        public void CanSerializeAndDeserializeJSON()
        {
            var obj = new FieldDefinition();
            var jsonService = new DefaultJSONSerializationService();

            var strValue = jsonService.Serialize(obj);
            jsonService.Deserialize(obj.GetType(), strValue);

        }
예제 #21
0
        protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
        {
            base.ProcessSPFieldXElement(fieldTemplate, fieldModel);

            var typedFieldModel = fieldModel.WithAssertAndCast<URLFieldDefinition>("model", value => value.RequireNotNull());

            if (!string.IsNullOrEmpty(typedFieldModel.DisplayFormat))
                fieldTemplate.SetAttribute(BuiltInFieldAttributes.Format, typedFieldModel.DisplayFormat);
        }
        protected override void PostProcessFieldDefinitionInstance(FieldDefinition def, FieldReverseHost typedReverseHost, ReverseOptions options)
        {
            var context = typedReverseHost.HostClientContext;

            var typedField = context.CastTo<FieldCurrency>(typedReverseHost.Field);
            var typedDef = def.WithAssertAndCast<CurrencyFieldDefinition>("modelHost", m => m.RequireNotNull());

            if (typedField.CurrencyLocaleId > 0)
                typedDef.CurrencyLocaleId = typedField.CurrencyLocaleId;
        }
        protected override void ProcessSPFieldXElement(XElement fieldTemplate, FieldDefinition fieldModel)
        {
            base.ProcessSPFieldXElement(fieldTemplate, fieldModel);

            var businessFieldModel = fieldModel.WithAssertAndCast<BusinessDataFieldDefinition>("model", value => value.RequireNotNull());

            fieldTemplate.SetAttribute(BuiltInFieldAttributes.SystemInstance, businessFieldModel.SystemInstanceName);
            fieldTemplate.SetAttribute(BuiltInFieldAttributes.EntityNamespace, businessFieldModel.EntityNamespace);
            fieldTemplate.SetAttribute(BuiltInFieldAttributes.EntityName, businessFieldModel.EntityName);
            fieldTemplate.SetAttribute(BuiltInFieldAttributes.BdcField, businessFieldModel.BdcFieldName);
        }
예제 #24
0
 protected SPField GetField(object modelHost, FieldDefinition definition)
 {
     if (modelHost is SiteModelHost)
         return GetSiteField((modelHost as SiteModelHost).HostSite, definition);
     else if (modelHost is SPList)
         return GetListField(modelHost as SPList, definition);
     else
     {
         throw new ArgumentException("modelHost needs to be SPSite/SPList");
     }
 }
        protected override void PostProcessFieldDefinitionInstance(FieldDefinition def, FieldReverseHost typedReverseHost, ReverseOptions options)
        {
            var context = typedReverseHost.HostClientContext;

            var typedField = context.CastTo<FieldDateTime>(typedReverseHost.Field);
            var typedDef = def.WithAssertAndCast<DateTimeFieldDefinition>("modelHost", m => m.RequireNotNull());

            typedDef.CalendarType = typedField.DateTimeCalendarType.ToString();
            typedDef.DisplayFormat = typedField.DisplayFormat.ToString();
            typedDef.FriendlyDisplayFormat = typedField.FriendlyDisplayFormat.ToString();
        }
예제 #26
0
        protected override void ProcessFieldProperties(Field field, FieldDefinition fieldModel)
        {
            // let base setting be setup
            base.ProcessFieldProperties(field, fieldModel);

            var typedFieldModel = fieldModel.WithAssertAndCast<CalculatedFieldDefinition>("model", value => value.RequireNotNull());
            var typedField = field.Context.CastTo<FieldCalculated>(field);

            typedField.Formula = typedFieldModel.Formula ?? string.Empty;
            typedField.OutputType = typedField.OutputType = (FieldType)Enum.Parse(typeof(FieldType), typedFieldModel.OutputType);
        }
예제 #27
0
        public static ModelNode AddField(this ModelNode model, FieldDefinition fieldDefinition, Action<ModelNode> action)
        {
            var defModel = new ModelNode { Value = fieldDefinition };

            model.ChildModels.Add(defModel);

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

            return model;
        }
예제 #28
0
        protected override void ProcessFieldProperties(SPField field, FieldDefinition fieldModel)
        {
            // let base setting be setup
            base.ProcessFieldProperties(field, fieldModel);

            var typedFieldModel = fieldModel.WithAssertAndCast<ImageFieldDefinition>("model", value => value.RequireNotNull());
            var typedField = field as ImageField;

            // TODO
            //typedField.NumberOfLines = typedFieldModel.NumberOfLines;
        }
예제 #29
0
        protected override void ProcessFieldProperties(Field field, FieldDefinition fieldModel)
        {
            // let base setting be setup
            base.ProcessFieldProperties(field, fieldModel);

            if (!string.IsNullOrEmpty(fieldModel.ValidationMessage))
                field.ValidationMessage = fieldModel.ValidationMessage;

            if (!string.IsNullOrEmpty(fieldModel.ValidationFormula))
                field.ValidationFormula = fieldModel.ValidationFormula;
        }
예제 #30
0
        protected override void ProcessFieldProperties(Field field, FieldDefinition fieldModel)
        {
            // let base setting be setup
            base.ProcessFieldProperties(field, fieldModel);

            var typedFieldModel = fieldModel.WithAssertAndCast<URLFieldDefinition>("model", value => value.RequireNotNull());
            var typedField = field.Context.CastTo<FieldUrl>(field);

            if (!string.IsNullOrEmpty(typedFieldModel.DisplayFormat))
                typedField.DisplayFormat = (UrlFieldFormatType)Enum.Parse(typeof(UrlFieldFormatType), typedFieldModel.DisplayFormat);
        }