Skip to content

Commit 99e6e7a

Browse files
Updated connectors to use context cache. (#54)
* Updated connectors to use context cache. * Add context cache to ToArtifact/FromArtifact and update sealed * Apply suggestions from code review Co-authored-by: Ronald Barendse <[email protected]> * Reverted amend to csproj. * Updated dependency to 4.7.0-alpha001. * Added nightly feed to NuGet.config * Updated Deploy dependency in nuspec file. * Bumped version to 4.2.0-alpha001 and fixed local build. * Fix MSBuild path for AzureDevOps? Co-authored-by: Ronald Barendse <[email protected]>
1 parent bb99efb commit 99e6e7a

File tree

11 files changed

+89
-56
lines changed

11 files changed

+89
-56
lines changed

build/NuSpecs/UmbracoDeploy.Contrib.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<language>en-US</language>
1818
<tags>umbraco</tags>
1919
<dependencies>
20-
<dependency id="UmbracoDeploy.Core" version="4.1.2" />
20+
<dependency id="UmbracoDeploy.Core" version="4.7.0-alpha11437" />
2121
</dependencies>
2222
</metadata>
2323
<files>

build/RunBuild.bat

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ if exist "%programfiles(x86)%\Microsoft Visual Studio\2017\BuildTools\MSBuild\15
4545
SET MSBUILDPath="%programfiles(x86)%\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MsBuild.exe"
4646
)
4747

48+
if exist "%programfiles%\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe" (
49+
SET MSBUILDPath="%programfiles%\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe"
50+
)
51+
52+
if exist "%programfiles%\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe" (
53+
SET MSBUILDPath="%programfiles%\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe"
54+
)
55+
4856
ECHO MSBUILD is here %MSBUILDPath%
4957
%MSBUILDPath% "Build.proj" /p:BUILD_RELEASE=%release% /p:BUILD_COMMENT=%comment%
5058

build/version.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# Usage: on line 2 put the release version, on line 3 put the version comment (example: beta)
2-
4.1.3
2+
4.2.0
3+
alpha001

src/NuGet.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
<configuration>
33
<packageSources>
44
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
5+
<add key="Umbraco Nightly" value="https://www.myget.org/F/umbraconightly/api/v3/index.json" />
56
</packageSources>
67
</configuration>

src/Umbraco.Deploy.Contrib.Connectors/GridCellValueConnectors/DocTypeGridEditorCellValueConnector.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
using Newtonsoft.Json;
2-
using Newtonsoft.Json.Linq;
3-
using System;
1+
using System;
42
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Linq;
55
using Umbraco.Core;
66
using Umbraco.Core.Deploy;
77
using Umbraco.Core.Logging;
88
using Umbraco.Core.Models;
99
using Umbraco.Core.Services;
10+
using Umbraco.Deploy.Connectors;
11+
using Umbraco.Deploy.Connectors.GridCellValueConnectors;
1012
using Umbraco.Deploy.Connectors.ValueConnectors.Services;
13+
using Umbraco.Deploy.Core;
1114

