PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/Source/Bifrost/Sagas/ISaga.cs

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