Move IContextCache parameter to base Deploy interfaces and add checksum to artifact dependency (#15144)

* Move IContextCache parameter to base interfaces

* Add checksum to artifact dependency
This commit is contained in:
Ronald Barendse
2023-11-06 18:05:02 +01:00
committed by GitHub
parent 5f3c0c56cc
commit e7bab6995a
11 changed files with 52 additions and 310 deletions

View File

@@ -1,42 +1,64 @@
using System.Text.Json.Serialization;
namespace Umbraco.Cms.Core.Deploy;
/// <summary>
/// Represents an artifact dependency.
/// Represents an artifact dependency.
/// </summary>
/// <remarks>
/// <para>Dependencies have an order property which indicates whether it must be respected when ordering artifacts.</para>
/// <para>
/// Dependencies have a mode which can be <c>Match</c> or <c>Exist</c> depending on whether the checksum should
/// match.
/// </para>
/// <para>
/// Dependencies have an order property which indicates whether it must be respected when ordering artifacts.
/// </para>
/// <para>
/// Dependencies have a mode which can be <see cref="ArtifactDependencyMode.Match" /> or <see cref="ArtifactDependencyMode.Exist" /> depending on whether the checksum should match.
/// </para>
/// </remarks>
public class ArtifactDependency
{
/// <summary>
/// Initializes a new instance of the ArtifactDependency class with an entity identifier and a mode.
/// Initializes a new instance of the <see cref="ArtifactDependency" /> class.
/// </summary>
/// <param name="udi">The entity identifier of the artifact that is a dependency.</param>
/// <param name="udi">The entity identifier of the artifact dependency.</param>
/// <param name="ordering">A value indicating whether the dependency is ordering.</param>
/// <param name="mode">The dependency mode.</param>
public ArtifactDependency(Udi udi, bool ordering, ArtifactDependencyMode mode)
/// <param name="checksum">The checksum.</param>
public ArtifactDependency(Udi udi, bool ordering, ArtifactDependencyMode mode, string? checksum = null)
{
Udi = udi;
Ordering = ordering;
Mode = mode;
Checksum = checksum;
}
/// <summary>
/// Gets the entity id of the artifact that is a dependency.
/// Gets the entity identifier of the artifact dependency.
/// </summary>
/// <value>
/// The entity identifier of the artifact dependency.
/// </value>
public Udi Udi { get; }
/// <summary>
/// Gets a value indicating whether the dependency is ordering.
/// Gets a value indicating whether the dependency is ordering.
/// </summary>
/// <value>
/// <c>true</c> if the dependency is ordering; otherwise, <c>false</c>.
/// </value>
public bool Ordering { get; }
/// <summary>
/// Gets the dependency mode.
/// Gets the dependency mode.
/// </summary>
/// <value>
/// The dependency mode.
/// </value>
public ArtifactDependencyMode Mode { get; }
/// <summary>
/// Gets the checksum.
/// </summary>
/// <value>
/// The checksum.
/// </value>
public string? Checksum { get; }
}

View File

@@ -1,48 +0,0 @@
using Umbraco.Cms.Core.Models;
namespace Umbraco.Cms.Core.Deploy;
/// <summary>
/// Extension methods adding backwards-compatability between <see cref="IDataTypeConfigurationConnector" /> and <see cref="IDataTypeConfigurationConnector2" />.
/// </summary>
/// <remarks>
/// These extension methods will be removed in Umbraco 13.
/// </remarks>
public static class DataTypeConfigurationConnectorExtensions
{
/// <summary>
/// Gets the artifact configuration value corresponding to a data type configuration and gather dependencies.
/// </summary>
/// <param name="connector">The connector.</param>
/// <param name="dataType">The data type.</param>
/// <param name="dependencies">The dependencies.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The artifact configuration value.
/// </returns>
/// <remarks>
/// This extension method tries to make use of the <see cref="IContextCache" /> on types also implementing <see cref="IDataTypeConfigurationConnector2" />.
/// </remarks>
public static string? ToArtifact(this IDataTypeConfigurationConnector connector, IDataType dataType, ICollection<ArtifactDependency> dependencies, IContextCache contextCache)
=> connector is IDataTypeConfigurationConnector2 connector2
? connector2.ToArtifact(dataType, dependencies, contextCache)
: connector.ToArtifact(dataType, dependencies);
/// <summary>
/// Gets the data type configuration corresponding to an artifact configuration value.
/// </summary>
/// <param name="connector">The connector.</param>
/// <param name="dataType">The data type.</param>
/// <param name="configuration">The artifact configuration value.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The data type configuration.
/// </returns>
/// <remarks>
/// This extension method tries to make use of the <see cref="IContextCache" /> on types also implementing <see cref="IDataTypeConfigurationConnector2" />.
/// </remarks>
public static object? FromArtifact(this IDataTypeConfigurationConnector connector, IDataType dataType, string? configuration, IContextCache contextCache)
=> connector is IDataTypeConfigurationConnector2 connector2
? connector2.FromArtifact(dataType, configuration, contextCache)
: connector.FromArtifact(dataType, configuration);
}

View File

@@ -24,20 +24,20 @@ public interface IDataTypeConfigurationConnector
/// </summary>
/// <param name="dataType">The data type.</param>
/// <param name="dependencies">The dependencies.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The artifact configuration value.
/// </returns>
[Obsolete($"Implement {nameof(IDataTypeConfigurationConnector2)} and use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")]
string? ToArtifact(IDataType dataType, ICollection<ArtifactDependency> dependencies);
string? ToArtifact(IDataType dataType, ICollection<ArtifactDependency> dependencies, IContextCache contextCache);
/// <summary>
/// Gets the data type configuration corresponding to an artifact configuration value.
/// </summary>
/// <param name="dataType">The data type.</param>
/// <param name="configuration">The artifact configuration value.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The data type configuration.
/// </returns>
[Obsolete($"Implement {nameof(IDataTypeConfigurationConnector2)} and use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")]
object? FromArtifact(IDataType dataType, string? configuration);
object? FromArtifact(IDataType dataType, string? configuration, IContextCache contextCache);
}

