PageRenderTime 12ms CodeModel.GetById 5ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/Source/Bifrost/Events/EventStream.cs

#
C# | 84 lines | 35 code | 7 blank | 42 comment | 0 complexity | 3adf80097f0a87e45907a94e6fe81c31 MD5 | raw file
 1#region License
 2//
 3// Copyright (c) 2008-2012, DoLittle Studios and Komplett ASA
 4//
 5// Licensed under the Microsoft Permissive License (Ms-PL), Version 1.1 (the "License")
 6// With one exception :
 7//   Commercial libraries that is based partly or fully on Bifrost and is sold commercially, 
 8//   must obtain a commercial license.
 9//
10// You may not use this file except in compliance with the License.
11// You may obtain a copy of the license at 
12//
13//   http://bifrost.codeplex.com/license
14//
15// Unless required by applicable law or agreed to in writing, software
16// distributed under the License is distributed on an "AS IS" BASIS,
17// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18// See the License for the specific language governing permissions and
19// limitations under the License.
20//
21#endregion
22using System;
23using System.Collections;
24using System.Collections.Generic;
25using System.Linq;
26using Bifrost.Domain;
27
28namespace Bifrost.Events
29{
30    /// <summary>
31    /// Represents a collection of events in the order that they were applied.
32    /// </summary>
33    public class EventStream : IEnumerable<IEvent>
34    {
35		/// <summary>
36		/// Gets a list of all the events in the stream
37		/// </summary>
38        protected readonly List<IEvent> Events = new List<IEvent>();
39
40		/// <summary>
41		/// Initializes a new <see cref="EventStream">EventStream</see>
42		/// </summary>
43		/// <param name="eventSourceId">Id of the event source - typically an <see cref="AggregatedRoot">AggregatedRoot</see></param>
44        public EventStream(Guid eventSourceId)
45        {
46            EventSourceId = eventSourceId;
47        }
48
49        /// <summary>
50        /// Gets the Id of the Event Source (Aggregate Root) that this Event Stream relates to.
51        /// </summary>
52        public Guid EventSourceId { get; private set; }
53
54        /// <summary>
55        /// Indicates whether there are any events in the Stream.
56        /// </summary>
57        public bool HasEvents
58        {
59            get { return this.Count()  > 0; } 
60        }
61
62        /// <summary>
63        /// The number of Events in the Stream.
64        /// </summary>
65        public int Count
66        {
67            get { return Events.Count; }
68        }
69
70        /// <summary>
71        /// Get a generic enumerator to iterate over the events
72        /// </summary>
73        /// <returns>Enumerator</returns>
74        public IEnumerator<IEvent> GetEnumerator()
75        {
76            return Events.GetEnumerator();
77        }
78
79        IEnumerator IEnumerable.GetEnumerator()
80        {
81            return GetEnumerator();
82        }
83    }
84}