/// <summary>
 /// Add on the class that represents your custom data type, so that the custom data type is inserted into the database.
 /// </summary>
 /// <param name="dataTypeName">Friendly name of the data type</param>
 /// <param name="propertyEditorAlias">Alias of the data type</param>
 /// <param name="preValues">The <c>System.Type</c> of a class which implements <see cref="IPreValueProvider"/></param>      
 public UmbracoDataTypeAttribute(string dataTypeName, string propertyEditorAlias, Type preValues, DataTypeDatabaseType dataTypeDatabaseType)
 {
     DataTypeName = dataTypeName;
     PropertyEditorAlias = propertyEditorAlias;
     PreValues = preValues;
     DatabaseType = dataTypeDatabaseType;
 }
Example #2
0
 /// <summary>
 /// Used internally to assign an explicity database type for this property type regardless of what the underlying data type/property editor is.
 /// </summary>
 /// <param name="propertyEditorAlias"></param>
 /// <param name="dataTypeDatabaseType"></param>
 /// <param name="isExplicitDbType"></param>
 /// <param name="propertyTypeAlias"></param>
 internal PropertyType(string propertyEditorAlias, DataTypeDatabaseType dataTypeDatabaseType, bool isExplicitDbType, string propertyTypeAlias)
 {
     _isExplicitDbType     = isExplicitDbType;
     _propertyEditorAlias  = propertyEditorAlias;
     _dataTypeDatabaseType = dataTypeDatabaseType;
     SetAlias(propertyTypeAlias);
 }
 private static PropertyType GetLabelPropertyType(string name, string alias, DataTypeDatabaseType dataTypeDatabaseType)
 {
     return(new PropertyType("Umbraco.NoEdit", dataTypeDatabaseType)
     {
         Name = name, Alias = alias
     });
 }
Example #4
0
        public PropertyType(IDataTypeDefinition dataTypeDefinition)
        {
            if (dataTypeDefinition.HasIdentity)
            {
                _dataTypeDefinitionId = dataTypeDefinition.Id;
            }

            _propertyEditorAlias  = dataTypeDefinition.PropertyEditorAlias;
            _dataTypeDatabaseType = dataTypeDefinition.DatabaseType;
        }
        public PropertyType(IDataTypeDefinition dataTypeDefinition)
        {
            if (dataTypeDefinition == null)
            {
                throw new ArgumentNullException("dataTypeDefinition");
            }

            if (dataTypeDefinition.HasIdentity)
            {
                _dataTypeDefinitionId = dataTypeDefinition.Id;
            }

            _propertyEditorAlias  = dataTypeDefinition.PropertyEditorAlias;
            _dataTypeDatabaseType = dataTypeDefinition.DatabaseType;
        }
        /// <summary>
        /// If this is one of our internal properties - we will manually assign the data type since they must
        /// always correspond to the correct db type no matter what the backing data type is assigned.
        /// </summary>
        /// <param name="propAlias"></param>
        /// <param name="dbType"></param>
        /// <param name="standardProps"></param>
        /// <returns>
        /// Successful attempt if it was a built in property
        /// </returns>
        internal static Attempt <DataTypeDatabaseType> GetDbTypeForBuiltInProperty(
            string propAlias,
            DataTypeDatabaseType dbType,
            Dictionary <string, PropertyType> standardProps)
        {
            var aliases = standardProps.Select(x => x.Key).ToArray();

            //check if it is built in
            if (aliases.Contains(propAlias))
            {
                //return the pre-determined db type for this property
                return(Attempt <DataTypeDatabaseType> .Succeed(standardProps.Single(x => x.Key == propAlias).Value.DataTypeDatabaseType));
            }

            return(Attempt <DataTypeDatabaseType> .Fail(dbType));
        }
Example #7
0
        public IDataTypeDefinition Create(string name, string propertyEditorAlias, int parentId,
                                          DataTypeDatabaseType databaseType, IDictionary <string, string> preValues)
        {
            if (Exists(name))
            {
                return(null);
            }

            var dataType = new DataTypeDefinition(propertyEditorAlias)
            {
                Name         = name,
                DatabaseType = databaseType,
            };

            if (parentId > 0)
            {
                dataType.ParentId = parentId;
            }

            _dataTypeService.Save(dataType);

            var itemPreValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataType.Id)
                                .FormatAsDictionary();


            foreach (var preValue in preValues)
            {
                LogHelper.Info <DataTypeBuilder>("PreValue: {0} [{1}]", () => preValue.Key, () => preValue.Value);

                if (itemPreValues.ContainsKey(preValue.Key))
                {
                    LogHelper.Info <DataTypeBuilder>("Update");
                    itemPreValues[preValue.Key].Value = preValue.Value;
                }
                else
                {
                    LogHelper.Info <DataTypeBuilder>("Add");
                    itemPreValues.Add(preValue.Key, new PreValue(preValue.Value));
                }
            }

            _dataTypeService.SavePreValues(dataType, itemPreValues);
            _dataTypeService.Save(dataType);

            return(dataType);
        }