View File

@@ -1,56 +0,0 @@
using Umbraco.Cms.Core.Models;
namespace Umbraco.Cms.Core.Deploy;
/// <inheritdoc />
/// <remarks>
/// This interface will be merged back into <see cref="IDataTypeConfigurationConnector" /> and removed in Umbraco 13.
/// </remarks>
public interface IDataTypeConfigurationConnector2 : IDataTypeConfigurationConnector
{
/// <summary>
/// Gets the artifact configuration value corresponding to a data type configuration and gather dependencies.
/// </summary>
/// <param name="dataType">The data type.</param>
/// <param name="dependencies">The dependencies.</param>
/// <returns>
/// The artifact configuration value.
/// </returns>
[Obsolete($"Use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")]
string? IDataTypeConfigurationConnector.ToArtifact(IDataType dataType, ICollection<ArtifactDependency> dependencies)
=> ToArtifact(dataType, dependencies, PassThroughCache.Instance);
/// <summary>
/// Gets the artifact configuration value corresponding to a data type configuration and gather dependencies.
/// </summary>
/// <param name="dataType">The data type.</param>
/// <param name="dependencies">The dependencies.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The artifact configuration value.
/// </returns>
string? ToArtifact(IDataType dataType, ICollection<ArtifactDependency> dependencies, IContextCache contextCache);
/// <summary>
/// Gets the data type configuration corresponding to an artifact configuration value.
/// </summary>
/// <param name="dataType">The data type.</param>
/// <param name="configuration">The artifact configuration value.</param>
/// <returns>
/// The data type configuration.
/// </returns>
[Obsolete($"Use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")]
object? IDataTypeConfigurationConnector.FromArtifact(IDataType dataType, string? configuration)
=> FromArtifact(dataType, configuration, PassThroughCache.Instance);
/// <summary>
/// Gets the data type configuration corresponding to an artifact configuration value.
/// </summary>
/// <param name="dataType">The data type.</param>
/// <param name="configuration">The artifact configuration value.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The data type configuration.
/// </returns>
object? FromArtifact(IDataType dataType, string? configuration, IContextCache contextCache);
}

View File

