Merge remote-tracking branch 'origin/v8/dev' into v8/feature/media-tracking

# Conflicts:
#	src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs
#	src/Umbraco.Core/Models/RelationType.cs
#	src/Umbraco.Web/PropertyEditors/NestedContentPropertyEditor.cs
#	src/Umbraco.Web/UmbracoComponentRenderer.cs
This commit is contained in:
Shannon
2019-12-18 15:28:27 +11:00
275 changed files with 4520 additions and 3266 deletions

View File

@@ -18,19 +18,52 @@ namespace Umbraco.Core.Composing
private readonly Composition _composition;
private readonly IProfilingLogger _logger;
private readonly IEnumerable<Type> _composerTypes;
private readonly IEnumerable<Attribute> _enableDisableAttributes;
private const int LogThresholdMilliseconds = 100;
/// <summary>
/// Initializes a new instance of the <see cref="Composers"/> class.
/// Initializes a new instance of the <see cref="Composers" /> class.
/// </summary>
/// <param name="composition">The composition.</param>
/// <param name="composerTypes">The composer types.</param>
/// <param name="logger">A profiling logger.</param>
/// <param name="composerTypes">The <see cref="IComposer" /> types.</param>
/// <param name="logger">The profiling logger.</param>
[Obsolete("This overload only gets the EnableComposer/DisableComposer attributes from the composerTypes assemblies.")]
public Composers(Composition composition, IEnumerable<Type> composerTypes, IProfilingLogger logger)
: this(composition, composerTypes, Enumerable.Empty<Attribute>(), logger)
{
var enableDisableAttributes = new List<Attribute>();
var assemblies = composerTypes.Select(t => t.Assembly).Distinct();
foreach (var assembly in assemblies)
{
enableDisableAttributes.AddRange(assembly.GetCustomAttributes(typeof(EnableComposerAttribute)));
enableDisableAttributes.AddRange(assembly.GetCustomAttributes(typeof(DisableComposerAttribute)));
}
_enableDisableAttributes = enableDisableAttributes;
}
/// <summary>
/// Initializes a new instance of the <see cref="Composers" /> class.
/// </summary>
/// <param name="composition">The composition.</param>
/// <param name="composerTypes">The <see cref="IComposer" /> types.</param>
/// <param name="enableDisableAttributes">The <see cref="EnableComposerAttribute" /> and/or <see cref="DisableComposerAttribute" /> attributes.</param>
/// <param name="logger">The profiling logger.</param>
/// <exception cref="ArgumentNullException">composition
/// or
/// composerTypes
/// or
/// enableDisableAttributes
/// or
/// logger</exception>
public Composers(Composition composition, IEnumerable<Type> composerTypes, IEnumerable<Attribute> enableDisableAttributes, IProfilingLogger logger)
{
_composition = composition ?? throw new ArgumentNullException(nameof(composition));
_composerTypes = composerTypes ?? throw new ArgumentNullException(nameof(composerTypes));
_enableDisableAttributes = enableDisableAttributes ?? throw new ArgumentNullException(nameof(enableDisableAttributes));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
@@ -103,7 +136,7 @@ namespace Umbraco.Core.Composing
.ToList();
// enable or disable composers
EnableDisableComposers(composerTypeList);
EnableDisableComposers(_enableDisableAttributes, composerTypeList);
void GatherInterfaces<TAttribute>(Type type, Func<TAttribute, Type> getTypeInAttribute, HashSet<Type> iset, List<Type> set2)
where TAttribute : Attribute
@@ -218,7 +251,7 @@ namespace Umbraco.Core.Composing
return text.ToString();
}
private static void EnableDisableComposers(ICollection<Type> types)
private static void EnableDisableComposers(IEnumerable<Attribute> enableDisableAttributes, ICollection<Type> types)
{
var enabled = new Dictionary<Type, EnableInfo>();
@@ -240,20 +273,16 @@ namespace Umbraco.Core.Composing
enableInfo.Weight = weight2;
}
var assemblies = types.Select(x => x.Assembly).Distinct();
foreach (var assembly in assemblies)
foreach (var attr in enableDisableAttributes.OfType<EnableComposerAttribute>())
{
foreach (var attr in assembly.GetCustomAttributes<EnableComposerAttribute>())
{
var type = attr.EnabledType;
UpdateEnableInfo(type, 2, enabled, true);
}
var type = attr.EnabledType;
UpdateEnableInfo(type, 2, enabled, true);
}
foreach (var attr in assembly.GetCustomAttributes<DisableComposerAttribute>())
{
var type = attr.DisabledType;
UpdateEnableInfo(type, 2, enabled, false);
}
foreach (var attr in enableDisableAttributes.OfType<DisableComposerAttribute>())
{
var type = attr.DisabledType;
UpdateEnableInfo(type, 2, enabled, false);
}
foreach (var composerType in types)

View File

