public static MetaField CreateMetaField(MetadataManager metadataManager, string title, string dbSQLType, string dbType, string clrType)
        {
            var metaField = metadataManager.CreateMetafield(title);

            metaField.Title     = title;
            metaField.DBSqlType = dbSQLType;
            metaField.DBType    = dbType;
            metaField.ClrType   = clrType;

            return(metaField);
        }
        internal static void CreateRequiredFields()
        {
            // Creation of IsOptimized boolean field
            Type   contentType = typeof(Image);
            string fieldName   = ImageOptimizationConstants.IsOptimizedFieldName;
            UserFriendlyDataType userFriendlyDataType = UserFriendlyDataType.YesNo;

            MetadataManager metadataManager = MetadataManager.GetManager();
            MetaType        metaType        = metadataManager.GetMetaType(contentType);

            if (metaType != null)
            {
                MetaField metaField = metaType.Fields.SingleOrDefault(f => string.Compare(f.FieldName, fieldName, true, CultureInfo.InvariantCulture) == 0);

                if (metaField == null)
                {
                    var metaProperty = FieldHelper.GetFields(contentType).FirstOrDefault(f => string.Compare(f.Name, fieldName, true, CultureInfo.InvariantCulture) == 0);

                    if (metaProperty == null)
                    {
                        WcfField wcfField = BuildBooleanWcfField(contentType, fieldName, true);

                        metaField = metadataManager.CreateMetafield(fieldName);

                        CustomFieldsContext.SetFieldDatabaseMappings(metaField, metaType, userFriendlyDataType, wcfField, metadataManager);

                        metaField.Title = fieldName;
                        metaField.MetaAttributes.Add(new MetaFieldAttribute {
                            Name = "UserFriendlyDataType", Value = userFriendlyDataType.ToString()
                        });
                        metaField.MetaAttributes.Add(new MetaFieldAttribute {
                            Name = "IsCommonProperty", Value = "true"
                        });
                        metaField.Origin = Assembly.GetExecutingAssembly().GetName().Name; // needed to override deletion from Export for deployment
                        metaType.Fields.Add(metaField);

                        metadataManager.SaveChanges();
                    }
                }
            }
        }
        /// <summary>
        /// Installs the profile type.
        /// </summary>
        private void InstallUserProfileTypes(SiteInitializer initializer)
        {
            MetadataManager managerInTransaction = initializer.GetManagerInTransaction <MetadataManager>();
            MetaType        metaType             = managerInTransaction.GetMetaType(typeof(SitefinityProfile));

            if (metaType != null)
            {
                MetaField fullName = (
                    from f in metaType.Fields
                    where f.FieldName == "AuthyId"
                    select f).FirstOrDefault <MetaField>();
                if (fullName == null)
                {
                    fullName            = managerInTransaction.CreateMetafield("AuthyId");
                    fullName.Title      = "AuthyId";
                    fullName.ClrType    = typeof(string).FullName;
                    fullName.ColumnName = "authy_id";
                    fullName.Required   = false;
                    fullName.Hidden     = false;
                    fullName.SetMinValue(0);
                    IList <MetaFieldAttribute> metaAttributes     = fullName.MetaAttributes;
                    MetaFieldAttribute         metaFieldAttribute = new MetaFieldAttribute()
                    {
                        Name  = "UserFriendlyDataType",
                        Value = UserFriendlyDataType.ShortText.ToString()
                    };
                    metaAttributes.Add(metaFieldAttribute);
                    IList <MetaFieldAttribute> metaFieldAttributes = fullName.MetaAttributes;
                    MetaFieldAttribute         metaFieldAttribute1 = new MetaFieldAttribute()
                    {
                        Name  = "IsCommonProperty",
                        Value = "true"
                    };
                    metaFieldAttributes.Add(metaFieldAttribute1);
                    metaType.Fields.Add(fullName);
                }
            }
            this.InstallAuthyProfileConfiguration(initializer);
        }