@@ -12,21 +12,21 @@ public interface IServiceConnector : IDiscoverable
/// Gets an artifact.
/// </summary>
/// <param name="udi">The entity identifier of the artifact.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The corresponding artifact, or null.
/// </returns>
[Obsolete($"Implement {nameof(IServiceConnector2)} and use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")]
IArtifact? GetArtifact(Udi udi);
IArtifact? GetArtifact(Udi udi, IContextCache contextCache);
/// <summary>
/// Gets an artifact.
/// </summary>
/// <param name="entity">The entity.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The corresponding artifact.
/// </returns>
[Obsolete($"Implement {nameof(IServiceConnector2)} and use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")]
IArtifact GetArtifact(object entity);
IArtifact GetArtifact(object entity, IContextCache contextCache);
/// <summary>
/// Initializes processing for an artifact.
@@ -47,10 +47,10 @@ public interface IServiceConnector : IDiscoverable
void Process(ArtifactDeployState dart, IDeployContext context, int pass);
/// <summary>
/// Explodes a range into udis.
/// Explodes a range into UDIs.
/// </summary>
/// <param name="range">The range.</param>
/// <param name="udis">The list of udis where to add the new udis.</param>
/// <param name="udis">The list of UDIs where to add the new UDIs.</param>
/// <remarks>
/// Also, it's cool to have a method named Explode. Kaboom!
/// </remarks>
@@ -78,9 +78,9 @@ public interface IServiceConnector : IDiscoverable
/// <remarks>
/// <para>This is temporary. At least we thought it would be, in sept. 2016. What day is it now?</para>
/// <para>
/// At the moment our UI has a hard time returning proper udis, mainly because Core's tree do
/// not manage guids but only ints... so we have to provide a way to support it. The string id here
/// can be either a real string (for string udis) or an "integer as a string", using the value "-1" to
/// At the moment our UI has a hard time returning proper UDIs, mainly because Core's tree do
/// not manage GUIDs but only integers... so we have to provide a way to support it. The string id here
/// can be either a real string (for string UDIs) or an "integer as a string", using the value "-1" to
/// indicate the "root" i.e. an open udi.
/// </para>
/// </remarks>

View File

@@ -1,38 +0,0 @@
namespace Umbraco.Cms.Core.Deploy;
/// <inheritdoc />
/// <remarks>
/// This interface will be merged back into <see cref="IServiceConnector" /> and removed in Umbraco 13.
/// </remarks>
public interface IServiceConnector2 : IServiceConnector
{
/// <inheritdoc />
[Obsolete($"Use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")]
IArtifact? IServiceConnector.GetArtifact(Udi udi)
=> GetArtifact(udi, PassThroughCache.Instance);
/// <summary>
/// Gets an artifact.
/// </summary>
/// <param name="udi">The entity identifier of the artifact.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The corresponding artifact, or null.
/// </returns>
IArtifact? GetArtifact(Udi udi, IContextCache contextCache);
/// <inheritdoc />
[Obsolete($"Use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")]
IArtifact IServiceConnector.GetArtifact(object entity)
=> GetArtifact(entity, PassThroughCache.Instance);
/// <summary>
/// Gets an artifact.
/// </summary>
/// <param name="entity">The entity.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The corresponding artifact.
/// </returns>
IArtifact GetArtifact(object entity, IContextCache contextCache);
}

View File

@@ -26,11 +26,11 @@ public interface IValueConnector
/// <param name="value">The content property value.</param>
/// <param name="propertyType">The value property type</param>
/// <param name="dependencies">The content dependencies.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The deploy property value.
/// </returns>
[Obsolete($"Implement {nameof(IValueConnector2)} and use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")]
string? ToArtifact(object? value, IPropertyType propertyType, ICollection<ArtifactDependency> dependencies);
string? ToArtifact(object? value, IPropertyType propertyType, ICollection<ArtifactDependency> dependencies, IContextCache contextCache);
/// <summary>
/// Gets the content property value corresponding to a deploy property value.
@@ -38,9 +38,9 @@ public interface IValueConnector
/// <param name="value">The deploy property value.</param>
/// <param name="propertyType">The value property type</param>
/// <param name="currentValue">The current content property value.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The content property value.
/// </returns>
[Obsolete($"Implement {nameof(IValueConnector2)} and use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")]
object? FromArtifact(string? value, IPropertyType propertyType, object? currentValue);
object? FromArtifact(string? value, IPropertyType propertyType, object? currentValue, IContextCache contextCache);
}

View File

@@ -1,44 +0,0 @@
using Umbraco.Cms.Core.Models;
namespace Umbraco.Cms.Core.Deploy;
/// <inheritdoc />
/// <remarks>
/// This interface will be merged back into <see cref="IValueConnector" /> and removed in Umbraco 13.
/// </remarks>
public interface IValueConnector2 : IValueConnector
{
/// <inheritdoc />
[Obsolete($"Use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")]
string? IValueConnector.ToArtifact(object? value, IPropertyType propertyType, ICollection<ArtifactDependency> dependencies)
=> ToArtifact(value, propertyType, dependencies, PassThroughCache.Instance);
/// <summary>
/// Gets the deploy property value corresponding to a content property value, and gather dependencies.
/// </summary>
/// <param name="value">The content property value.</param>
/// <param name="propertyType">The value property type</param>
/// <param name="dependencies">The content dependencies.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The deploy property value.
/// </returns>
string? ToArtifact(object? value, IPropertyType propertyType, ICollection<ArtifactDependency> dependencies, IContextCache contextCache);
/// <inheritdoc />
[Obsolete($"Use the overload accepting {nameof(IContextCache)} instead. This overload will be removed in Umbraco 13.")]
object? IValueConnector.FromArtifact(string? value, IPropertyType propertyType, object? currentValue)
=> FromArtifact(value, propertyType, currentValue, PassThroughCache.Instance);
/// <summary>
/// Gets the content property value corresponding to a deploy property value.
/// </summary>
/// <param name="value">The deploy property value.</param>
/// <param name="propertyType">The value property type</param>
/// <param name="currentValue">The current content property value.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The content property value.
/// </returns>
object? FromArtifact(string? value, IPropertyType propertyType, object? currentValue, IContextCache contextCache);
}

