Line data Source code
1 : #region Copyright
2 : // // -----------------------------------------------------------------------
3 : // // <copyright company="Chinchilla Software Limited">
4 : // // Copyright Chinchilla Software Limited. All rights reserved.
5 : // // </copyright>
6 : // // -----------------------------------------------------------------------
7 : #endregion
8 :
9 : using System;
10 : using System.Collections.Generic;
11 : using System.Runtime.Serialization;
12 : using Cqrs.Domain;
13 : using Cqrs.Messages;
14 :
15 : namespace Cqrs.Events
16 : {
17 : /// <summary>
18 : /// A <see cref="IEvent{TAuthenticationToken}"/> for <see cref="IDto"/> objects
19 : /// </summary>
20 : /// <typeparam name="TAuthenticationToken">The <see cref="Type"/> of authentication token.</typeparam>
21 : /// <typeparam name="TDto">The <see cref="Type"/> of <see cref="IDto"/> this command targets.</typeparam>
22 : [Serializable]
23 : [DataContract]
24 : public class DtoAggregateEvent<TAuthenticationToken, TDto> : IEvent<TAuthenticationToken>
25 : where TDto : IDto
26 1 : {
27 : /// <summary>
28 : /// Gets or sets the original version of the <typeparamref name="TDto"/>.
29 : /// </summary>
30 : [DataMember]
31 : public TDto Original { get; private set; }
32 :
33 : /// <summary>
34 : /// Gets or sets the new version of the <typeparamref name="TDto"/>.
35 : /// </summary>
36 : [DataMember]
37 : public TDto New { get; private set; }
38 :
39 : /// <summary>
40 : /// Instantiates a new instance of <see cref="DtoAggregateEvent{TAuthenticationToken,TDto}"/>
41 : /// </summary>
42 1 : public DtoAggregateEvent(Guid id, TDto original, TDto @new)
43 : {
44 : Id = id;
45 : Original = original;
46 : New = @new;
47 : }
48 :
49 : #region Implementation of IEvent<TAuthenticationToken>
50 :
51 : /// <summary>
52 : /// The identifier of the event itself.
53 : /// In some cases this may be the <see cref="IAggregateRoot{TAuthenticationToken}"/> or <see cref="ISaga{TAuthenticationToken}"/> this command targets.
54 : /// </summary>
55 : [DataMember]
56 : public Guid Id { get; set; }
57 :
58 : /// <summary>
59 : /// The new version number the targeted <see cref="IAggregateRoot{TAuthenticationToken}"/> or <see cref="ISaga{TAuthenticationToken}"/> that raised this.
60 : /// </summary>
61 : [DataMember]
62 : public int Version { get; set; }
63 :
64 : /// <summary>
65 : /// The date and time the event was raised or published.
66 : /// </summary>
67 : [DataMember]
68 : public DateTimeOffset TimeStamp { get; set; }
69 :
70 :
71 : #endregion
72 :
73 : /// <summary>
74 : /// Determines the <see cref="DtoAggregateEventType"/> this <see cref="IEvent{TAuthenticationToken}"/> represents.
75 : /// </summary>
76 1 : public DtoAggregateEventType GetEventType()
77 : {
78 : if (New != null && Original == null)
79 : return DtoAggregateEventType.Created;
80 : if (New != null && Original != null)
81 : return DtoAggregateEventType.Updated;
82 : if (New == null && Original != null)
83 : return DtoAggregateEventType.Deleted;
84 : return DtoAggregateEventType.Unknown;
85 : }
86 :
87 : #region Implementation of IMessageWithAuthenticationToken<TAuthenticationToken>
88 :
89 : /// <summary>
90 : /// The <typeparamref name="TAuthenticationToken"/> of the entity that triggered the event to be raised.
91 : /// </summary>
92 : [DataMember]
93 : public TAuthenticationToken AuthenticationToken { get; set; }
94 :
95 : #endregion
96 :
97 : #region Implementation of IMessage
98 :
99 : /// <summary>
100 : /// An identifier used to group together several <see cref="IMessage"/>. Any <see cref="IMessage"/> with the same <see cref="CorrelationId"/> were triggered by the same initiating request.
101 : /// </summary>
102 : [DataMember]
103 : public Guid CorrelationId { get; set; }
104 :
105 : /// <summary>
106 : /// The originating framework this message was sent from.
107 : /// </summary>
108 : [DataMember]
109 : public string OriginatingFramework { get; set; }
110 :
111 : /// <summary>
112 : /// The frameworks this <see cref="IMessage"/> has been delivered to/sent via already.
113 : /// </summary>
114 : [DataMember]
115 : public IEnumerable<string> Frameworks { get; set; }
116 :
117 : #endregion
118 : }
119 : }
|