Example #1
0
        private void SetFieldSlots(FieldSetting fieldSetting, ISupportsDynamicFields handler)
        {
            if (fieldSetting.DataTypes.Length == 0)
            {
                return;
            }
            var handlerType = handler.GetType();

            Type[][] slots = fieldSetting.HandlerSlots;
            var      dynamicFieldMetadata = handler.GetDynamicFieldMetadata();

            for (int i = 0; i < fieldSetting.Bindings.Count; i++)
            {
                string       propName = fieldSetting.Bindings[i];
                PropertyInfo propInfo = null;
                propInfo = handlerType.GetProperty(propName);
                Type propertyType = null;
                bool readOnly     = false;
                if (propInfo != null)
                {
                    //-- code property
                    propertyType = propInfo.PropertyType;
                    readOnly     = readOnly || !ContentTypeManager.PropertyHasPublicSetter(propInfo);
                }
                else
                {
                    //-- generic property
                    propertyType = dynamicFieldMetadata[propName].PropertyType;
                    readOnly     = !dynamicFieldMetadata[propName].CanWrite;
                }
                for (int j = 0; j < slots[i].Length; j++)
                {
                    if (slots[i][j].IsAssignableFrom(propertyType))
                    {
                        fieldSetting.HandlerSlotIndices[i] = j;
                        fieldSetting.PropertyIsReadOnly    = readOnly;
                        break;
                    }
                }
            }
            fieldSetting.Initialize();
        }
Example #2
0
        public static string GenerateCtd(ISupportsDynamicFields handler, ContentType baseContentType)
        {
            var ctdFormat       = @"<ContentType name=""{0}"" parentType=""{1}"" handler=""{2}"" xmlns=""{4}"">
    <Fields>
{3}
    </Fields>
</ContentType>";
            var fieldFormat     = @"        <Field name=""{0}"" handler=""{1}"">
            <DisplayName>{2}</DisplayName>
            <Description>{3}</Description>
            <Bind property=""{4}"" />
        </Field>
";
            var enumFieldFormat = @"        <Field name=""{0}"" handler=""{1}"">
            <DisplayName>{2}</DisplayName>
            <Description>{3}</Description>
            <Bind property=""{4}"" />
            <Configuration>
                <AllowMultiple>false</AllowMultiple>
                <AllowExtraValue>false</AllowExtraValue>
                <Options>
                    <Enum type='{5}' />
                </Options>
            </Configuration>
        </Field>
";

            var handlerType = handler.GetType();
            var nameAttr    = baseContentType.Name;
            var parentAttr  = baseContentType.Name;
            var handlerAttr = handlerType.FullName;

            var fields = new StringBuilder();
            var dynamicFieldMetadata = handler.GetDynamicFieldMetadata();

            foreach (var propertyName in dynamicFieldMetadata.Keys)
            {
                var dynamicField = dynamicFieldMetadata[propertyName];

                if (dynamicField.FieldSetting == null)
                {
                    var proptype  = dynamicField.PropertyType;
                    var fieldType = dynamicField.FieldType;
                    if (typeof(Enum).IsAssignableFrom(proptype))
                    {
                        fields.AppendFormat(enumFieldFormat, dynamicField.FieldName, fieldType, dynamicField.DisplayName,
                                            dynamicField.Description, propertyName, proptype.FullName);
                    }
                    else
                    {
                        fields.AppendFormat(fieldFormat, dynamicField.FieldName, fieldType,
                                            dynamicField.DisplayName, dynamicField.Description, propertyName);
                    }
                }
                else
                {
                    fields.Append(dynamicField.FieldSetting.ToXml());
                }
            }

            return(String.Format(ctdFormat, nameAttr, parentAttr, handlerAttr,
                                 fields, ContentType.ContentDefinitionXmlNamespace));
        }
Example #3
0
        public static string GenerateCtd(ISupportsDynamicFields handler, ContentType baseContentType)
        {
            var ctdFormat = @"<ContentType name=""{0}"" parentType=""{1}"" handler=""{2}"" xmlns=""{4}"">
    <Fields>
{3}
    </Fields>
</ContentType>";
            var fieldFormat = @"        <Field name=""{0}"" handler=""{1}"">
            <DisplayName>{2}</DisplayName>
            <Description>{3}</Description>
            <Bind property=""{4}"" />
        </Field>
";
            var enumFieldFormat = @"        <Field name=""{0}"" handler=""{1}"">
            <DisplayName>{2}</DisplayName>
            <Description>{3}</Description>
            <Bind property=""{4}"" />
            <Configuration>
                <AllowMultiple>false</AllowMultiple>
                <AllowExtraValue>false</AllowExtraValue>
                <Options>
                    <Enum type='{5}' />
                </Options>
            </Configuration>
        </Field>
";

            var handlerType = handler.GetType();
            var nameAttr = baseContentType.Name; //handlerType.Name;
            var parentAttr = baseContentType.Name;
            var handlerAttr = handlerType.FullName;

            var fields = new StringBuilder();
            var dynamicFieldMetadata = handler.GetDynamicFieldMetadata();
            foreach (var propertyName in dynamicFieldMetadata.Keys)
            {
                var dynamicField = dynamicFieldMetadata[propertyName];

                if (dynamicField.FieldSetting == null)
                {
                    var proptype = dynamicField.PropertyType;
                    var fieldType = dynamicField.FieldType; //GetSuggestedFieldType(proptype);
                    if (typeof (Enum).IsAssignableFrom(proptype))
                    {
                        fields.AppendFormat(enumFieldFormat, dynamicField.FieldName, fieldType, dynamicField.DisplayName,
                            dynamicField.Description, propertyName, proptype.FullName);
                    }
                    else
                    {
                        fields.AppendFormat(fieldFormat, dynamicField.FieldName, fieldType,
                                            dynamicField.DisplayName, dynamicField.Description, propertyName);
                    }
                }
                else
                {
                    fields.Append(dynamicField.FieldSetting.ToXml());
                }
            }

            return String.Format(ctdFormat, nameAttr, parentAttr, handlerAttr, 
                fields, ContentType.ContentDefinitionXmlNamespace);
        }
Example #4
0
 private void SetFieldSlots(FieldSetting fieldSetting, ISupportsDynamicFields handler)
 {
     if (fieldSetting.DataTypes.Length == 0)
         return;
     var handlerType = handler.GetType();
     Type[][] slots = fieldSetting.HandlerSlots;
     var dynamicFieldMetadata = handler.GetDynamicFieldMetadata();
     for (int i = 0; i < fieldSetting.Bindings.Count; i++)
     {
         string propName = fieldSetting.Bindings[i];
         PropertyInfo propInfo = null;
         propInfo = handlerType.GetProperty(propName);
         Type propertyType = null;
         bool readOnly = false;
         if (propInfo != null)
         {
             //-- code property
             propertyType = propInfo.PropertyType;
             readOnly = readOnly || !ContentTypeManager.PropertyHasPublicSetter(propInfo);
         }
         else
         {
             //-- generic property
             propertyType = dynamicFieldMetadata[propName].PropertyType;
             readOnly = !dynamicFieldMetadata[propName].CanWrite;
         }
         for (int j = 0; j < slots[i].Length; j++)
         {
             if (slots[i][j].IsAssignableFrom(propertyType))
             {
                 fieldSetting.HandlerSlotIndices[i] = j;
                 fieldSetting.PropertyIsReadOnly = readOnly;
                 break;
             }
         }
     }
     fieldSetting.Initialize();
 }