Skip to content
This repository has been archived by the owner on Dec 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #231 from leekelleher/develop
Browse files Browse the repository at this point in the history
Preparing Ditto 0.11.3 release
  • Loading branch information
leekelleher authored Oct 3, 2017
2 parents 67da90c + f3a4c9d commit 28b08c9
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 60 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
os: Visual Studio 2015
image: Visual Studio 2017

# version format
version: 0.11.2.{build}
version: 0.11.3.{build}

# UMBRACO_PACKAGE_PRERELEASE_SUFFIX if a rtm release build this should be blank, otherwise if empty will default to alpha
# example UMBRACO_PACKAGE_PRERELEASE_SUFFIX=beta
Expand Down
3 changes: 2 additions & 1 deletion build/build-appveyor.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ ECHO APPVEYOR_BUILD_NUMBER : %APPVEYOR_BUILD_NUMBER%
ECHO APPVEYOR_BUILD_VERSION : %APPVEYOR_BUILD_VERSION%

CALL build\tools\NuGet.exe restore src\Our.Umbraco.Ditto.sln
CALL "%programfiles(x86)%\MSBuild\14.0\Bin\amd64\MsBuild.exe" build\package.proj
CALL "%programfiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MsBuild.exe" build\package.proj
REM CALL "%programfiles(x86)%\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\amd64\MsBuild.exe" build\package.proj
4 changes: 2 additions & 2 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ We also have a [MyGet package repository](https://www.myget.org/gallery/umbraco-

If you prefer, you can compile Ditto yourself, you'll need:

* [Visual Studio 2012 (or above, including Community Editions)](https://www.visualstudio.com/downloads/)
* Microsoft Build Tools 2013 (aka [MSBuild 12](https://www.microsoft.com/en-us/download/details.aspx?id=40760))
* [Visual Studio 2017 (or above, including Community Editions)](https://www.visualstudio.com/downloads/)
* Microsoft Build Tools 2015 (aka [MSBuild 15](https://www.microsoft.com/en-us/download/details.aspx?id=48159))

To clone it locally run the following git commands:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Our.Umbraco.Ditto
{
/// <summary>
/// Represents a multi-ditto processor capable of wrapping multiple attributes into a single attribute definition
/// Represents a multi-Ditto processor capable of wrapping multiple attributes into a single attribute definition.
/// </summary>
[AttributeUsage(Ditto.ProcessorAttributeTargets, AllowMultiple = true, Inherited = false)]
public abstract class DittoMultiProcessorAttribute : DittoProcessorAttribute
Expand Down Expand Up @@ -43,12 +43,15 @@ protected DittoMultiProcessorAttribute(IEnumerable<DittoProcessorAttribute> attr
/// </returns>
public override object ProcessValue()
{

foreach (var processorAttr in this.Attributes)
{
// Get the right context type
var newCtx = this.ChainContext.ProcessorContexts.GetOrCreate(this.Context, processorAttr.ContextType);

// Populate UmbracoContext & ApplicationContext
processorAttr.UmbracoContext = this.UmbracoContext;
processorAttr.ApplicationContext = this.ApplicationContext;

// Process value
this.Value = processorAttr.ProcessValue(this.Value, newCtx, this.ChainContext);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Globalization;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Services;
Expand All @@ -23,7 +22,7 @@ protected DittoProcessorAttribute()
var metaData = this.GetType().GetCustomAttribute<DittoProcessorMetaDataAttribute>(true);
if (metaData == null)
{
throw new ApplicationException("Ditto processor attributes require a DittoProcessorMetaData attribute to be applied to the class but none was found");
throw new ApplicationException("Ditto processor attributes require a DittoProcessorMetaData attribute to be applied to the class but none was found.");
}

this.ValueType = metaData.ValueType;
Expand Down Expand Up @@ -79,57 +78,57 @@ protected DittoProcessorAttribute()
internal Type ContextType { get; set; }

/// <summary>
/// Returns the MembershipHelper instance
/// Returns a new instance of MembershipHelper.
/// </summary>
protected MembershipHelper Members
{
get { return new MembershipHelper(UmbracoContext); }
}

/// <summary>
/// Returns the UmbracoHelper instance
/// Returns a new instance of UmbracoHelper.
/// </summary>
protected UmbracoHelper Umbraco
{
get { return new UmbracoHelper(UmbracoContext); }
}

/// <summary>
/// Returns an ILogger
/// Returns the current implementation of ILogger.
/// </summary>
protected ILogger Logger
{
get { return ProfilingLogger.Logger; }
}

/// <summary>
/// Returns a ProfilingLogger
/// Returns the current instance of ProfilingLogger.
/// </summary>
protected virtual ProfilingLogger ProfilingLogger
{
get { return ApplicationContext.ProfilingLogger; }
}

/// <summary>
/// Returns the current UmbracoContext
/// Returns the current instance of UmbracoContext.
/// </summary>
public virtual UmbracoContext UmbracoContext { get; internal set; }

/// <summary>
/// Returns the current ApplicationContext
/// Returns the current instance of ApplicationContext.
/// </summary>
public virtual ApplicationContext ApplicationContext { get; internal set; }

/// <summary>
/// Returns a ServiceContext
/// Returns the current instance of ServiceContext.
/// </summary>
protected ServiceContext Services
{
get { return ApplicationContext.Services; }
}

/// <summary>
/// Returns a DatabaseContext
/// Returns the current instance of DatabaseContext.
/// </summary>
protected DatabaseContext DatabaseContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public class DittoCacheContext
/// <param name="targetType">Type of the target.</param>
/// <param name="culture">The culture.</param>
internal DittoCacheContext(
DittoCacheableAttribute attribute,
IPublishedContent content,
Type targetType,
DittoCacheableAttribute attribute,
IPublishedContent content,
Type targetType,
CultureInfo culture)
: this(attribute, content, targetType, null, culture)
{ }
Expand All @@ -34,10 +34,10 @@ internal DittoCacheContext(
/// <param name="propertyDescriptor">The property descriptor.</param>
/// <param name="culture">The culture.</param>
internal DittoCacheContext(
DittoCacheableAttribute attribute,
IPublishedContent content,
Type targetType,
PropertyDescriptor propertyDescriptor,
DittoCacheableAttribute attribute,
IPublishedContent content,
Type targetType,
PropertyDescriptor propertyDescriptor,
CultureInfo culture)
{
this.Attribute = attribute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,14 @@ public override object ProcessValue()
}
else
{
types = (IEnumerable<Type>)ApplicationContext.Current.ApplicationCache.StaticCache.GetCacheItem(
string.Concat("DittoFactoryAttribute_ResolveTypes_", baseType.AssemblyQualifiedName),
types = (IEnumerable<Type>)ApplicationContext.ApplicationCache.StaticCache.GetCacheItem(
$"DittoFactoryAttribute_ResolveTypes_{baseType.AssemblyQualifiedName}",
() =>
{
// Workaround for http://issues.umbraco.org/issue/U4-9011
if (baseType.Assembly.IsAppCodeAssembly())
{
// This logic is taken from the core type finder so
// it should be performing the same checks
// This logic is taken from the core type finder so it should be performing the same checks.
return baseType.Assembly
.GetTypes()
.Where(t => baseType.IsAssignableFrom(t)
Expand All @@ -90,7 +89,7 @@ public override object ProcessValue()
&& !t.IsSealed
&& !t.IsNestedPrivate
&& t.GetCustomAttribute<HideFromTypeFinderAttribute>(true) == null)
.ToArray();
.ToArray();
}

// Find the appropriate types
Expand All @@ -99,13 +98,11 @@ public override object ProcessValue()
var method = typeof(PluginManager).GetMethod("ResolveTypes");
var generic = method.MakeGenericMethod(baseType);
return ((IEnumerable<Type>)generic.Invoke(PluginManager.Current, new object[] { true, null })).ToArray();

});
}

// Check for IEnumerable<IPublishedContent> value
var enumerableValue = this.Value as IEnumerable<IPublishedContent>;
if (enumerableValue != null)
if (this.Value is IEnumerable<IPublishedContent> enumerableValue && enumerableValue != null)
{
var items = enumerableValue.Select(x =>
{
Expand All @@ -119,12 +116,13 @@ public override object ProcessValue()
}

// Check for IPublishedContent value
var ipublishedContentValue = this.Value as IPublishedContent;
if (ipublishedContentValue != null)
if (this.Value is IPublishedContent ipublishedContentValue && ipublishedContentValue != null)
{
var typeName = this.ResolveTypeName(ipublishedContentValue);
var type = types.FirstOrDefault(y => y.Name.InvariantEquals(typeName));
return type != null ? ipublishedContentValue.As(type, chainContext: ChainContext) : null;
return type != null
? ipublishedContentValue.As(type, chainContext: ChainContext)
: null;
}

// No other possible options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Umbraco.Core;

namespace Our.Umbraco.Ditto
{
Expand Down Expand Up @@ -118,21 +119,21 @@ public void RegisterProcessorAttribute<TObjectType, TProcessorAttributeType>(TPr
}

/// <summary>
/// Gets the default processor attribute type for the given object type.
/// Gets the default processor for the given object type.
/// </summary>
/// <param name="objectType">Type of the object.</param>
/// <returns>
/// Returns the default processor attribute type for the given object type.
/// Returns the default processor for the given object type.
/// </returns>
public Type GetDefaultProcessorType(Type objectType)
public DittoProcessorAttribute GetDefaultProcessorFor(Type objectType)
{
var attr = objectType.GetCustomAttribute<DittoDefaultProcessorAttribute>();
if (attr != null)
{
return attr.ProcessorType;
return (DittoProcessorAttribute)attr.ProcessorType.GetInstance();
}

return DefaultProcessorType;
return (DittoProcessorAttribute)DefaultProcessorType.GetInstance();
}

/// <summary>
Expand Down Expand Up @@ -200,7 +201,7 @@ public void DeregisterPostProcessorType<TProcessorAttributeType>()
{
lock (PostProcessorTypesLock)
{
PostProcessorTypes.RemoveAll(x => x is TProcessorAttributeType);
PostProcessorTypes.RemoveAll(x => x == typeof(TProcessorAttributeType));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ public UmbracoPropertyAttribute(
string altPropertyName = null,
bool recursive = false,
object defaultValue = null)
: this()
{
this.PropertyName = propertyName;
this.AltPropertyName = altPropertyName;
this.Recursive = recursive;
this.DefaultValue = defaultValue;

PropertySource = Ditto.DefaultPropertySource;
}

/// <summary>
Expand Down Expand Up @@ -93,11 +92,11 @@ public override object ProcessValue()
var propName = this.Context.PropertyDescriptor != null ? this.Context.PropertyDescriptor.Name : string.Empty;
var altPropName = string.Empty;

// Check for umbraco properties attribute on class
// Check for Umbraco properties attribute on class
if (this.Context.TargetType != null)
{
var classAttr = this.Context.TargetType
.GetCustomAttribute<UmbracoPropertiesAttribute>();
// TODO: [LK:2017-09-26] Is there a way to optimise or avoid this?
var classAttr = this.Context.TargetType.GetCustomAttribute<UmbracoPropertiesAttribute>();
if (classAttr != null)
{
// Apply the prefix
Expand Down
3 changes: 2 additions & 1 deletion src/Our.Umbraco.Ditto/Ditto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public class Ditto
/// <summary>
/// A list of mappable properties defined on the IPublishedContent interface
/// </summary>
internal static readonly IEnumerable<PropertyInfo> IPublishedContentProperties = typeof(IPublishedContent).GetProperties(MappablePropertiesBindingFlags)
internal static readonly IEnumerable<PropertyInfo> IPublishedContentProperties = typeof(IPublishedContent)
.GetProperties(MappablePropertiesBindingFlags)
.Where(x => x.IsMappable())
.ToList();

Expand Down
Loading

0 comments on commit 28b08c9

Please sign in to comment.