-
Notifications
You must be signed in to change notification settings - Fork 2
/
EventCollection.cs
75 lines (66 loc) · 2.45 KB
/
EventCollection.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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using GalleryServerPro.Business.Interfaces;
namespace GalleryServerPro.Events
{
/// <summary>
/// A collection of <see cref="IEvent" /> objects.
/// </summary>
public class EventCollection : Collection<IEvent>, IEventCollection
{
/// <summary>
/// Initializes a new instance of the <see cref="EventCollection"/> class.
/// </summary>
public EventCollection()
: base(new List<IEvent>())
{
}
/// <summary>
/// Finds the application event with the specified <paramref name="eventId" /> or null if not found.
/// </summary>
/// <param name="eventId">The value that uniquely identifies the application event (<see cref="IEvent.EventId" />).</param>
/// <returns>Returns an <see cref="IEvent" /> or null.</returns>
public IEvent FindById(int eventId)
{
// We know Items is actually a List<IEvent> because we specified it in the constructor.
return ((List<IEvent>)Items).Find(ev => (ev.EventId == eventId));
}
/// <summary>
/// Sort the objects in this collection based on the <see cref="IEvent.TimestampUtc"/> property,
/// with the most recent timestamp first.
/// </summary>
public void Sort()
{
// We know Items is actually a List<IEvent> because we passed it to the constructor.
((List<IEvent>)Items).Sort();
}
/// <summary>
/// Adds the application events to the current collection.
/// </summary>
/// <param name="events">The application events to add to the current collection.</param>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="events" /> is null.</exception>
public void AddRange(IEnumerable<IEvent> events)
{
if (events == null)
throw new ArgumentNullException("events");
foreach (var appError in events)
{
Add(appError);
}
}
/// <summary>
/// Gets the application events associated with the specified gallery.
/// </summary>
/// <param name="galleryId">The gallery ID.</param>
/// <returns>Returns an <see cref="IEventCollection" /> containing events corresponding to the specified parameters.</returns>
public IEventCollection FindAllForGallery(int galleryId)
{
// We know Items is actually a List<IEvent> because we passed it to the constructor.
var events = (List<IEvent>)Items;
IEventCollection matchingEvents = new EventCollection();
matchingEvents.AddRange(events.FindAll(ev => (ev.GalleryId == galleryId)));
return matchingEvents;
}
}
}