Repository navigation
Expand file tree
/
Copy pathChangeHistoryPage.cs
More file actions
165 lines (152 loc) · 6.91 KB
/
Copy pathChangeHistoryPage.cs
File metadata and controls
165 lines (152 loc) · 6.91 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using Gx.Atom;
using Gx.Fs.Tree;
using System;
using System.Xml.Serialization;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FamilySearch.Api.Util
{
/// <summary>
/// Represents a page of change histories.
/// </summary>
public class ChangeHistoryPage : Entry
{
private readonly Feed feed;
private readonly List<ChangeEntry> entries;
/// <summary>
/// Initializes a new instance of the <see cref="ChangeHistoryPage"/> class.
/// </summary>
/// <param name="feed">The feed with change histories from which this page will be initialized.</param>
public ChangeHistoryPage(Feed feed)
{
this.feed = feed;
List<Entry> entries = feed.Entries;
List<ChangeEntry> changes = new List<ChangeEntry>();
if (entries != null)
{
foreach (Entry entry in entries)
{
changes.Add(new ChangeEntry(entry));
}
}
this.entries = changes;
}
/// <summary>
/// Gets the feed associated with this page.
/// </summary>
/// <value>
/// The feed associated with this page.
/// </value>
public Feed Feed
{
get
{
return feed;
}
}
/// <summary>
/// Gets the list of change entries associated with this page.
/// </summary>
/// <value>
/// The list of change entries associated with this page.
/// </value>
public List<ChangeEntry> Entries
{
get
{
return entries;
}
}
/// <summary>
/// Searches the current page of change entries for the type of object and operation changed.
/// </summary>
/// <param name="operation">The change operation being sought.</param>
/// <param name="objectType">The change object type being sought.</param>
/// <returns>The first <see cref="ChangeEntry"/> matching the search conditions.</returns>
public ChangeEntry FindChange(ChangeOperation operation, ChangeObjectType objectType)
{
return FindChange(operation, objectType, null);
}
/// <summary>
/// Searches the current page of change entries for the type of object and operation changed and the modifier involved.
/// </summary>
/// <param name="operation">The change operation being sought.</param>
/// <param name="objectType">The change object type being sought.</param>
/// <param name="modifier">The change object modifier involved being sought.</param>
/// <returns>
/// The first <see cref="ChangeEntry" /> matching the search conditions.
/// </returns>
public ChangeEntry FindChange(ChangeOperation operation, ChangeObjectType objectType, ChangeObjectModifier? modifier)
{
List<ChangeEntry> changes = FindChanges(operation, objectType, modifier);
return changes.Count > 0 ? changes.First() : null;
}
/// <summary>
/// Searches the current page of change entries for the type of object and operation changed.
/// </summary>
/// <param name="operation">The change operation being sought.</param>
/// <param name="objectType">The change object type being sought.</param>
/// <returns>
/// The list of <see cref="ChangeEntry" />s matching the search conditions.
/// </returns>
public List<ChangeEntry> FindChanges(ChangeOperation operation, ChangeObjectType objectType)
{
return FindChanges(new ChangeOperation[] { operation }, new ChangeObjectType[] { objectType });
}
/// <summary>
/// Searches the current page of change entries for the type of object and operation changed and the modifier involved.
/// </summary>
/// <param name="operation">The change operation being sought.</param>
/// <param name="objectType">The change object type being sought.</param>
/// <param name="modifier">The change object modifier involved being sought.</param>
/// <returns>
/// The list of <see cref="ChangeEntry" />s matching the search conditions.
/// </returns>
public List<ChangeEntry> FindChanges(ChangeOperation operation, ChangeObjectType objectType, ChangeObjectModifier? modifier)
{
return FindChanges(new ChangeOperation[] { operation }, new ChangeObjectType[] { objectType }, modifier != null ? new ChangeObjectModifier[] { modifier.Value } : Enum.GetValues(typeof(ChangeObjectModifier)).Cast<ChangeObjectModifier>());
}
/// <summary>
/// Searches the current page of change entries for the type of object and operation changed.
/// </summary>
/// <param name="operations">The collection of change operations being sought.</param>
/// <param name="types">The collection of change object types being sought.</param>
/// <returns>
/// The list of <see cref="ChangeEntry" />s matching the search conditions.
/// </returns>
public List<ChangeEntry> FindChanges(IEnumerable<ChangeOperation> operations, IEnumerable<ChangeObjectType> types)
{
return FindChanges(operations, types, Enum.GetValues(typeof(ChangeObjectModifier)).Cast<ChangeObjectModifier>());
}
/// <summary>
/// Searches the current page of change entries for the type of object and operation changed.
/// </summary>
/// <param name="operations">The collection of change operations being sought.</param>
/// <param name="types">The collection of change object types being sought.</param>
/// <param name="modifiers">The collection of change object modifiers involved being sought.</param>
/// <returns>
/// The list of <see cref="ChangeEntry" />s matching the search conditions.
/// </returns>
public List<ChangeEntry> FindChanges(IEnumerable<ChangeOperation> operations, IEnumerable<ChangeObjectType> types, IEnumerable<ChangeObjectModifier> modifiers)
{
List<ChangeEntry> changes = new List<ChangeEntry>();
foreach (ChangeEntry entry in this.entries)
{
ChangeOperation? operation = entry.Operation;
ChangeObjectType? type = entry.ObjectType;
ChangeObjectModifier? modifier = entry.ObjectModifier;
if (operation != null && type != null & operations.Contains(operation.Value) && types.Contains(type.Value))
{
if (modifier == null || modifiers.Contains(modifier.Value))
{
changes.Add(entry);
}
}
}
return changes;
}
}
}