PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/Bifrost/Events/EventStream.cs

#
C# | 84 lines | 35 code | 7 blank | 42 comment | 0 complexity | 3adf80097f0a87e45907a94e6fe81c31 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  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
  22. using System;
  23. using System.Collections;
  24. using System.Collections.Generic;
  25. using System.Linq;
  26. using Bifrost.Domain;
  27. namespace Bifrost.Events
  28. {
  29. /// <summary>
  30. /// Represents a collection of events in the order that they were applied.
  31. /// </summary>
  32. public class EventStream : IEnumerable<IEvent>
  33. {
  34. /// <summary>
  35. /// Gets a list of all the events in the stream
  36. /// </summary>
  37. protected readonly List<IEvent> Events = new List<IEvent>();
  38. /// <summary>
  39. /// Initializes a new <see cref="EventStream">EventStream</see>
  40. /// </summary>
  41. /// <param name="eventSourceId">Id of the event source - typically an <see cref="AggregatedRoot">AggregatedRoot</see></param>
  42. public EventStream(Guid eventSourceId)
  43. {
  44. EventSourceId = eventSourceId;
  45. }
  46. /// <summary>
  47. /// Gets the Id of the Event Source (Aggregate Root) that this Event Stream relates to.
  48. /// </summary>
  49. public Guid EventSourceId { get; private set; }
  50. /// <summary>
  51. /// Indicates whether there are any events in the Stream.
  52. /// </summary>
  53. public bool HasEvents
  54. {
  55. get { return this.Count() > 0; }
  56. }
  57. /// <summary>
  58. /// The number of Events in the Stream.
  59. /// </summary>
  60. public int Count
  61. {
  62. get { return Events.Count; }
  63. }
  64. /// <summary>
  65. /// Get a generic enumerator to iterate over the events
  66. /// </summary>
  67. /// <returns>Enumerator</returns>
  68. public IEnumerator<IEvent> GetEnumerator()
  69. {
  70. return Events.GetEnumerator();
  71. }
  72. IEnumerator IEnumerable.GetEnumerator()
  73. {
  74. return GetEnumerator();
  75. }
  76. }
  77. }