@@ -1,4 +1,5 @@
using System;
using System.Runtime.Serialization;
using System.Text;
namespace Umbraco.Core.Composing.LightInject
@@ -6,20 +7,51 @@ namespace Umbraco.Core.Composing.LightInject
/// <summary>
/// Represents errors that occur due to LightInject.
/// </summary>
/// <seealso cref="System.Exception" />
[Serializable]
public class LightInjectException : Exception
{
public LightInjectException(string message)
: base(message)
{ }
public LightInjectException(string message, Exception innerException)
: base(message, innerException)
{ }
private const string LightInjectUnableToResolveType = "Unable to resolve type:";
private const string LightInjectUnresolvedDependency = "Unresolved dependency ";
private const string LightInjectRequestedDependency = "[Requested dependency:";
/// <summary>
/// Initializes a new instance of the <see cref="LightInjectException" /> class.
/// </summary>
public LightInjectException()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="LightInjectException" /> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public LightInjectException(string message)
: base(message)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="LightInjectException" /> class.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (<see langword="Nothing" /> in Visual Basic) if no inner exception is specified.</param>
public LightInjectException(string message, Exception innerException)
: base(message, innerException)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="LightInjectException"/> class.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination.</param>
protected LightInjectException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
/// <summary>
/// Tries to throw the exception with additional details.
/// </summary>
/// <param name="e">The exception.</param>
/// <exception cref="Umbraco.Core.Composing.LightInject.LightInjectException"></exception>
public static void TryThrow(Exception e)
{
var ex = e as InvalidOperationException;
@@ -32,6 +64,12 @@ namespace Umbraco.Core.Composing.LightInject
throw new LightInjectException(sb.ToString(), e);
}
/// <summary>
/// Tries to throw the exception with additional details.
/// </summary>
/// <param name="e">The exception.</param>
/// <param name="implementingType">The implementing type.</param>
/// <exception cref="Umbraco.Core.Composing.LightInject.LightInjectException"></exception>
public static void TryThrow(Exception e, Type implementingType)
{
var ex = e as InvalidOperationException;
@@ -45,6 +83,11 @@ namespace Umbraco.Core.Composing.LightInject
throw new LightInjectException(sb.ToString(), e);
}
/// <summary>
/// Writes the details.
/// </summary>
/// <param name="ex">The exception.</param>
/// <param name="sb">The <see cref="StringBuilder" /> to write the details to.</param>
private static void WriteDetails(InvalidOperationException ex, StringBuilder sb)
{
ex = ex.InnerException as InvalidOperationException;

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text;
using System.Threading;
using System.Web;
@@ -505,6 +506,49 @@ namespace Umbraco.Core.Composing
#endregion
#region Get Assembly Attributes
/// <summary>
/// Gets the assembly attributes of the specified type <typeparamref name="T" />.
/// </summary>
/// <typeparam name="T">The attribute type.</typeparam>
/// <returns>
/// The assembly attributes of the specified type <typeparamref name="T" />.
/// </returns>
public IEnumerable<T> GetAssemblyAttributes<T>()
where T : Attribute
{
return AssembliesToScan.SelectMany(a => a.GetCustomAttributes<T>()).ToList();
}
/// <summary>
/// Gets all the assembly attributes.
/// </summary>
/// <returns>
/// All assembly attributes.
/// </returns>
public IEnumerable<Attribute> GetAssemblyAttributes()
{
return AssembliesToScan.SelectMany(a => a.GetCustomAttributes()).ToList();
}
/// <summary>
/// Gets the assembly attributes of the specified <paramref name="attributeTypes" />.
/// </summary>
/// <param name="attributeTypes">The attribute types.</param>
/// <returns>
/// The assembly attributes of the specified types.
/// </returns>
/// <exception cref="ArgumentNullException">attributeTypes</exception>
public IEnumerable<Attribute> GetAssemblyAttributes(params Type[] attributeTypes)
{
if (attributeTypes == null) throw new ArgumentNullException(nameof(attributeTypes));
return AssembliesToScan.SelectMany(a => attributeTypes.SelectMany(at => a.GetCustomAttributes(at))).ToList();
}
#endregion
#region Get Types
/// <summary>
@@ -813,11 +857,44 @@ namespace Umbraco.Core.Composing
}
/// <summary>
/// Represents the error that occurs when a type was not found in the cache type
/// list with the specified TypeResolutionKind.
/// Represents the error that occurs when a type was not found in the cache type list with the specified TypeResolutionKind.
/// </summary>
/// <seealso cref="System.Exception" />
[Serializable]
internal class CachedTypeNotFoundInFileException : Exception
{ }
{
/// <summary>
/// Initializes a new instance of the <see cref="CachedTypeNotFoundInFileException" /> class.
/// </summary>
public CachedTypeNotFoundInFileException()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="CachedTypeNotFoundInFileException" /> class.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public CachedTypeNotFoundInFileException(string message)
: base(message)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="CachedTypeNotFoundInFileException" /> class.
/// </summary>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference (<see langword="Nothing" /> in Visual Basic) if no inner exception is specified.</param>
public CachedTypeNotFoundInFileException(string message, Exception innerException)
: base(message, innerException)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="CachedTypeNotFoundInFileException" /> class.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination.</param>
protected CachedTypeNotFoundInFileException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
}
#endregion
}