Beispiel #1
0
 protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
 {
     Ditto.IsDebuggingEnabled = Ditto.GetDebugFlag();
 }
Beispiel #2
0
        /// <summary>
        /// Processes the value.
        /// </summary>
        /// <returns>
        /// The <see cref="object" /> representing the processed value.
        /// </returns>
        public override object ProcessValue()
        {
            var defaultValue = this.DefaultValue;

            var recursive   = this.Recursive;
            var propName    = this.Context.PropertyInfo != null ? this.Context.PropertyInfo.Name : string.Empty;
            var altPropName = string.Empty;

            // Check for Umbraco properties attribute on class
            if (Ditto.TryGetTypeAttribute(this.Context.TargetType, out UmbracoPropertiesAttribute classAttr))
            {
                // Apply the prefix
                if (string.IsNullOrWhiteSpace(classAttr.Prefix) == false)
                {
                    altPropName = propName;
                    propName    = classAttr.Prefix + propName;
                }

                // Apply global recursive setting
                recursive |= classAttr.Recursive;

                // Apply property source only if it's different from the default,
                // and the current value is the default. We only do it this
                // way because if they change it at the property level, we
                // want that to take precedence over the class level.
                if (classAttr.PropertySource != Ditto.DefaultPropertySource && PropertySource == Ditto.DefaultPropertySource)
                {
                    PropertySource = classAttr.PropertySource;
                }
            }

            var umbracoPropertyName    = this.PropertyName ?? propName;
            var altUmbracoPropertyName = this.AltPropertyName ?? altPropName;

            var content = this.Value as IPublishedContent;

            if (content == null)
            {
                return(defaultValue);
            }

            object propertyValue = null;

            // Try fetching the value.
            if (string.IsNullOrWhiteSpace(umbracoPropertyName) == false)
            {
                propertyValue = GetPropertyValue(content, umbracoPropertyName, recursive);
            }

            // Try fetching the alt value.
            if ((propertyValue == null || (propertyValue is string tmp && string.IsNullOrWhiteSpace(tmp))) &&
                string.IsNullOrWhiteSpace(altUmbracoPropertyName) == false)
            {
                propertyValue = GetPropertyValue(content, altUmbracoPropertyName, recursive);
            }

            // Try setting the default value.
            if ((propertyValue == null || (propertyValue is string tmp2 && string.IsNullOrWhiteSpace(tmp2))) &&
                defaultValue != null)
            {
                propertyValue = defaultValue;
            }

            return(propertyValue);
        }