public ArchetypeValueResolverShim(DittoValueResolverContext context, CultureInfo culture, ArchetypeValueResolverAttribute attribute) : base(context, new ArchetypeBindingService())
 {
     base.Context = context;
     base.Culture = culture;
     base.Content = context.Instance as IPublishedContent;
     base.Attribute = attribute;
 }
        public void SetUp()
        {
            _archetype = ContentHelpers.Archetype;

            var content = ContentHelpers.FakeContent(123, "Fake Node 1", properties: new Collection<IPublishedProperty>
            {
                new FakePublishedProperty("myArchetypeProperty", _archetype, true)
            });

            _content = new FakeModel(content);
            _propertyDescriptor = TypeDescriptor.GetProperties(_content)["TextString"];

            _context = new FakeDittoValueResolverContext(_content, _propertyDescriptor);

            var mockedPropertyService = new Mock<PropertyValueService>();

            mockedPropertyService.SetupSequence(
                i =>
                    i.Set(It.IsAny<IPublishedContent>(), It.IsAny<CultureInfo>(), It.IsAny<PropertyInfo>(),
                        It.IsAny<object>(), It.IsAny<object>(), It.IsAny<DittoValueResolverContext>()))
                        .Returns(new HtmlString("<p>This is the <strong>summary</strong> text.</p>"))
                        .Returns("Ready to Enroll?")
                        .Returns("{}");

            _sut = new ArchetypeBindingService(mockedPropertyService.Object, new DittoAliasLocator());
        }
 protected ParentContentValueResolver(DittoValueResolverAttribute attribute, IPublishedContent content, DittoValueResolverContext context)
 {
     Attribute = attribute;
     Content = content;
     Context = context;
     Culture = new CultureInfo("en-GB");
 }
 public void TearDown()
 {
     _sut = null;
     _archetype = null;
     _content = null;
     _propertyDescriptor = null;
     _context = null;
 }
예제 #5
0
        /// <summary>
        /// Gets the raw value for the current property from Umbraco.
        /// </summary>
        /// <param name="context">
        /// An <see cref="DittoValueResolverContext" /> that provides a context.
        /// </param>
        /// <param name="attribute">
        /// The <see cref="DittoValueResolverAttribute"/> containing additional information
        /// indicating how to resolve the property.
        /// </param>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture.</param>
        /// <returns>
        /// The <see cref="object"/> representing the raw value.
        /// </returns>
        internal virtual object ResolveValue(
            DittoValueResolverContext context,
            DittoValueResolverAttribute attribute,
            CultureInfo culture)
        {
            this.Content   = context.Instance as IPublishedContent;
            this.Context   = context;
            this.Attribute = attribute;
            this.Culture   = culture;

            return(this.ResolveValue());
        }
예제 #6
0
        /// <summary>
        /// Gets the raw value for the current property from Umbraco.
        /// </summary>
        /// <param name="context">
        /// An <see cref="DittoValueResolverContext" /> that provides a context.
        /// </param>
        /// <param name="attribute">
        /// The <see cref="DittoValueResolverAttribute"/> containing additional information 
        /// indicating how to resolve the property.
        /// </param>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture.</param>
        /// <returns>
        /// The <see cref="object"/> representing the raw value.
        /// </returns>
        internal virtual object ResolveValue(
            DittoValueResolverContext context,
            DittoValueResolverAttribute attribute,
            CultureInfo culture)
        {
            this.Content = context.Instance as IPublishedContent;
            this.Context = context;
            this.Attribute = attribute;
            this.Culture = culture;

            return this.ResolveValue();
        }
        /// <summary>
        /// Get the value using the Ditto GetTypedValue method on PublishedContentExtensions via reflection (breakable)
        /// </summary>
        /// <param name="content"></param>
        /// <param name="culture"></param>
        /// <param name="propertyInfo"></param>
        /// <param name="propertyValue"></param>
        /// <param name="instance"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override object Set(IPublishedContent content, CultureInfo culture, PropertyInfo propertyInfo, object propertyValue, object instance, DittoValueResolverContext context)
        {
            object result = null;

            var dynMethod = _getTypedValue.Value;

            if (dynMethod != null)
            {
                result = dynMethod.Invoke(this, new [] { content, culture, propertyInfo, propertyValue, instance });
            }

            return result;
        }
