-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathMultiUrls.cs
80 lines (67 loc) · 1.99 KB
/
MultiUrls.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
namespace RJP.MultiUrlPicker.Models
{
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Umbraco.Core.Logging;
[Obsolete("Use IEnumerable<Link> instead")]
public class MultiUrls : IEnumerable<Link>
{
private readonly string _propertyData;
private readonly List<Link> _multiUrls = new List<Link>();
internal MultiUrls()
{
}
internal MultiUrls(JArray propertyData)
{
_propertyData = propertyData.ToString();
Initialize(propertyData);
}
public MultiUrls(string propertyData)
{
_propertyData = propertyData;
if (!string.IsNullOrEmpty(propertyData))
{
var relatedLinks = JsonConvert.DeserializeObject<JArray>(propertyData);
Initialize(relatedLinks);
}
}
private void Initialize(JArray data)
{
foreach (var item in data)
{
var newLink = new Link(item);
if (!newLink.Deleted)
{
_multiUrls.Add(new Link(item));
}
else
{
LogHelper.Info<MultiUrls>("Skipped link as the node has been unpublished/deleted (UDI: {0})", () => newLink.Udi);
}
}
}
public string PropertyData
{
get
{
return _propertyData;
}
}
// Although this method seems unnecessary it makes .Any() available in Dynamics
public bool Any()
{
return Enumerable.Any(this);
}
public IEnumerator<Link> GetEnumerator()
{
return _multiUrls.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}