Skip to content

Commit e1128a3

Browse files
committed
Merge branch 'dev-v3' into master-v3
2 parents 65586a7 + 9ff2829 commit e1128a3

File tree

3 files changed

+21
-59
lines changed

3 files changed

+21
-59
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ src/Umbraco.Deploy.Contrib.Connectors/App_Plugins/*
3030
src/Umbraco.Deploy.Contrib.Connectors/Config/*
3131
src/Umbraco.Deploy.Contrib.Connectors/app.config
3232
/build/UmbracoDeploy.Contrib.*.nupkg
33+
/build/UmbracoDeploy.Contrib.*.zip

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
![Build status](https://umbraco.visualstudio.com/_apis/public/build/definitions/c854e28c-27a5-4caf-a499-67997042aa5e/15/badge)
2-
[![NuGet release](https://img.shields.io/nuget/v/Umbraco.Deploy.Contrib.svg)](https://www.nuget.org/packages/Umbraco.Deploy.Contrib)
1+
[![Build Status](https://dev.azure.com/umbraco/Umbraco%20Deploy%20Contrib/_apis/build/status/Umbraco%20Deploy%20Contrib%20v3%20-%20Release?branchName=master-v3)](https://dev.azure.com/umbraco/Umbraco%20Deploy%20Contrib/_build/latest?definitionId=185&branchName=master-v3) [![NuGet release](https://img.shields.io/nuget/v/UmbracoDeploy.Contrib.svg)](https://www.nuget.org/packages/UmbracoDeploy.Contrib)
32

43
# Umbraco Deploy Contrib
54

@@ -20,7 +19,7 @@ None so far.
2019

2120
### Installation
2221

23-
You can install the NuGet package using `Install-Package Umbraco.Deploy.Contrib`.
22+
You can install the NuGet package using `Install-Package UmbracoDeploy.Contrib`.
2423

2524
---
2625
## Contributing to this project

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

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ public class NestedContentValueConnector : IValueConnector
2121
private readonly Lazy<ValueConnectorCollection> _valueConnectorsLazy;
2222
private readonly ILogger _logger;
2323

24+
// Our.Umbraco.NestedContent is the original NestedContent package
25+
// Umbraco.NestedContent is Core NestedContent (introduced in v7.7)
26+
public virtual IEnumerable<string> PropertyEditorAliases => new[] { "Our.Umbraco.NestedContent", "Umbraco.NestedContent" };
27+
28+
// cannot inject ValueConnectorCollection else of course it creates a circular (recursive) dependency,
29+
// so we have to inject it lazily and use the lazy value when actually needing it
30+
private ValueConnectorCollection ValueConnectors => _valueConnectorsLazy.Value;
31+
2432
public NestedContentValueConnector(IContentTypeService contentTypeService, Lazy<ValueConnectorCollection> valueConnectors, ILogger logger)
2533
{
2634
if (contentTypeService == null) throw new ArgumentNullException(nameof(contentTypeService));
@@ -31,8 +39,6 @@ public NestedContentValueConnector(IContentTypeService contentTypeService, Lazy<
3139
_logger = logger;
3240
}
3341

34-
// Our.Umbraco.NestedContent is the original NestedContent package
35-
// Umbraco.NestedContent is Core NestedContent (introduced in v7.7)
3642
public string ToArtifact(object value, PropertyType propertyType, ICollection<ArtifactDependency> dependencies)
3743
{
3844
var svalue = value as string;
@@ -44,9 +50,13 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
4450

4551
var nestedContent = new List<NestedContentValue>();
4652
if (svalue.Trim().StartsWith("{"))
53+
{
4754
nestedContent.Add(JsonConvert.DeserializeObject<NestedContentValue>(svalue));
55+
}
4856
else
57+
{
4958
nestedContent.AddRange(JsonConvert.DeserializeObject<NestedContentValue[]>(svalue));
59+
}
5060

5161
if (nestedContent.All(x => x == null))
5262
return null;
@@ -86,31 +96,19 @@ public string ToArtifact(object value, PropertyType propertyType, ICollection<Ar
8696
continue;
8797
}
8898

99+
// fetch the right value connector from the collection of connectors, intended for use with this property type.
89100
// throws if not found - no need for a null check
90101
var propValueConnector = ValueConnectors.Get(propType);
91102

92-
// this should be enough for all other value connectors to work with
93-
// as all they should need is the value, and the property type infos
94-
//var mockProperty = new Property(propType);
95-
//var mockProperty = new Property(propType, row.PropertyValues[key]);
103+
// pass the value, property type and the dependencies collection to the connector to get a "artifact" value
96104
var val = row.PropertyValues[key];
97105
object parsedValue = propValueConnector.ToArtifact(val, propType, dependencies);
98106

99107
// getting Map image value umb://media/43e7401fb3cd48ceaa421df511ec703c to (nothing) - why?!
100108
_logger.Debug<NestedContentValueConnector>("Map " + key + " value '" + row.PropertyValues[key] + "' to '" + parsedValue
101109
+ "' using " + propValueConnector.GetType() + " for " + propType);
102110

103-
// test if the value is a json object (thus could be a nested complex editor)
104-
// if that's the case we'll need to add it as a json object instead of string to avoid it being escaped
105-
JToken jtokenValue = parsedValue != null && parsedValue.ToString().DetectIsJson() ? JToken.Parse(parsedValue.ToString()) : null;
106-
if (jtokenValue != null)
107-
{
108-
parsedValue = jtokenValue;
109-
}
110-
else if (parsedValue != null)
111-
{
112-
parsedValue = parsedValue.ToString();
113-
}
111+
parsedValue = parsedValue?.ToString();
114112

115113
row.PropertyValues[key] = parsedValue;
116114
}
@@ -145,25 +143,10 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
145143
throw new InvalidOperationException($"Could not resolve these content types for the Nested Content property: {string.Join(",", allContentTypes.Where(x => x.Value == null).Select(x => x.Key))}");
146144
}
147145

148-
var mocks = new Dictionary<IContentType, IContent>();
149-
150146
foreach (var row in nestedContent)
151147
{
152148
var contentType = allContentTypes[row.ContentTypeAlias];
153149

154-
// note
155-
// the way we do it here, doing content.SetValue() several time on the same content, reduces
156-
// allocations and should be ok because SetValue does not care about the previous value - would
157-
// be different for the overloads that manage eg files for uploads (not sure how NestedContent
158-
// deals with them really)
159-
160-
// we need a fake content instance to pass in to the value connector, since the value connector
161-
// wants to SetValue on an object - then we can extract the value back from that object to set
162-
// it correctly on the real instance
163-
IContent mockContent;
164-
if (!mocks.TryGetValue(contentType, out mockContent))
165-
mockContent = mocks[contentType] = new Content("NC_" + Guid.NewGuid(), -1, contentType);
166-
167150
foreach (var key in row.PropertyValues.Keys.ToArray())
168151
{
169152
// key is a system property that is added by NestedContent in Core v7.7
@@ -179,13 +162,15 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
179162
continue;
180163
}
181164

165+
// fetch the right value connector from the collection of connectors, intended for use with this property type.
182166
// throws if not found - no need for a null check
183167
var propValueConnector = ValueConnectors.Get(innerPropertyType);
184168

185169
var rowValue = row.PropertyValues[key];
186170

187171
if (rowValue != null)
188172
{
173+
// pass the artifact value and property type to the connector to get a real value from the artifact
189174
var convertedValue = propValueConnector.FromArtifact(rowValue.ToString(), innerPropertyType, null);
190175
if (convertedValue == null)
191176
{
@@ -198,17 +183,7 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
198183
}
199184
else
200185
{
201-
// test if the value is a json object (thus could be a nested complex editor)
202-
// if that's the case we'll need to add it as a json object instead of string to avoid it being escaped
203-
JToken jtokenValue = convertedValue.ToString().DetectIsJson() ? JToken.Parse(convertedValue.ToString()) : null;
204-
if (jtokenValue != null)
205-
{
206-
row.PropertyValues[key] = jtokenValue;
207-
}
208-
else
209-
{
210-
row.PropertyValues[key] = convertedValue;
211-
}
186+
row.PropertyValues[key] = convertedValue;
212187
}
213188
}
214189
else
@@ -223,12 +198,6 @@ public object FromArtifact(string value, PropertyType propertyType, object curre
223198
return value;
224199
}
225200

226-
public virtual IEnumerable<string> PropertyEditorAliases => new[] { "Our.Umbraco.NestedContent", "Umbraco.NestedContent" };
227-
228-
// cannot inject ValueConnectorCollection else of course it creates a circular (recursive) dependency,
229-
// so we have to inject it lazily and use the lazy value when actually needing it
230-
private ValueConnectorCollection ValueConnectors => _valueConnectorsLazy.Value;
231-
232201
/// <summary>
233202
/// The typed value stored for Nested Content
234203
/// </summary>
@@ -249,13 +218,6 @@ public class NestedContentValue
249218
[JsonProperty("ncContentTypeAlias")]
250219
public string ContentTypeAlias { get; set; }
251220

252-
// starting with v7.7, Core's NestedContent implement "key" as a system property
253-
// but since we are supporting pre-v7.7 including the NestedContent package, we
254-
// cannot do it this way - it's all managed "manually" when dealing with
255-
// PropertyValues.
256-
//[JsonProperty("key")]
257-
//public Guid Key { get; set; }
258-
259221
/// <summary>
260222
/// The remaining properties will be serialized to a dictionary
261223
/// </summary>

0 commit comments

Comments
 (0)