예제 #1
0
        private Dictionary <string, IPublishedProperty> MapProperties(PropertyEditorResolver resolver, ServiceContext services)
        {
            var contentType = this.contentType.Value;
            var properties  = this.content.Properties;

            var items = new Dictionary <string, IPublishedProperty>(StringComparer.InvariantCultureIgnoreCase);

            foreach (var propertyType in contentType.PropertyTypes)
            {
                var property = properties.FirstOrDefault(x => x.Alias.InvariantEquals(propertyType.PropertyTypeAlias));
                var value    = property?.Value;
                if (value != null)
                {
                    var propertyEditor = resolver.GetByAlias(propertyType.PropertyEditorAlias);
                    if (propertyEditor != null)
                    {
                        value = propertyEditor.ValueEditor.ConvertDbToString(property, property.PropertyType, services.DataTypeService);
                    }
                }

                items.Add(propertyType.PropertyTypeAlias, new UnpublishedProperty(propertyType, value));
            }

            return(items);
        }
        internal DataTypeInfo ResolveDataType(FluidityEditorFieldConfig fieldConfig, bool isReadOnly = false)
        {
            var dtdKey = !fieldConfig.DataTypeName.IsNullOrWhiteSpace()
                ? fieldConfig.DataTypeName
                : fieldConfig.GetOrCalculateDefinititionId().ToString();

            dtdKey += $"_{isReadOnly}";

            return(_cacheProvider.GetCacheItem <DataTypeInfo>($"fluidity_datatypeinfo_{dtdKey}", () =>
            {
                IDataTypeDefinition dataTypeDefinition = null;

                if (!fieldConfig.DataTypeName.IsNullOrWhiteSpace())
                {
                    dataTypeDefinition = _dataTypeService.GetDataTypeDefinitionByName(fieldConfig.DataTypeName);
                }

                if (dataTypeDefinition == null)
                {
                    var dataTypeId = fieldConfig.DataTypeId == 0 && isReadOnly
                        ? -92 // If readonly and no explicit datatype defined, default to label
                        : fieldConfig.GetOrCalculateDefinititionId();
                    dataTypeDefinition = _dataTypeService.GetDataTypeDefinitionById(dataTypeId);
                }

                var preValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id);
                var propEditor = _propertyEditorResolver.GetByAlias(dataTypeDefinition.PropertyEditorAlias);

                return new DataTypeInfo(dataTypeDefinition, propEditor, preValues);
            }));
        }
예제 #3
0
        internal DataTypeInfo ResolveDataType(FluidityEditorFieldConfig fieldConfig)
        {
            var dtdKey = !fieldConfig.DataTypeName.IsNullOrWhiteSpace()
                ? fieldConfig.DataTypeName
                : fieldConfig.GetOrCalculateDefinititionId().ToString();

            return(_cacheProvider.GetCacheItem <DataTypeInfo>($"fluidity_datatypeinfo_{dtdKey}", () =>
            {
                IDataTypeDefinition dataTypeDefinition = null;

                if (!fieldConfig.DataTypeName.IsNullOrWhiteSpace())
                {
                    dataTypeDefinition = _dataTypeService.GetDataTypeDefinitionByName(fieldConfig.DataTypeName);
                }

                if (dataTypeDefinition == null)
                {
                    var dataTypeId = fieldConfig.GetOrCalculateDefinititionId();
                    dataTypeDefinition = _dataTypeService.GetDataTypeDefinitionById(dataTypeId);
                }

                var preValues = _dataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeDefinition.Id);
                var propEditor = _propertyEditorResolver.GetByAlias(dataTypeDefinition.PropertyEditorAlias);

                return new DataTypeInfo(dataTypeDefinition, propEditor, preValues);
            }));
        }
예제 #4
0
        /// <summary>
        /// The map properties.
        /// </summary>
        /// <param name="propertyTypes">
        /// The property types.
        /// </param>
        /// <param name="properties">
        /// The properties.
        /// </param>
        /// <param name="map">
        /// The map.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{T}"/>.
        /// </returns>
        internal static IEnumerable <IPublishedProperty> MapProperties(
            IEnumerable <PublishedPropertyType> propertyTypes,
            IEnumerable <Property> properties,
            Func <PublishedPropertyType, object, IPublishedProperty> map)
        {
            PropertyEditorResolver propertyEditorResolver = PropertyEditorResolver.Current;
            IDataTypeService       dataTypeService        = ApplicationContext.Current.Services.DataTypeService;

            return(propertyTypes.Select(
                       x =>
            {
                Property p = properties.SingleOrDefault(xx => xx.Alias == x.PropertyTypeAlias);
                object v = p?.Value;

                if (v == null)
                {
                    return map(x, v);
                }

                PropertyEditor e = propertyEditorResolver.GetByAlias(x.PropertyEditorAlias);

                // We are converting to string, even for database values which are integer or
                // DateTime, which is not optimum. Doing differently would require that we have a way to tell
                // whether the conversion to XML string changes something or not... which we don't, and we
                // don't want to implement it as PropertyValueEditor.ConvertDbToXml/String should die anyway.

                // Don't think about improving the situation here: this is a corner case and the real
                // thing to do is to get rig of PropertyValueEditor.ConvertDbToXml/String.

                // Use ConvertDbToString to keep it simple, although everywhere we use ConvertDbToXml and
                // nothing ensures that the two methods are consistent.
                if (e != null)
                {
                    v = e.ValueEditor.ConvertDbToString(p, p.PropertyType, dataTypeService);
                }

                return map(x, v);
            }));
        }