コード例 #1
0
        void IMappingRule.Execute(IMappingSession session, MappingOptions options, object model, Type type, object source)
        {
            var content = source as IPublishedContent;

            if (content == null)
            {
                throw new Exception("Expected source type IPublishedContent");
            }

            if (_isLazy && (!options.IncludedProperties.ContainsKey(type) || !options.IncludedProperties[type].Contains(_propertyName)))
            {
                return;
            }

            var destProperty = type.GetProperty(_propertyName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public) ?? type.GetProperty(_propertyName);

            //set to empty list.  This will prevent loading the list again if the nested session.Map<> contains a circular reference
            destProperty.SetValue(model, new List <TModel>());

            var filtered = _filter(content);

            var collection = session.Map <TModel>(filtered).WithOptions(options).List();

            destProperty.SetValue(model, collection);
        }
コード例 #2
0
        void IMappingRule.Execute(IMappingSession session, MappingOptions options, object model, Type type, object source)
        {
            var destProperty = type.GetProperty(_propertyName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public) ?? type.GetProperty(_propertyName);

            var fieldset = source as ArchetypeFieldsetModel;

            if (fieldset == null)
            {
                return;
            }

            if (!fieldset.HasProperty(_propertyAlias) || !fieldset.HasValue(_propertyAlias))
            {
                return;
            }

            var srcValue = fieldset.GetValue <string>(_propertyAlias);

            var helper = new UmbracoHelper(UmbracoContext.Current);

            var node = _isMedia ? helper.TypedMedia(srcValue) : helper.TypedContent(srcValue);

            if (node == null)
            {
                //Orphan node reference, so ignore
                return;
            }

            var mappedNode = session.Map <TModel>(node).WithOptions(options).Single();

            destProperty.SetValue(model, mappedNode);
        }
コード例 #3
0
        void IMappingRule.Execute(IMappingSession session, MappingOptions options, object model, Type type, object source)
        {
            var relatedContent = session.Map <TModel>(_filter(new UmbracoHelper(UmbracoContext.Current))).WithOptions(options).Single();

            var destProperty = type.GetProperty(_propertyName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public) ?? type.GetProperty(_propertyName);

            destProperty.SetValue(model, relatedContent);
        }
        void IMappingRule.Execute(IMappingSession session, MappingOptions options, object model, Type type, object source)
        {
            if (_isLazy && (!options.IncludedProperties.ContainsKey(type) || !options.IncludedProperties[type].Contains(_propertyName)))
            {
                return;
            }

            var filtered = _filter(new UmbracoHelper(UmbracoContext.Current));

            var collection = session.Map <TModel>(filtered).WithOptions(options).List();

            var destProperty = type.GetProperty(_propertyName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public) ?? type.GetProperty(_propertyName);

            destProperty.SetValue(model, collection);
        }
コード例 #5
0
        void IMappingRule.Execute(IMappingSession session, MappingOptions options, object model, Type type, object source)
        {
            var content = source as IPublishedContent;

            if (content == null)
            {
                throw new Exception("Expected source type IPublishedContent");
            }

            var relatedContent = session.Map <TModel>(_filter(content)).WithOptions(options).Single();

            var destProperty = type.GetProperty(_propertyName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public) ?? type.GetProperty(_propertyName);

            destProperty.SetValue(model, relatedContent);
        }
コード例 #6
0
        void IMappingRule.Execute(IMappingSession session, MappingOptions options, object model, Type type, object source)
        {
            var dataTypeService = UmbracoContext.Current.Application.Services.DataTypeService;
            var destProperty    = type.GetProperty(_propertyName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public) ?? type.GetProperty(_propertyName);

            ArchetypeModel      srcValue;
            IDataTypeDefinition dataTypeDefinition;

            if (source is ArchetypeFieldsetModel)
            {
                var fieldSet = source as ArchetypeFieldsetModel;
                var property = fieldSet.Properties.FirstOrDefault(x => x.Alias == _propertyAlias);

                srcValue           = fieldSet.GetValue <ArchetypeModel>(_propertyAlias);
                dataTypeDefinition = dataTypeService.GetDataTypeDefinitionById(property.DataTypeId);
            }

            else
            {
                var content     = source as IPublishedContent;
                var srcProperty = content.GetProperty(_propertyAlias);

                if (srcProperty == null)
                {
                    return;
                }

                var propertyType = content.ContentType.GetPropertyType(_propertyAlias);

                dataTypeDefinition = dataTypeService.GetDataTypeDefinitionById(propertyType.DataTypeId);

                srcValue = srcProperty.Value as ArchetypeModel;
            }

            if (srcValue == null)
            {
                return;
            }

            if (!srcValue.Any())
            {
                return;
            }

            var archetypeModel = session.Map <T>(srcValue, dataTypeDefinition.Name).Single();

            destProperty.SetValue(model, archetypeModel);
        }
コード例 #7
0
        void IMappingRule.Execute(IMappingSession session, MappingOptions options, object model, Type type, object source)
        {
            var content = source as IPublishedContent;

            if (content == null)
            {
                throw new Exception("Expected source type IPublishedContent");
            }

            var destProperty = type.GetProperty(_propertyName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public) ?? type.GetProperty(_propertyName);

            var srcProperty = content.GetProperty(_propertyAlias);

            if ((srcProperty == null) || !srcProperty.HasValue)
            {
                return;
            }

            var srcValue = srcProperty.Value;

            var helper = new UmbracoHelper(UmbracoContext.Current);

            try
            {
                var node = _isMedia ? helper.TypedMedia(srcValue) : helper.TypedContent(srcValue);

                if (node == null)
                {
                    //Orphan node reference, so ignore
                    return;
                }

                var mappedNode = session.Map <TModel>(node).WithOptions(options).Single();

                destProperty.SetValue(model, mappedNode);
            }

            catch
            {
                //suppress error The valueDictionary is not formatted correctly and is missing any of the  'id,nodeId,__NodeId' elements until fix in 7.2
            }
        }
コード例 #8
0
        public void Execute(IMappingSession session, MappingOptions options, object model, Type type, object source)
        {
            var destProperty = type.GetProperty(_propertyName, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public) ?? type.GetProperty(_propertyName);

            var content = source as IPublishedContent;

            if (content == null)
            {
                return;
            }

            if (_isLazy && (!options.IncludedProperties.ContainsKey(type) || !options.IncludedProperties[type].Contains(_propertyName)))
            {
                return;
            }

            var srcProperty = content.GetProperty(_propertyAlias);

            if ((srcProperty == null) || !srcProperty.HasValue)
            {
                return;
            }

            var srcValue = srcProperty.Value as string;

            var srcNodes = srcValue.Split(',');

            var helper = new UmbracoHelper(UmbracoContext.Current);

            var list = srcNodes.Select(x =>
            {
                var node = _isMedia ? helper.TypedMedia(x) : helper.TypedContent(x);

                return(node == null ? null : session.Map <TModel>(node).WithOptions(options).Single());
            }).Where(n => n != null).ToList();

            destProperty.SetValue(model, list);
        }