Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IContextCache to deploy connectors (#13287)
* Add IContextCache and implementations * Update connector interfaces to use IContextCache * Minor cleanup * Move DeployContextCache prefix to constant * Move default implementations to obsolete methods * Remove DeployContextCache and DictionaryCache Co-authored-by: Andy Butland <abutland73@gmail.com>
- Loading branch information
1 parent
fc18759
commit 1560e84
Showing
10 changed files
with
351 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,49 @@ | ||
namespace Umbraco.Cms.Core.Deploy | ||
namespace Umbraco.Cms.Core.Deploy; | ||
|
||
/// <summary> | ||
/// Provides a base class to all artifacts. | ||
/// </summary> | ||
public abstract class ArtifactBase<TUdi> : IArtifact | ||
where TUdi : Udi | ||
{ | ||
/// <summary> | ||
/// Provides a base class to all artifacts. | ||
/// </summary> | ||
public abstract class ArtifactBase<TUdi> : IArtifact | ||
where TUdi : Udi | ||
protected ArtifactBase(TUdi udi, IEnumerable<ArtifactDependency>? dependencies = null) | ||
{ | ||
protected ArtifactBase(TUdi udi, IEnumerable<ArtifactDependency>? dependencies = null) | ||
{ | ||
Udi = udi ?? throw new ArgumentNullException("udi"); | ||
Name = Udi.ToString(); | ||
Udi = udi ?? throw new ArgumentNullException("udi"); | ||
Name = Udi.ToString(); | ||
|
||
_dependencies = dependencies ?? Enumerable.Empty<ArtifactDependency>(); | ||
_checksum = new Lazy<string>(GetChecksum); | ||
} | ||
|
||
private readonly Lazy<string> _checksum; | ||
_dependencies = dependencies ?? Enumerable.Empty<ArtifactDependency>(); | ||
_checksum = new Lazy<string>(GetChecksum); | ||
} | ||
|
||
private IEnumerable<ArtifactDependency> _dependencies; | ||
private readonly Lazy<string> _checksum; | ||
|
||
protected abstract string GetChecksum(); | ||
private IEnumerable<ArtifactDependency> _dependencies; | ||
|
||
Udi IArtifactSignature.Udi => Udi; | ||
protected abstract string GetChecksum(); | ||
|
||
public TUdi Udi { get; set; } | ||
Udi IArtifactSignature.Udi => Udi; | ||
|
||
public string Checksum => _checksum.Value; | ||
public TUdi Udi { get; set; } | ||
|
||
/// <summary> | ||
/// Prevents the <see cref="Checksum" /> property from being serialized. | ||
/// </summary> | ||
/// <remarks> | ||
/// Note that we can't use <see cref="NonSerializedAttribute"/> here as that works only on fields, not properties. And we want to avoid using [JsonIgnore] | ||
/// as that would require an external dependency in Umbraco.Cms.Core. | ||
/// So using this method of excluding properties from serialized data, documented here: https://www.newtonsoft.com/json/help/html/ConditionalProperties.htm | ||
/// </remarks> | ||
public bool ShouldSerializeChecksum() => false; | ||
public string Checksum => _checksum.Value; | ||
|
||
public IEnumerable<ArtifactDependency> Dependencies | ||
{ | ||
get => _dependencies; | ||
set => _dependencies = value.OrderBy(x => x.Udi); | ||
} | ||
/// <summary> | ||
/// Prevents the <see cref="Checksum" /> property from being serialized. | ||
/// </summary> | ||
/// <remarks> | ||
/// Note that we can't use <see cref="NonSerializedAttribute"/> here as that works only on fields, not properties. And we want to avoid using [JsonIgnore] | ||
/// as that would require an external dependency in Umbraco.Cms.Core. | ||
/// So using this method of excluding properties from serialized data, documented here: https://www.newtonsoft.com/json/help/html/ConditionalProperties.htm | ||
/// </remarks> | ||
public bool ShouldSerializeChecksum() => false; | ||
|
||
public IEnumerable<ArtifactDependency> Dependencies | ||
{ | ||
get => _dependencies; | ||
set => _dependencies = value.OrderBy(x => x.Udi); | ||
} | ||
|
||
public string Name { get; set; } | ||
public string Name { get; set; } | ||
|
||
public string Alias { get; set; } = string.Empty; | ||
} | ||
public string Alias { get; set; } = string.Empty; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
src/Umbraco.Core/Deploy/ArtifactDeployStateOfTArtifactTEntity.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace Umbraco.Cms.Core.Deploy; | ||
|
||
/// <summary> | ||
/// Represents a context cache used by Deploy operations. | ||
/// </summary> | ||
public interface IContextCache | ||
{ | ||
/// <summary> | ||
/// Creates the item on the context cache using the specified <paramref name="key" />. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the cached item.</typeparam> | ||
/// <param name="key">The key of the cached item.</param> | ||
/// <param name="item">The item.</param> | ||
void Create<T>(string key, T item); | ||
|
||
/// <summary> | ||
/// Gets an item from the context cache or creates and stores it using the specified <paramref name="key" />. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the cached item.</typeparam> | ||
/// <param name="key">The key of the cached item.</param> | ||
/// <param name="factory">The factory method to create the item (if it doesn't exist yet).</param> | ||
/// <returns> | ||
/// The item. | ||
/// </returns> | ||
T? GetOrCreate<T>(string key, Func<T?> factory); | ||
|
||
/// <summary> | ||
/// Clears all cached items on this context. | ||
/// </summary> | ||
void Clear(); | ||
} |
62 changes: 46 additions & 16 deletions
62
src/Umbraco.Core/Deploy/IDataTypeConfigurationConnector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,67 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using Umbraco.Cms.Core.Models; | ||
|
||
namespace Umbraco.Cms.Core.Deploy; | ||
|
||
/// <summary> | ||
/// Defines methods that can convert data type configuration to / from an environment-agnostic string. | ||
/// Defines methods that can convert data type configuration to / from an environment-agnostic string. | ||
/// </summary> | ||
/// <remarks> | ||
/// Configuration may contain values such as content identifiers, that would be local | ||
/// to one environment, and need to be converted in order to be deployed. | ||
/// Configuration may contain values such as content identifiers, that would be local | ||
/// to one environment, and need to be converted in order to be deployed. | ||
/// </remarks> | ||
[SuppressMessage( | ||
"ReSharper", | ||
"UnusedMember.Global", | ||
Justification = "This is actual only used by Deploy, but we don't want third parties to have references on deploy, that's why this interface is part of core.")] | ||
public interface IDataTypeConfigurationConnector | ||
{ | ||
/// <summary> | ||
/// Gets the property editor aliases that the value converter supports by default. | ||
/// Gets the property editor aliases that the value converter supports by default. | ||
/// </summary> | ||
/// <value> | ||
/// The property editor aliases. | ||
/// </value> | ||
IEnumerable<string> PropertyEditorAliases { get; } | ||
|
||
/// <summary> | ||
/// Gets the artifact datatype configuration corresponding to the actual datatype configuration. | ||
/// Gets the artifact configuration value corresponding to a data type configuration and gather dependencies. | ||
/// </summary> | ||
/// <param name="dataType">The datatype.</param> | ||
/// <param name="dataType">The data type.</param> | ||
/// <param name="dependencies">The dependencies.</param> | ||
string? ToArtifact(IDataType dataType, ICollection<ArtifactDependency> dependencies); | ||
/// <returns> | ||
/// The artifact configuration value. | ||
/// </returns> | ||
[Obsolete("Use the overload accepting IContextCache instead. This overload will be removed in a future version.")] | ||
string? ToArtifact(IDataType dataType, ICollection<ArtifactDependency> dependencies) | ||
=> ToArtifact(dataType, dependencies, PassThroughCache.Instance); | ||
|
||
/// <summary> | ||
/// Gets the actual datatype configuration corresponding to the artifact configuration. | ||
/// Gets the artifact configuration value corresponding to a data type configuration and gather dependencies. | ||
/// </summary> | ||
/// <param name="dataType">The datatype.</param> | ||
/// <param name="configuration">The artifact configuration.</param> | ||
object? FromArtifact(IDataType dataType, string? configuration); | ||
/// <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 IContextCache instead. This overload will be removed in a future version.")] | ||
object? 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); | ||
} |
Oops, something went wrong.