Пример #4
0
        /// <summary>
        /// Installs the focal point fields.
        /// </summary>
        private void InstallFocalPointFields(SiteInitializer initializer)
        {
            MetadataManager managerInTransaction = initializer.GetManagerInTransaction<MetadataManager>();
            MetaType metaType = managerInTransaction.GetMetaType(typeof(Image));
            if (metaType != null)
            {
                MetaField focalPointX = (
                    from f in metaType.Fields
                    where f.FieldName == "FocalPointX"
                    select f).FirstOrDefault<MetaField>();

                if (focalPointX == null)
                {
                    focalPointX = managerInTransaction.CreateMetafield("FocalPointX");
                    focalPointX.Title = "FocalPointX";
                    focalPointX.ClrType = typeof(int).FullName;
                    focalPointX.ColumnName = "focal_point_x";
                    focalPointX.Required = false;
                    focalPointX.Hidden = true;
                    focalPointX.SetMinValue(0);
                    IList<MetaFieldAttribute> metaAttributes = focalPointX.MetaAttributes;
                    MetaFieldAttribute metaFieldAttribute = new MetaFieldAttribute()
                    {
                        Name = "UserFriendlyDataType",
                        Value = UserFriendlyDataType.Integer.ToString()
                    };
                    metaAttributes.Add(metaFieldAttribute);
                    IList<MetaFieldAttribute> metaFieldAttributes = focalPointX.MetaAttributes;
                    MetaFieldAttribute metaFieldAttribute1 = new MetaFieldAttribute()
                    {
                        Name = "IsCommonProperty",
                        Value = "true"
                    };
                    metaFieldAttributes.Add(metaFieldAttribute1);
                    metaType.Fields.Add(focalPointX);
                }

                MetaField focalPointY = (
                    from f in metaType.Fields
                    where f.FieldName == "FocalPointY"
                    select f).FirstOrDefault<MetaField>();

                if (focalPointY == null)
                {
                    focalPointY = managerInTransaction.CreateMetafield("FocalPointY");
                    focalPointY.Title = "FocalPointY";
                    focalPointY.ClrType = typeof(int).FullName;
                    focalPointY.ColumnName = "focal_point_y";
                    focalPointY.Required = false;
                    focalPointY.Hidden = true;
                    focalPointY.SetMinValue(0);
                    IList<MetaFieldAttribute> metaAttributes = focalPointY.MetaAttributes;
                    MetaFieldAttribute metaFieldAttribute = new MetaFieldAttribute()
                    {
                        Name = "UserFriendlyDataType",
                        Value = UserFriendlyDataType.Integer.ToString()
                    };
                    metaAttributes.Add(metaFieldAttribute);
                    IList<MetaFieldAttribute> metaFieldAttributes = focalPointY.MetaAttributes;
                    MetaFieldAttribute metaFieldAttribute1 = new MetaFieldAttribute()
                    {
                        Name = "IsCommonProperty",
                        Value = "true"
                    };
                    metaFieldAttributes.Add(metaFieldAttribute1);
                    metaType.Fields.Add(focalPointY);
                }

                MetaField focalPointWidth = (
                    from f in metaType.Fields
                    where f.FieldName == "FocalPointWidth"
                    select f).FirstOrDefault<MetaField>();

                if (focalPointWidth == null)
                {
                    focalPointWidth = managerInTransaction.CreateMetafield("FocalPointWidth");
                    focalPointWidth.Title = "FocalPointWidth";
                    focalPointWidth.ClrType = typeof(int).FullName;
                    focalPointWidth.ColumnName = "focal_point_width";
                    focalPointWidth.Required = false;
                    focalPointWidth.Hidden = true;
                    focalPointWidth.SetMinValue(0);
                    IList<MetaFieldAttribute> metaAttributes = focalPointWidth.MetaAttributes;
                    MetaFieldAttribute metaFieldAttribute = new MetaFieldAttribute()
                    {
                        Name = "UserFriendlyDataType",
                        Value = UserFriendlyDataType.Integer.ToString()
                    };
                    metaAttributes.Add(metaFieldAttribute);
                    IList<MetaFieldAttribute> metaFieldAttributes = focalPointWidth.MetaAttributes;
                    MetaFieldAttribute metaFieldAttribute1 = new MetaFieldAttribute()
                    {
                        Name = "IsCommonProperty",
                        Value = "true"
                    };
                    metaFieldAttributes.Add(metaFieldAttribute1);
                    metaType.Fields.Add(focalPointWidth);
                }

                MetaField focalPointHeight = (
                    from f in metaType.Fields
                    where f.FieldName == "FocalPointHeight"
                    select f).FirstOrDefault<MetaField>();

                if (focalPointHeight == null)
                {
                    focalPointHeight = managerInTransaction.CreateMetafield("FocalPointHeight");
                    focalPointHeight.Title = "FocalPointHeight";
                    focalPointHeight.ClrType = typeof(int).FullName;
                    focalPointHeight.ColumnName = "focal_point_height";
                    focalPointHeight.Required = false;
                    focalPointHeight.Hidden = true;
                    focalPointHeight.SetMinValue(0);
                    IList<MetaFieldAttribute> metaAttributes = focalPointHeight.MetaAttributes;
                    MetaFieldAttribute metaFieldAttribute = new MetaFieldAttribute()
                    {
                        Name = "UserFriendlyDataType",
                        Value = UserFriendlyDataType.Integer.ToString()
                    };
                    metaAttributes.Add(metaFieldAttribute);
                    IList<MetaFieldAttribute> metaFieldAttributes = focalPointHeight.MetaAttributes;
                    MetaFieldAttribute metaFieldAttribute1 = new MetaFieldAttribute()
                    {
                        Name = "IsCommonProperty",
                        Value = "true"
                    };
                    metaFieldAttributes.Add(metaFieldAttribute1);
                    metaType.Fields.Add(focalPointHeight);
                }

                MetaField focalPointAnchor = (
                    from f in metaType.Fields
                    where f.FieldName == "FocalPointAnchor"
                    select f).FirstOrDefault<MetaField>();

                if (focalPointAnchor == null)
                {
                    focalPointAnchor = managerInTransaction.CreateMetafield("FocalPointAnchor");
                    focalPointAnchor.Title = "FocalPointAnchor";
                    focalPointAnchor.ClrType = typeof(int).FullName;
                    focalPointAnchor.ColumnName = "focal_point_anchor";
                    focalPointAnchor.Required = false;
                    focalPointAnchor.Hidden = true;
                    focalPointAnchor.SetMinValue(0);
                    IList<MetaFieldAttribute> metaAttributes = focalPointAnchor.MetaAttributes;
                    MetaFieldAttribute metaFieldAttribute = new MetaFieldAttribute()
                    {
                        Name = "UserFriendlyDataType",
                        Value = UserFriendlyDataType.Integer.ToString()
                    };
                    metaAttributes.Add(metaFieldAttribute);
                    IList<MetaFieldAttribute> metaFieldAttributes = focalPointAnchor.MetaAttributes;
                    MetaFieldAttribute metaFieldAttribute1 = new MetaFieldAttribute()
                    {
                        Name = "IsCommonProperty",
                        Value = "true"
                    };
                    metaFieldAttributes.Add(metaFieldAttribute1);
                    metaType.Fields.Add(focalPointAnchor);
                }
            }
        }