Example #8
0
        public DataType Create(string name, string propertyEditor, DataTypeDatabaseType databaseType = DataTypeDatabaseType.Ntext)
        {
            var allDataTypeDefinitions = UmbracoUtils.DataTypeService.GetAllDataTypeDefinitions();

            if (allDataTypeDefinitions.Any(x => x.Name == name))
            {
                throw new FluentException(string.Format("Cannot create Data Type Definition `{0}` as it already exists.", name));
            }

            var newDataTypeDefinition = new DataTypeDefinition(-1, propertyEditor)
            {
                Name = name, DatabaseType = databaseType
            };

            UmbracoUtils.DataTypeService.Save(newDataTypeDefinition);

            return(new DataType(newDataTypeDefinition, UmbracoUtils.UmbracoDatabase, UmbracoUtils.DataTypeService));
        }
Example #9
0
 internal PropertyType(Guid dataTypeControlId, DataTypeDatabaseType dataTypeDatabaseType)
 {
     DataTypeId           = dataTypeControlId;
     DataTypeDatabaseType = dataTypeDatabaseType;
 }
        private static void AddLabelProperty(IContentTypeBase mediaType, string name, string alias, DataTypeDatabaseType dataTypeDatabaseType)
        {
            var intranetUserIdPropertyType = GetLabelPropertyType(name, alias, dataTypeDatabaseType);

            if (mediaType.PropertyTypeExists(intranetUserIdPropertyType.Alias))
            {
                return;
            }

            mediaType.AddPropertyType(intranetUserIdPropertyType, AddVideoMediaTypeStepConstants.DocumentTypeTabNames.File);
        }
        public void DefaultData_SetValue_Ensures_Empty_String_When_Null_Value_Any_Data_Type(DataTypeDatabaseType type)
        {
            var defaultData = new DefaultData(MockRepository.GenerateMock<BaseDataType>());

            ((IDataValueSetter)defaultData).SetValue(null, type.ToString());

            Assert.AreEqual(string.Empty, defaultData.Value);
        }
Example #12
0
 public PropertyType(string propertyEditorAlias, DataTypeDatabaseType dataTypeDatabaseType, string propertyTypeAlias)
     : this(propertyEditorAlias, dataTypeDatabaseType, false, propertyTypeAlias)
 {
 }
Example #13
0
 public IDataType SetDataTypeDatabaseType(DataTypeDatabaseType dataTypeDatabaseType)
 {
     DataTypeDefinition.DatabaseType = dataTypeDatabaseType;
     return(this);
 }
Example #14
0
 public static IDataType Create(string name, string propertyEditor, DataTypeDatabaseType databaseType = DataTypeDatabaseType.Ntext)
 {
     return(FluentDataTypeService.Create(name, propertyEditor, databaseType));
 }
Example #15
0
 public DataTypeConfigurator DataType(DataTypeDatabaseType type)
 {
     configuration.DatabaseType = type;
     return(this);
 }
        /// <summary>
        /// Override so we can specify explicit db type's on any property types that are built-in.
        /// </summary>
        /// <param name="propertyEditorAlias"></param>
        /// <param name="dbType"></param>
        /// <param name="propertyTypeAlias"></param>
        /// <returns></returns>
        protected override PropertyType CreatePropertyType(string propertyEditorAlias, DataTypeDatabaseType dbType, string propertyTypeAlias)
        {
            //custom property type constructor logic to set explicit dbtype's for built in properties
            var stdProps   = Constants.Conventions.Member.GetStandardPropertyTypeStubs();
            var propDbType = GetDbTypeForBuiltInProperty(propertyTypeAlias, dbType, stdProps);

            return(new PropertyType(propertyEditorAlias, propDbType.Result,
                                    //This flag tells the property type that it has an explicit dbtype and that it cannot be changed
                                    // which is what we want for the built-in properties.
                                    propDbType.Success,
                                    propertyTypeAlias));
        }
Example #17
0
        public void DefaultData_SetValue_Ensures_Empty_String_When_Null_Value_Any_Data_Type(DataTypeDatabaseType type)
        {
            var defaultData = new DefaultData(new Mock <BaseDataType>().Object);

            ((IDataValueSetter)defaultData).SetValue(null, type.ToString());

            Assert.AreEqual(string.Empty, defaultData.Value);
        }
Example #18
0
 public IDataTypeDefinition Create(string name, string propertyEditorAlias, int parentId,
                                   DataTypeDatabaseType databaseType)
 {
     return(Create(name, propertyEditorAlias, parentId, databaseType,
                   new Dictionary <string, string>()));
 }