1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Text . RegularExpressions ;
4
4
using Newtonsoft . Json ;
@@ -64,7 +64,6 @@ public sealed override string ToArtifact(object value, PropertyType propertyType
64
64
}
65
65
66
66
var valueAsJToken = JToken . Parse ( svalue ) ;
67
-
68
67
if ( valueAsJToken is JArray )
69
68
{
70
69
// Multiple links, parse as JArray
@@ -114,9 +113,9 @@ public sealed override string ToArtifact(object value, PropertyType propertyType
114
113
}
115
114
else if ( isMedia && TryParseJTokenAttr ( link , "url" , out string url ) )
116
115
{
117
- // This state can happen due to an issue in RJP.MultiUrlPicker(or our linkPicker in RTE which it relies on),
118
- // where you edit a media link, and just hit "Select".
119
- // That will set the id to null, but the url will still be filled. We try to get the media item, and if so add it as
116
+ // This state can happen due to an issue in RJP.MultiUrlPicker(or our linkPicker in RTE which it relies on),
117
+ // where you edit a media link, and just hit "Select".
118
+ // That will set the id to null, but the url will still be filled. We try to get the media item, and if so add it as
120
119
// a dependency to the package. If we can't find it, we abort(aka continue)
121
120
var entry = _mediaService . GetMediaByPath ( url ) ;
122
121
if ( entry == null )
@@ -132,6 +131,7 @@ public sealed override string ToArtifact(object value, PropertyType propertyType
132
131
link [ "url" ] = udi . ToString ( ) ;
133
132
}
134
133
}
134
+
135
135
return JsonConvert . SerializeObject ( links ) ;
136
136
}
137
137
@@ -145,11 +145,9 @@ public sealed override string ToArtifact(object value, PropertyType propertyType
145
145
}
146
146
147
147
var isMedia = link [ "isMedia" ] != null ;
148
- int intId ;
149
- string url ;
150
- GuidUdi guidUdi ;
148
+
151
149
// Only do processing if the Id is set on the element. OR if the url is set and its a media item
152
- if ( TryParseJTokenAttr ( link , "id" , out intId ) )
150
+ if ( TryParseJTokenAttr ( link , "id" , out int intId ) )
153
151
{
154
152
// Checks weather we are resolving a media item or a document
155
153
var objectTypeId = isMedia
@@ -169,19 +167,19 @@ public sealed override string ToArtifact(object value, PropertyType propertyType
169
167
link [ "id" ] = udi . ToString ( ) ;
170
168
}
171
169
}
172
- else if ( TryParseJTokenAttr ( link , "udi" , out guidUdi ) )
170
+ else if ( TryParseJTokenAttr ( link , "udi" , out GuidUdi guidUdi ) )
173
171
{
174
172
if ( contextCache . EntityExists ( _entityService , guidUdi . Guid ) )
175
173
{
176
174
// Add the artifact dependency
177
175
dependencies . Add ( new ArtifactDependency ( guidUdi , false , ArtifactDependencyMode . Exist ) ) ;
178
176
}
179
177
}
180
- else if ( isMedia && TryParseJTokenAttr ( link , "url" , out url ) )
178
+ else if ( isMedia && TryParseJTokenAttr ( link , "url" , out string url ) )
181
179
{
182
- // This state can happen due to an issue in RJP.MultiUrlPicker(or our linkPicker in RTE which it relies on),
183
- // where you edit a media link, and just hits "Select".
184
- // That will set the id to null, but the url will still be filled. We try to get the media item, and if so add it as
180
+ // This state can happen due to an issue in RJP.MultiUrlPicker(or our linkPicker in RTE which it relies on),
181
+ // where you edit a media link, and just hits "Select".
182
+ // That will set the id to null, but the url will still be filled. We try to get the media item, and if so add it as
185
183
// a dependency to the package. If we can't find it, we abort(aka continue)
186
184
var entry = _mediaService . GetMediaByPath ( url ) ;
187
185
if ( entry != null )
@@ -194,10 +192,11 @@ public sealed override string ToArtifact(object value, PropertyType propertyType
194
192
link [ "url" ] = udi . ToString ( ) ;
195
193
}
196
194
}
195
+
197
196
return JsonConvert . SerializeObject ( link ) ;
198
197
}
199
198
200
- //if none of the above...
199
+ // If none of the above...
201
200
return string . Empty ;
202
201
}
203
202
@@ -209,19 +208,16 @@ public sealed override object FromArtifact(string value, PropertyType propertyTy
209
208
}
210
209
211
210
var valueAsJToken = JToken . Parse ( value ) ;
212
-
213
211
if ( valueAsJToken is JArray )
214
212
{
215
- //Multiple links, parse as JArray
213
+ // Multiple links, parse as JArray
216
214
var links = JsonConvert . DeserializeObject < JArray > ( value ) ;
217
215
if ( links != null )
218
216
{
219
217
foreach ( var link in links )
220
218
{
221
- GuidUdi udi ;
222
- string url ;
223
219
// Only do processing on an item if the Id or the url is set
224
- if ( TryParseJTokenAttr ( link , "id" , out udi ) )
220
+ if ( TryParseJTokenAttr ( link , "id" , out GuidUdi udi ) )
225
221
{
226
222
// Check the type of the link
227
223
var nodeObjectType = link [ "isMedia" ] != null
@@ -237,15 +233,15 @@ public sealed override object FromArtifact(string value, PropertyType propertyTy
237
233
link [ "id" ] = idAttempt . Success ? idAttempt . Result : 0 ;
238
234
}
239
235
}
240
- else if ( TryParseJTokenAttr ( link , "url" , out url ) )
236
+ else if ( TryParseJTokenAttr ( link , "url" , out string url ) )
241
237
{
242
238
// Check whether the url attribute of the link contains a udi, if so, replace it with the
243
239
// path to the file, i.e. the regex replaces <udi> with /path/to/file
244
240
var newUrl = MediaUdiSrcRegex . Replace ( url , match =>
245
241
{
246
242
var udiString = match . Groups [ "udi" ] . ToString ( ) ;
247
- GuidUdi foundUdi ;
248
- if ( GuidUdi . TryParse ( udiString , out foundUdi ) && foundUdi . EntityType == Constants . UdiEntityType . Media )
243
+ if ( GuidUdi . TryParse ( udiString , out var foundUdi ) &&
244
+ foundUdi . EntityType == Constants . UdiEntityType . Media )
249
245
{
250
246
// (take care of nulls)
251
247
var media = _mediaService . GetById ( foundUdi . Guid ) ;
@@ -254,23 +250,24 @@ public sealed override object FromArtifact(string value, PropertyType propertyTy
254
250
return media . GetUrl ( "umbracoFile" , _logger ) ;
255
251
}
256
252
}
253
+
257
254
return string . Empty ;
258
255
} ) ;
256
+
259
257
link [ "url" ] = newUrl ;
260
258
}
261
259
}
260
+
262
261
value = JsonConvert . SerializeObject ( links ) ;
263
262
}
264
263
}
265
264
else if ( valueAsJToken is JObject )
266
265
{
267
- //Single link, parse as JToken
266
+ // Single link, parse as JToken
268
267
var link = JsonConvert . DeserializeObject < JToken > ( value ) ;
269
268
270
- GuidUdi udi ;
271
- string url ;
272
269
// Only do processing on an item if the Id or the url is set
273
- if ( TryParseJTokenAttr ( link , "id" , out udi ) )
270
+ if ( TryParseJTokenAttr ( link , "id" , out GuidUdi udi ) )
274
271
{
275
272
// Check the type of the link
276
273
var nodeObjectType = link [ "isMedia" ] != null
@@ -286,15 +283,14 @@ public sealed override object FromArtifact(string value, PropertyType propertyTy
286
283
link [ "id" ] = idAttempt . Success ? idAttempt . Result : 0 ;
287
284
}
288
285
}
289
- else if ( TryParseJTokenAttr ( link , "url" , out url ) )
286
+ else if ( TryParseJTokenAttr ( link , "url" , out string url ) )
290
287
{
291
- // Check whether the url attribute of the link contains a udi, if so, replace it with the
288
+ // Check whether the url attribute of the link contains a udi, if so, replace it with the
292
289
// path to the file, i.e. the regex replaces <udi> with /path/to/file
293
290
var newUrl = MediaUdiSrcRegex . Replace ( url , match =>
294
291
{
295
292
var udiString = match . Groups [ "udi" ] . ToString ( ) ;
296
- GuidUdi foundUdi ;
297
- if ( GuidUdi . TryParse ( udiString , out foundUdi ) &&
293
+ if ( GuidUdi . TryParse ( udiString , out var foundUdi ) &&
298
294
foundUdi . EntityType == Constants . UdiEntityType . Media )
299
295
{
300
296
// (take care of nulls)
@@ -307,6 +303,7 @@ public sealed override object FromArtifact(string value, PropertyType propertyTy
307
303
308
304
return string . Empty ;
309
305
} ) ;
306
+
310
307
link [ "url" ] = newUrl ;
311
308
}
312
309
@@ -323,6 +320,7 @@ private bool TryParseJTokenAttr(JToken link, string attrName, out int attrValue)
323
320
var val = link [ attrName ] . ToString ( ) ;
324
321
return int . TryParse ( val , out attrValue ) ;
325
322
}
323
+
326
324
attrValue = 0 ;
327
325
return false ;
328
326
}
@@ -334,6 +332,7 @@ private bool TryParseJTokenAttr(JToken link, string attrName, out GuidUdi attrVa
334
332
var val = link [ attrName ] . ToString ( ) ;
335
333
return GuidUdi . TryParse ( val , out attrValue ) ;
336
334
}
335
+
337
336
attrValue = null ;
338
337
return false ;
339
338
}
@@ -349,7 +348,8 @@ private bool TryParseJTokenAttr(JToken link, string attrName, out string strAttr
349
348
return true ;
350
349
}
351
350
}
352
- strAttr = "" ;
351
+
352
+ strAttr = string . Empty ;
353
353
return false ;
354
354
}
355
355
}
0 commit comments