1215
namespace Umbraco.Deploy.Contrib.Connectors.GridCellValueConnectors
1316
{
14-
public class DocTypeGridEditorCellValueConnector : IGridCellValueConnector
17+
public class DocTypeGridEditorCellValueConnector : GridCellValueConnectorBase2
1518
{
1619
private readonly ILogger _logger;
1720
private readonly IContentTypeService _contentTypeService;
@@ -26,9 +29,10 @@ public DocTypeGridEditorCellValueConnector(ILogger logger, IContentTypeService c
2629
_valueConnectorsLazy = valueConnectors ?? throw new ArgumentNullException(nameof(valueConnectors));
2730
}
2831

29-
public bool IsConnector(string view) => !string.IsNullOrWhiteSpace(view) && view.Contains("doctypegrideditor");
32+
public sealed override bool IsConnector(string view)
33+
=> !string.IsNullOrWhiteSpace(view) && view.Contains("doctypegrideditor");
3034

31-
public string GetValue(GridValue.GridControl gridControl, ICollection<ArtifactDependency> dependencies)
35+
public sealed override string GetValue(GridValue.GridControl gridControl, ICollection<ArtifactDependency> dependencies, IContextCache contextCache)
3236
{
3337
// cancel if there's no values
3438
if (gridControl.Value == null || gridControl.Value.HasValues == false) return null;
@@ -47,8 +51,7 @@ public string GetValue(GridValue.GridControl gridControl, ICollection<ArtifactDe
4751
_logger.Debug<DocTypeGridEditorCellValueConnector>($"GetValue - ContentTypeAlias - {docTypeGridEditorContent.ContentTypeAlias}");
4852

4953
// check if the doc type exist - else abort packaging
50-
var contentType = _contentTypeService.Get(docTypeGridEditorContent.ContentTypeAlias);
51-
54+
var contentType = contextCache.GetContentTypeByAlias(_contentTypeService, docTypeGridEditorContent.ContentTypeAlias);
5255
if (contentType == null)
5356
{
5457
_logger.Debug<DocTypeGridEditorCellValueConnector>("GetValue - Missing ContentType");
@@ -84,7 +87,7 @@ public string GetValue(GridValue.GridControl gridControl, ICollection<ArtifactDe
8487
_logger.Debug<DocTypeGridEditorCellValueConnector>($"GetValue - propertyTypeValue - {value}");
8588

8689
//properties like MUP / Nested Content are JSON, we need to convert to string for the conversion to artifact
87-
string parsedValue = propValueConnector.ToArtifact(IsJson(value) ? value.ToString() : value, propertyType, dependencies);
90+
string parsedValue = propValueConnector.ToArtifact(IsJson(value) ? value.ToString() : value, propertyType, dependencies, contextCache);
8891

8992
_logger.Debug<DocTypeGridEditorCellValueConnector>($"GetValue - ParsedValue - {parsedValue}");
9093

@@ -98,7 +101,7 @@ public string GetValue(GridValue.GridControl gridControl, ICollection<ArtifactDe
98101
return resolvedValue;
99102
}
100103

101-
public void SetValue(GridValue.GridControl gridControl)
104+
public sealed override void SetValue(GridValue.GridControl gridControl, IContextCache contextCache)
102105
{
103106
// cancel if there's no values
104107
if (string.IsNullOrWhiteSpace(gridControl.Value.ToString()))
@@ -121,8 +124,7 @@ public void SetValue(GridValue.GridControl gridControl)
121124
_logger.Debug<DocTypeGridEditorCellValueConnector>($"SetValue - ContentTypeAlias - {docTypeGridEditorContent.ContentTypeAlias}");
122125

123126
// check if the doc type exist - else abort packaging
124-
var contentType = _contentTypeService.Get(docTypeGridEditorContent.ContentTypeAlias);
125-
127+
var contentType = contextCache.GetContentTypeByAlias(_contentTypeService, docTypeGridEditorContent.ContentTypeAlias);
126128
if (contentType == null)
127129
{
128130
throw new InvalidOperationException($"Could not resolve the Content Type for the Doc Type Grid Editor property: {docTypeGridEditorContent.ContentTypeAlias}");
@@ -145,7 +147,7 @@ public void SetValue(GridValue.GridControl gridControl)
145147

146148
// throws if not found - no need for a null check
147149
var propValueConnector = ValueConnectors.Get(propertyType);
148-
var convertedValue = propValueConnector.FromArtifact(value.ToString(), propertyType, string.Empty);
150+
var convertedValue = propValueConnector.FromArtifact(value.ToString(), propertyType, string.Empty, contextCache);
149151

150152
JToken jtokenValue = null;
151153
if (IsJson(convertedValue))

src/Umbraco.Deploy.Contrib.Connectors/Properties/VersionInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// </auto-generated>
99
//------------------------------------------------------------------------------
1010

11-
[assembly: System.Reflection.AssemblyInformationalVersion("4.1.3")]
12-
[assembly: System.Reflection.AssemblyVersion("4.1.3")]
11+
[assembly: System.Reflection.AssemblyInformationalVersion("4.2.0-alpha001")]
12+
[assembly: System.Reflection.AssemblyVersion("4.2.0")]
1313

1414

src/Umbraco.Deploy.Contrib.Connectors/Umbraco.Deploy.Contrib.Connectors.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
<RootNamespace>Umbraco.Deploy.Contrib.Connectors</RootNamespace>
66
<TargetFramework>net472</TargetFramework>
77
</PropertyGroup>
8-
98
<ItemGroup>
109
<PackageReference Include="UmbracoDeploy.Core">
11-
<Version>4.1.2</Version>
10+
<Version>4.7.0-alpha11437</Version>
1211
</PackageReference>
1312
</ItemGroup>
1413
</Project>

src/Umbraco.Deploy.Contrib.Connectors/ValueConnectors/BlockEditorValueConnector.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,27 @@
88
using Umbraco.Core.Logging;
99
using Umbraco.Core.Models;
1010
using Umbraco.Core.Services;
11+
using Umbraco.Deploy.Connectors;
12+
using Umbraco.Deploy.Connectors.ValueConnectors;
1113
using Umbraco.Deploy.Connectors.ValueConnectors.Services;
14+
using Umbraco.Deploy.Core;
1215

1316
namespace Umbraco.Deploy.Contrib.Connectors.ValueConnectors
1417
{
1518
/// <summary>
1619
/// A Deploy connector for BlockEditor based property editors (ie. BlockList)
1720
/// </summary>
18-
public abstract class BlockEditorValueConnector : IValueConnector
21+
public abstract class BlockEditorValueConnector : ValueConnectorBase
1922
{
2023
private readonly IContentTypeService _contentTypeService;
2124
private readonly Lazy<ValueConnectorCollection> _valueConnectorsLazy;
2225
private readonly ILogger _logger;
2326

24-
public virtual IEnumerable<string> PropertyEditorAliases => new[] { "Umbraco.BlockEditor" };
27+
/// <inheritdoc />
28+
public override IEnumerable<string> PropertyEditorAliases { get; } = new[]
29+
{
30+
"Umbraco.BlockEditor"
31+
};
2532

2633
// cannot inject ValueConnectorCollection directly as it would cause a circular (recursive) dependency,
2734
// so we have to inject it lazily and use the lazy value when actually needing it
@@ -37,7 +44,7 @@ public BlockEditorValueConnector(IContentTypeService contentTypeService, Lazy<Va
3744
_logger = logger;
3845
}
3946

40-
public virtual string ToArtifact(object value, PropertyType propertyType, ICollection<ArtifactDependency> dependencies)
47+
public override string ToArtifact(object value, PropertyType propertyType, ICollection<ArtifactDependency> dependencies, IContextCache contextCache)
4148
{
4249
_logger.Debug<BlockEditorValueConnector>("Converting {PropertyType} to artifact.", propertyType.Alias);
4350
var svalue = value as string;
@@ -78,7 +85,8 @@ public virtual string ToArtifact(object value, PropertyType propertyType, IColle
7885
{
7986
if (!Guid.TryParse(a, out var keyAsGuid))
8087
throw new InvalidOperationException($"Could not parse ContentTypeKey as GUID {keyAsGuid}.");
81-
return _contentTypeService.Get(keyAsGuid);
88+
89+
return contextCache.GetContentTypeByKey(_contentTypeService, keyAsGuid);
8290
});
8391

8492
//Ensure all of these content types are found
@@ -116,7 +124,7 @@ public virtual string ToArtifact(object value, PropertyType propertyType, IColle
116124

117125
// pass the value, property type and the dependencies collection to the connector to get a "artifact" value
118126
var innerValue = block.PropertyValues[key];
119-
object parsedValue = propertyValueConnector.ToArtifact(innerValue, innerPropertyType, dependencies);
127+
object parsedValue = propertyValueConnector.ToArtifact(innerValue, innerPropertyType, dependencies, contextCache);
120128

121129
_logger.Debug<BlockEditorValueConnector>("Mapped {Key} value '{PropertyValue}' to '{ParsedValue}' using {PropertyValueConnectorType} for {PropertyType}.", key, block.PropertyValues[key], parsedValue, propertyValueConnector.GetType(), innerPropertyType.Alias);
122130

@@ -132,7 +140,7 @@ public virtual string ToArtifact(object value, PropertyType propertyType, IColle
132140
return (string) value;
133141
}
134142

135-
public virtual object FromArtifact(string value, PropertyType propertyType, object currentValue)
143+
public override object FromArtifact(string value, PropertyType propertyType, object currentValue, IContextCache contextCache)
136144
{
137145
_logger.Debug<BlockEditorValueConnector>("Converting {PropertyType} from artifact.", propertyType.Alias);
138146
if (string.IsNullOrWhiteSpace(value))
@@ -156,7 +164,8 @@ public virtual object FromArtifact(string value, PropertyType propertyType, obje
156164
{
157165
if (!Guid.TryParse(a, out var keyAsGuid))
158166
throw new InvalidOperationException($"Could not parse ContentTypeKey as GUID {keyAsGuid}.");
159-
return _contentTypeService.Get(keyAsGuid);
167+
168+
return contextCache.GetContentTypeByKey(_contentTypeService, keyAsGuid);
160169
});
161170

162171
//Ensure all of these content types are found
@@ -190,7 +199,7 @@ public virtual object FromArtifact(string value, PropertyType propertyType, obje
190199
if (innerValue != null)
191200
{
192201
// pass the artifact value and property type to the connector to get a real value from the artifact
193-
var convertedValue = propertyValueConnector.FromArtifact(innerValue.ToString(), innerPropertyType, null);
202+
var convertedValue = propertyValueConnector.FromArtifact(innerValue.ToString(), innerPropertyType, null, contextCache);
194203

195204
if (convertedValue == null)
196205
{

src/Umbraco.Deploy.Contrib.Connectors/ValueConnectors/MultiUrlPickerValueConnector.cs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
using Umbraco.Core.Logging;
99
using Umbraco.Core.Models;
1010
using Umbraco.Core.Services;
11+
using Umbraco.Deploy.Connectors.ValueConnectors;
12+
using Umbraco.Deploy.Core;
1113

1214
namespace Umbraco.Deploy.Contrib.Connectors.ValueConnectors
1315
{
14-
public class MultiUrlPickerValueConnector : IValueConnector
16+
public class MultiUrlPickerValueConnector : ValueConnectorBase
1517
{
1618
private readonly IEntityService _entityService;
1719
private readonly IMediaService _mediaService;
@@ -20,6 +22,12 @@ public class MultiUrlPickerValueConnector : IValueConnector
2022
// Used to fetch the udi from a umb://-based url
2123
private static readonly Regex MediaUdiSrcRegex = new Regex(@"(?<udi>umb://media/[A-z0-9]+)", RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
2224

25+
/// <inheritdoc />
26+
public override IEnumerable<string> PropertyEditorAliases { get; } = new[]
27+
{
28+
"Umbraco.MultiUrlPicker"
29+
};
30+
2331
/// <summary>
2432
/// Initializes a new instance of the <see cref="MultiUrlPickerValueConnector"/> class.
2533
/// Source found here: https://github.com/rasmusjp/umbraco-multi-url-picker
@@ -49,7 +57,7 @@ public MultiUrlPickerValueConnector(IEntityService entityService, IMediaService
4957
_logger = logger;
5058
}
5159

52-
public string ToArtifact(object value, PropertyType propertyType, ICollection<ArtifactDependency> dependencies)
60+
public sealed override string ToArtifact(object value, PropertyType propertyType, ICollection<ArtifactDependency> dependencies, IContextCache contextCache)
5361
{
5462
var svalue = value as string;
5563
if (string.IsNullOrWhiteSpace(svalue))
@@ -67,11 +75,9 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
6775
foreach (var link in links)
6876
{
6977
var isMedia = link["isMedia"] != null;
70-
int intId;
71-
string url;
72-
GuidUdi guidUdi;
78+
7379
// Only do processing if the Id is set on the element. OR if the url is set and its a media item
74-
if (TryParseJTokenAttr(link, "id", out intId))
80+
if (TryParseJTokenAttr(link, "id", out int intId))
7581
{
7682
// Checks weather we are resolving a media item or a document
7783
var objectTypeId = isMedia
@@ -84,15 +90,16 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
8490
continue;
8591

8692
var udi = new GuidUdi(entityType, guidAttempt.Result);
93+
8794
// Add the artifact dependency
8895
dependencies.Add(new ArtifactDependency(udi, false, ArtifactDependencyMode.Exist));
8996

9097
// Set the Id attribute to the udi
9198
link["id"] = udi.ToString();
9299
}
93-
else if (TryParseJTokenAttr(link, "udi", out guidUdi))
100+
else if (TryParseJTokenAttr(link, "udi", out GuidUdi guidUdi))
94101
{
95-
var entityExists = _entityService.Exists(guidUdi.Guid);
102+
var entityExists = contextCache.EntityExists(_entityService, guidUdi.Guid);
96103
if (!entityExists)
97104
{
98105
continue;
@@ -101,7 +108,7 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
101108
// Add the artifact dependency
102109
dependencies.Add(new ArtifactDependency(guidUdi, false, ArtifactDependencyMode.Exist));
103110
}
104-
else if (isMedia && TryParseJTokenAttr(link, "url", out url))
111+
else if (isMedia && TryParseJTokenAttr(link, "url", out string url))
105112
{
106113
// This state can happen due to an issue in RJP.MultiUrlPicker(or our linkPicker in RTE which it relies on),
107114
// where you edit a media link, and just hit "Select".
@@ -142,10 +149,11 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
142149
: UmbracoObjectTypes.Document;
143150
var entityType = isMedia ? Constants.UdiEntityType.Media : Constants.UdiEntityType.Document;
144151

145-
var guidAttempt = _entityService.GetKey(intId, objectTypeId);
152+
var guidAttempt = contextCache.GetEntityKeyById(_entityService, intId, objectTypeId);
146153
if (guidAttempt.Success)
147154
{
148155
var udi = new GuidUdi(entityType, guidAttempt.Result);
156+
149157
// Add the artifact dependency
150158
dependencies.Add(new ArtifactDependency(udi, false, ArtifactDependencyMode.Exist));
151159

@@ -155,8 +163,7 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
155163
}
156164
else if (TryParseJTokenAttr(link, "udi", out guidUdi))
157165
{
158-
var entity = _entityService.Get(guidUdi.Guid, Constants.UdiEntityType.ToUmbracoObjectType(guidUdi.EntityType));
159-
if (entity != null)
166+
if (contextCache.EntityExists(_entityService, guidUdi.Guid))
160167
{
161168
// Add the artifact dependency
162169
dependencies.Add(new ArtifactDependency(guidUdi, false, ArtifactDependencyMode.Exist));
@@ -186,7 +193,7 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
186193
return string.Empty;
187194
}
188195

189-
public object FromArtifact(string value, PropertyType propertyType, object currentValue)
196+
public sealed override object FromArtifact(string value, PropertyType propertyType, object currentValue, IContextCache contextCache)
190197
{
191198
if (string.IsNullOrWhiteSpace(value))
192199
{
@@ -216,7 +223,7 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
216223
// Get the Id corresponding to the Guid
217224
// it *should* succeed when deploying, due to dependencies management
218225
// nevertheless, assume it can fail, and then create an invalid localLink
219-
var idAttempt = _entityService.GetId(udi.Guid, nodeObjectType);
226+
var idAttempt = contextCache.GetEntityIdByKey(_entityService, udi.Guid, nodeObjectType);
220227
if (idAttempt)
221228
link["id"] = idAttempt.Success ? idAttempt.Result : 0;
222229
}
@@ -261,7 +268,7 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
261268
// Get the Id corresponding to the Guid
262269
// it *should* succeed when deploying, due to dependencies management
263270
// nevertheless, assume it can fail, and then create an invalid localLink
264-
var idAttempt = _entityService.GetId(udi.Guid, nodeObjectType);
271+
var idAttempt = contextCache.GetEntityIdByKey(_entityService, udi.Guid, nodeObjectType);
265272
if (idAttempt)
266273
link["id"] = idAttempt.Success ? idAttempt.Result : 0;
267274
}
@@ -293,9 +300,6 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
293300
return value;
294301
}
295302

296-
/// <inheritdoc/>
297-
public virtual IEnumerable<string> PropertyEditorAliases => new[] { "RJP.MultiUrlPicker", "Umbraco.MultiUrlPicker" };
298-
299303
private bool TryParseJTokenAttr(JToken link, string attrName, out int attrValue)
300304
{
301305
if (link[attrName] != null)

0 commit comments

Comments
 (0)