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 Cqrs.Events;
11 : using Cqrs.Snapshots;
12 :
13 : namespace Cqrs.MongoDB.Serialisers
14 : {
15 : /// <summary>
16 : /// Builds <see cref="EventData"/> from various input formats.
17 : /// </summary>
18 : public class MongoDbSnapshotBuilder
19 : : SnapshotBuilder
20 1 : {
21 : #region Implementation of IEventBuilder<TAuthenticationToken>
22 :
23 : /// <summary>
24 : /// Create an <see cref="EventData">framework event</see> with the provided <paramref name="snapshot"/>.
25 : /// </summary>
26 : /// <param name="type">The name of the <see cref="Type"/> of the target object the serialised data is.</param>
27 : /// <param name="snapshot">The <see cref="Snapshot"/> to add to the <see cref="EventData"/>.</param>
28 1 : public override EventData CreateFrameworkEvent(string type, Snapshot snapshot)
29 : {
30 : return new EventData
31 : {
32 : EventId = Guid.NewGuid(),
33 : EventType = type,
34 : Data = snapshot
35 : };
36 : }
37 :
38 : /// <summary>
39 : /// Serialise the provided <paramref name="snapshot"/> into a <see cref="string"/>.
40 : /// </summary>
41 : /// <param name="snapshot">The <see cref="Snapshot"/> to serialise.</param>
42 1 : protected override string SerialiseEventDataToString(Snapshot snapshot)
43 : {
44 : throw new InvalidOperationException("MongoDB doesn't use strings.");
45 : }
46 :
47 : #endregion
48 : }
49 : }
|