PageRenderTime 47ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/Bifrost/Sagas/ISaga.cs

#
C# | 187 lines | 39 code | 27 blank | 121 comment | 0 complexity | 7192f5c5a1954ea197e13db5e48a218b 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.Generic;
  24. using Bifrost.Events;
  25. using System.Reflection;
  26. using Bifrost.Sagas.Exceptions;
  27. namespace Bifrost.Sagas
  28. {
  29. /// <summary>
  30. /// Defines a saga
  31. /// </summary>
  32. public interface ISaga : IEventStore
  33. {
  34. /// <summary>
  35. /// Gets or sets the unique identifier of a saga
  36. /// </summary>
  37. Guid Id { get; set; }
  38. /// <summary>
  39. /// Gets or sets what partition the saga belongs to
  40. /// </summary>
  41. /// <remarks>
  42. /// Partitions are used to group sagas into logical partitions
  43. /// </remarks>
  44. string Partition { get; set; }
  45. /// <summary>
  46. /// Gets or sets the unique key within a partition for a saga
  47. /// </summary>
  48. string Key { get; set; }
  49. /// <summary>
  50. /// Gets the chapters in the saga
  51. /// </summary>
  52. IEnumerable<IChapter> Chapters { get; }
  53. /// <summary>
  54. /// Gets the current chapter in the saga
  55. /// </summary>
  56. IChapter CurrentChapter { get; }
  57. /// <summary>
  58. /// Set the current chapter
  59. /// </summary>
  60. /// <param name="chapter"><see cref="IChapter"/> to set as current</param>
  61. void SetCurrentChapter(IChapter chapter);
  62. /// <summary>
  63. /// Set the current chapter
  64. /// </summary>
  65. /// <typeparam name="T"><see cref="IChapter"/> to set as current</typeparam>
  66. void SetCurrentChapter<T>() where T : IChapter;
  67. /// <summary>
  68. /// Add a chapter to the saga
  69. /// </summary>
  70. /// <param name="chapter"><see cref="IChapter"/> to add</param>
  71. void AddChapter(IChapter chapter);
  72. /// <summary>
  73. /// Check if the saga contains a chapter based on the type of the chapter
  74. /// </summary>
  75. /// <typeparam name="T">Type of <see cref="IChapter"/> to check if saga contains</typeparam>
  76. /// <returns></returns>
  77. bool Contains<T>() where T : IChapter;
  78. /// <summary>
  79. /// Check if the saga contains a chapter based on the type of the chapter
  80. /// </summary>
  81. /// <param name="type">Chapter type</param>
  82. /// <returns></returns>
  83. bool Contains(Type type);
  84. /// <summary>
  85. /// Get a specific chapter by type
  86. /// </summary>
  87. /// <typeparam name="T">Type of <see cref="IChapter"/> to get</typeparam>
  88. /// <returns>Instance of chapter</returns>
  89. /// <exception cref="ChapterDoesNotExistException">Thrown if chapter not in saga</exception>
  90. T Get<T>() where T : IChapter;
  91. /// <summary>
  92. /// Gets an array of PropertyInfo objects that reflect any Chapter instances that are available
  93. /// as properties on the Saga
  94. /// </summary>
  95. PropertyInfo[] ChapterProperties { get; }
  96. /// <summary>
  97. /// Gets and sets the SagaState. Only to be used directly by serialization.
  98. /// </summary>
  99. SagaState CurrentState { get; set; }
  100. /// <summary>
  101. /// Indicates whether the saga is continuing
  102. /// </summary>
  103. /// <returns></returns>
  104. bool IsNew { get; }
  105. /// <summary>
  106. /// Indicates whether the saga has Begun
  107. /// </summary>
  108. /// <returns></returns>
  109. bool IsBegun { get; }
  110. /// <summary>
  111. /// Indicates whether the saga is continuing
  112. /// </summary>
  113. /// <returns></returns>
  114. bool IsContinuing { get; }
  115. /// <summary>
  116. /// Indicates whether the saga is concluded
  117. /// </summary>
  118. /// <returns></returns>
  119. bool IsConcluded { get; }
  120. /// <summary>
  121. /// Begins the Saga
  122. /// </summary>
  123. void Begin();
  124. /// <summary>
  125. /// Continues the Saga
  126. /// </summary>
  127. void Continue();
  128. /// <summary>
  129. /// Concludes the Saga
  130. /// </summary>
  131. void Conclude();
  132. /// <summary>
  133. /// Method that is executed when the Saga is beginning.
  134. /// </summary>
  135. void OnBegin();
  136. /// <summary>
  137. /// Method that is executed when the Saga is continuing.
  138. /// </summary>
  139. void OnContinue();
  140. /// <summary>
  141. /// Method that is executed when the Saga is concludiung.
  142. /// </summary>
  143. void OnConclude();
  144. /// <summary>
  145. /// Get uncommitted events from the <see cref="ISaga"/>
  146. /// </summary>
  147. /// <returns></returns>
  148. IEnumerable<IEvent> GetUncommittedEvents();
  149. /// <summary>
  150. /// Set any uncommitted into the <see cref="ISaga"/>
  151. /// </summary>
  152. /// <param name="events"></param>
  153. void SetUncommittedEvents(IEnumerable<IEvent> events);
  154. /// <summary>
  155. /// Save any uncommitted events to a given <see cref="IEventStore"/>
  156. /// </summary>
  157. /// <param name="eventStore"><see cref="IEventStore"/> to save the events to</param>
  158. void SaveUncommittedEventsToEventStore(IEventStore eventStore);
  159. }
  160. }