View File

@@ -1,44 +0,0 @@
namespace Umbraco.Cms.Core.Deploy;
/// <summary>
/// Extension methods adding backwards-compatability between <see cref="IServiceConnector" /> and <see cref="IServiceConnector2" />.
/// </summary>
/// <remarks>
/// These extension methods will be removed in Umbraco 13.
/// </remarks>
public static class ServiceConnectorExtensions
{
/// <summary>
/// Gets an artifact.
/// </summary>
/// <param name="connector">The connector.</param>
/// <param name="udi">The entity identifier of the artifact.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The corresponding artifact, or null.
/// </returns>
/// <remarks>
/// This extension method tries to make use of the <see cref="IContextCache" /> on types also implementing <see cref="IServiceConnector2" />.
/// </remarks>
public static IArtifact? GetArtifact(this IServiceConnector connector, Udi udi, IContextCache contextCache)
=> connector is IServiceConnector2 connector2
? connector2.GetArtifact(udi, contextCache)
: connector.GetArtifact(udi);
/// <summary>
/// Gets an artifact.
/// </summary>
/// <param name="connector">The connector.</param>
/// <param name="entity">The entity.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The corresponding artifact.
/// </returns>
/// <remarks>
/// This extension method tries to make use of the <see cref="IContextCache" /> on types also implementing <see cref="IServiceConnector2" />.
/// </remarks>
public static IArtifact GetArtifact(this IServiceConnector connector, object entity, IContextCache contextCache)
=> connector is IServiceConnector2 connector2
? connector2.GetArtifact(entity, contextCache)
: connector.GetArtifact(entity);
}

View File

@@ -1,50 +0,0 @@
using Umbraco.Cms.Core.Models;
namespace Umbraco.Cms.Core.Deploy;
/// <summary>
/// Extension methods adding backwards-compatability between <see cref="IValueConnector" /> and <see cref="IValueConnector2" />.
/// </summary>
/// <remarks>
/// These extension methods will be removed in Umbraco 13.
/// </remarks>
public static class ValueConnectorExtensions
{
/// <summary>
/// Gets the artifact value corresponding to a property value and gather dependencies.
/// </summary>
/// <param name="connector">The connector.</param>
/// <param name="value">The property value.</param>
/// <param name="propertyType">The property type.</param>
/// <param name="dependencies">The dependencies.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The artifact value.
/// </returns>
/// <remarks>
/// This extension method tries to make use of the <see cref="IContextCache" /> on types also implementing <see cref="IValueConnector2" />.
/// </remarks>
public static string? ToArtifact(this IValueConnector connector, object? value, IPropertyType propertyType, ICollection<ArtifactDependency> dependencies, IContextCache contextCache)
=> connector is IValueConnector2 connector2
? connector2.ToArtifact(value, propertyType, dependencies, contextCache)
: connector.ToArtifact(value, propertyType, dependencies);
/// <summary>
/// Gets the property value corresponding to an artifact value.
/// </summary>
/// <param name="connector">The connector.</param>
/// <param name="value">The artifact value.</param>
/// <param name="propertyType">The property type.</param>
/// <param name="currentValue">The current property value.</param>
/// <param name="contextCache">The context cache.</param>
/// <returns>
/// The property value.
/// </returns>
/// <remarks>
/// This extension method tries to make use of the <see cref="IContextCache" /> on types also implementing <see cref="IValueConnector2" />.
/// </remarks>
public static object? FromArtifact(this IValueConnector connector, string? value, IPropertyType propertyType, object? currentValue, IContextCache contextCache)
=> connector is IValueConnector2 connector2
? connector2.FromArtifact(value, propertyType, currentValue, contextCache)
: connector.FromArtifact(value, propertyType, currentValue);
}

View File

@@ -326,7 +326,7 @@ public class UdiTests
}
[UdiDefinition("foo", UdiType.GuidUdi)]
public class FooConnector : IServiceConnector2
public class FooConnector : IServiceConnector
{
public IArtifact GetArtifact(Udi udi, IContextCache contextCache) => throw new NotImplementedException();