@@ -60,27 +60,24 @@ public string GetValue(Property property, ICollection<ArtifactDependency> depend
60
60
if ( innerContent == null )
61
61
return null ;
62
62
63
- var allContentTypes = innerContent . Select ( x => x . IcContentTypeAlias )
64
- . Distinct ( )
65
- . ToDictionary ( a => a , a => _contentTypeService . GetContentType ( a ) ) ;
66
-
67
- //Ensure all of these content types are found
68
- if ( allContentTypes . Values . Any ( contentType => contentType == null ) )
69
- {
70
- throw new InvalidOperationException ( $ "Could not resolve these content types for the Inner Content property: { string . Join ( "," , allContentTypes . Where ( x => x . Value == null ) . Select ( x => x . Key ) ) } ") ;
71
- }
72
-
73
- //Ensure that these content types have dependencies added
74
- foreach ( var contentType in allContentTypes . Values )
75
- {
76
- dependencies . Add ( new ArtifactDependency ( contentType . GetUdi ( ) , false , ArtifactDependencyMode . Match ) ) ;
77
- }
78
-
79
- foreach ( var row in innerContent )
63
+ var distinctContentTypes = new Dictionary < GuidUdi , IContentType > ( ) ;
64
+ foreach ( var innerContentItem in innerContent )
80
65
{
81
- var contentType = allContentTypes [ row . IcContentTypeAlias ] ;
66
+ var contentType = _contentTypeService . GetContentType ( innerContentItem . IcContentTypeGuid ) ;
67
+ if ( contentType == null )
68
+ contentType = _contentTypeService . GetContentType ( innerContentItem . IcContentTypeAlias ) ;
69
+ if ( contentType == null )
70
+ throw new InvalidOperationException ( $ "Could not resolve these content types for the Inner Content property with key: { innerContentItem . Key } , and name: { innerContentItem . Name } ") ;
71
+
72
+ // ensure the content type is added as a unique dependency
73
+ var contentTypeUdi = contentType . GetUdi ( ) ;
74
+ if ( distinctContentTypes . ContainsKey ( contentTypeUdi ) == false )
75
+ {
76
+ distinctContentTypes . Add ( contentTypeUdi , contentType ) ;
77
+ dependencies . Add ( new ArtifactDependency ( contentTypeUdi , false , ArtifactDependencyMode . Match ) ) ;
78
+ }
82
79
83
- foreach ( var key in row . PropertyValues . Keys . ToArray ( ) )
80
+ foreach ( var key in innerContentItem . PropertyValues . Keys . ToArray ( ) )
84
81
{
85
82
var propertyType = contentType . CompositionPropertyTypes . FirstOrDefault ( x => x . Alias == key ) ;
86
83
@@ -95,7 +92,7 @@ public string GetValue(Property property, ICollection<ArtifactDependency> depend
95
92
96
93
// this should be enough for all other value connectors to work with
97
94
// as all they should need is the value, and the property type infos
98
- var mockProperty = new Property ( propertyType , row . PropertyValues [ key ] ) ;
95
+ var mockProperty = new Property ( propertyType , innerContentItem . PropertyValues [ key ] ) ;
99
96
100
97
object parsedValue = propValueConnector . GetValue ( mockProperty , dependencies ) ;
101
98
@@ -111,7 +108,7 @@ public string GetValue(Property property, ICollection<ArtifactDependency> depend
111
108
parsedValue = parsedValue . ToString ( ) ;
112
109
}
113
110
114
- row . PropertyValues [ key ] = parsedValue ;
111
+ innerContentItem . PropertyValues [ key ] = parsedValue ;
115
112
}
116
113
}
117
114
@@ -147,21 +144,16 @@ public void SetValue(IContentBase content, string alias, string value)
147
144
if ( innerContent == null )
148
145
return ;
149
146
150
- var allContentTypes = innerContent . Select ( x => x . IcContentTypeAlias )
151
- . Distinct ( )
152
- . ToDictionary ( a => a , a => _contentTypeService . GetContentType ( a ) ) ;
153
-
154
- //Ensure all of these content types are found
155
- if ( allContentTypes . Values . Any ( contentType => contentType == null ) )
147
+ foreach ( var innerContentItem in innerContent )
156
148
{
157
- throw new InvalidOperationException ( $ "Could not resolve these content types for the Inner Content property: { string . Join ( "," , allContentTypes . Where ( x => x . Value == null ) . Select ( x => x . Key ) ) } ") ;
158
- }
149
+ var contentType = _contentTypeService . GetContentType ( innerContentItem . IcContentTypeGuid ) ;
150
+ if ( contentType == null )
151
+ contentType = _contentTypeService . GetContentType ( innerContentItem . IcContentTypeAlias ) ;
152
+ if ( contentType == null )
153
+ throw new InvalidOperationException ( $ "Could not resolve these content types for the Inner Content property with key: { innerContentItem . Key } , and name: { innerContentItem . Name } ") ;
159
154
160
- var mocks = new Dictionary < IContentType , IContent > ( ) ;
161
155
162
- foreach ( var row in innerContent )
163
- {
164
- var contentType = allContentTypes [ row . IcContentTypeAlias ] ;
156
+ var mocks = new Dictionary < IContentType , IContent > ( ) ;
165
157
166
158
// note
167
159
// the way we do it here, doing content.SetValue() several time on the same content, reduces
@@ -176,7 +168,7 @@ public void SetValue(IContentBase content, string alias, string value)
176
168
if ( ! mocks . TryGetValue ( contentType , out mockContent ) )
177
169
mockContent = mocks [ contentType ] = new Content ( "IC_" + Guid . NewGuid ( ) , - 1 , contentType ) ;
178
170
179
- foreach ( var key in row . PropertyValues . Keys . ToArray ( ) )
171
+ foreach ( var key in innerContentItem . PropertyValues . Keys . ToArray ( ) )
180
172
{
181
173
var propertyType = contentType . CompositionPropertyTypes . FirstOrDefault ( x => x . Alias == key ) ;
182
174
@@ -189,7 +181,7 @@ public void SetValue(IContentBase content, string alias, string value)
189
181
// throws if not found - no need for a null check
190
182
var propValueConnector = ValueConnectors . Get ( propertyType ) ;
191
183
192
- var rowValue = row . PropertyValues [ key ] ;
184
+ var rowValue = innerContentItem . PropertyValues [ key ] ;
193
185
194
186
if ( rowValue != null )
195
187
{
@@ -198,7 +190,7 @@ public void SetValue(IContentBase content, string alias, string value)
198
190
// integers needs to be converted into strings
199
191
if ( convertedValue is int )
200
192
{
201
- row . PropertyValues [ key ] = convertedValue . ToString ( ) ;
193
+ innerContentItem . PropertyValues [ key ] = convertedValue . ToString ( ) ;
202
194
}
203
195
else
204
196
{
@@ -207,17 +199,17 @@ public void SetValue(IContentBase content, string alias, string value)
207
199
var jtokenValue = convertedValue . ToString ( ) . DetectIsJson ( ) ? JToken . Parse ( convertedValue . ToString ( ) ) : null ;
208
200
if ( jtokenValue != null )
209
201
{
210
- row . PropertyValues [ key ] = jtokenValue ;
202
+ innerContentItem . PropertyValues [ key ] = jtokenValue ;
211
203
}
212
204
else
213
205
{
214
- row . PropertyValues [ key ] = convertedValue ;
206
+ innerContentItem . PropertyValues [ key ] = convertedValue ;
215
207
}
216
208
}
217
209
}
218
210
else
219
211
{
220
- row . PropertyValues [ key ] = rowValue ;
212
+ innerContentItem . PropertyValues [ key ] = rowValue ;
221
213
}
222
214
}
223
215
}
@@ -250,6 +242,8 @@ public class InnerContentValue
250
242
public string Icon { get ; set ; }
251
243
[ JsonProperty ( "icContentTypeAlias" ) ]
252
244
public string IcContentTypeAlias { get ; set ; }
245
+ [ JsonProperty ( "icContentTypeGuid" ) ]
246
+ public Guid IcContentTypeGuid { get ; set ; }
253
247
254
248
/// <summary>
255
249
/// The remaining properties will be serialized to a dictionary
0 commit comments