예제 #8
0
        /// <summary>
        /// Returns the resolved value for the given type and property.
        /// </summary>
        /// <param name="content">The <see cref="IPublishedContent"/> to convert.</param>
        /// <param name="culture">The <see cref="CultureInfo"/></param>
        /// <param name="propertyInfo">The <see cref="PropertyInfo"/> property info associated with the type.</param>
        /// <param name="instance">The instance to assign the value to.</param>
        /// <param name="valueResolverContexts">
        /// A collection of <see cref="DittoValueResolverContext"/> entities to use whilst resolving values.
        /// </param>
        /// <returns>The <see cref="object"/> representing the Umbraco value.</returns>
        private static object GetResolvedValue(
            IPublishedContent content,
            CultureInfo culture,
            PropertyInfo propertyInfo,
            object instance,
            IEnumerable <DittoValueResolverContext> valueResolverContexts = null)
        {
            // Check the property for an associated value attribute, otherwise fall-back on expected behaviour.
            var valueAttr = propertyInfo.GetCustomAttribute <DittoValueResolverAttribute>(true);

            if (valueAttr == null)
            {
                // Check for globally registered resolver
                valueAttr = DittoValueResolverRegistry.Instance.GetRegisteredResolverAttributeFor(propertyInfo.PropertyType);
            }

            if (valueAttr == null)
            {
                // Default to umbraco property attribute
                valueAttr = new UmbracoPropertyAttribute();
            }

            // Time custom value-resolver.
            using (DittoDisposableTimer.DebugDuration <object>(string.Format("Custom ValueResolver ({0}, {1})", content.Id, propertyInfo.Name)))
            {
                var resolver = (DittoValueResolver)valueAttr.ResolverType.GetInstance();

                DittoValueResolverContext context = null;

                // Get the value from the custom attribute.
                // TODO: Cache these?
                var resolverTypeInstances = valueAttr.ResolverType.GetGenericTypeImplementations(typeof(DittoValueResolver <,>)).ToArray();
                if (resolverTypeInstances.Length == 1)
                {
                    var contextType = resolverTypeInstances[0].GetGenericArguments().FirstOrDefault(x => typeof(DittoValueResolverContext).IsAssignableFrom(x));
                    if (contextType != null)
                    {
                        var resolverContext = valueResolverContexts != null?valueResolverContexts.FirstOrDefault(x => x.GetType() == contextType) : null;

                        if (resolverContext != null)
                        {
                            context = resolverContext;
                        }
                        else
                        {
                            context = (DittoValueResolverContext)contextType.GetInstance();
                        }
                    }
                }

                // No context found so create a default one
                if (context == null)
                {
                    context = new DittoValueResolverContext();
                }

                // Populate internal context properties
                context.ConversionType     = instance.GetType();
                context.Instance           = content;
                context.PropertyDescriptor = TypeDescriptor.GetProperties(instance)[propertyInfo.Name];

                // Resolve value
                return(resolver.ResolveValue(context, valueAttr, culture));
            }
        }
 /// <summary>
 /// SGets the converted value from the Umbraco property value
 /// </summary>
 /// <param name="content"></param>
 /// <param name="culture"></param>
 /// <param name="propertyInfo"></param>
 /// <param name="propertyValue"></param>
 /// <param name="instance"></param>
 /// <param name="context"></param>
 /// <returns></returns>
 public abstract object Set(IPublishedContent content, CultureInfo culture, PropertyInfo propertyInfo, object propertyValue, object instance, DittoValueResolverContext context);
 public ParentContentValueResolverShim(DittoValueResolverAttribute attribute, IPublishedContent content, DittoValueResolverContext context) : base(attribute, content, context)
 {
     
 }