Documentation Coverage Report
Current view: top level - Cqrs/Events - EventDeserialiser.cs Hit Total Coverage
Version: 2.2 Artefacts: 3 3 100.0 %
Date: 2017-09-22

          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 Newtonsoft.Json;
      11             : 
      12             : namespace Cqrs.Events
      13             : {
      14             :         /// <summary>
      15             :         /// Deserialises <see cref="IEvent{TAuthenticationToken}"/> from a serialised state.
      16             :         /// </summary>
      17             :         /// <typeparam name="TAuthenticationToken">The <see cref="Type"/> of the authentication token.</typeparam>
      18             :         public class EventDeserialiser<TAuthenticationToken> : IEventDeserialiser<TAuthenticationToken>
      19           1 :         {
      20             :                 /// <summary>
      21             :                 /// The default <see cref="JsonSerializerSettings"/> to use.
      22             :                 /// </summary>
      23             :                 public static JsonSerializerSettings DefaultSettings { get; private set; }
      24             : 
      25             :                 static EventDeserialiser()
      26             :                 {
      27             :                         DefaultSettings = DefaultJsonSerializerSettings.DefaultSettings;
      28             :                 }
      29             : 
      30             :                 /// <summary>
      31             :                 /// Deserialise the provided <paramref name="eventData"/> into an <see cref="IEvent{TAuthenticationToken}"/>.
      32             :                 /// </summary>
      33             :                 /// <param name="eventData">The <see cref="EventData"/> to Deserialise.</param>
      34           1 :                 public virtual IEvent<TAuthenticationToken> Deserialise(EventData eventData)
      35             :                 {
      36             :                         JsonSerializerSettings jsonSerialiserSettings = GetSerialisationSettings();
      37             : 
      38             :                         return (IEvent<TAuthenticationToken>)JsonConvert.DeserializeObject((string)eventData.Data, Type.GetType(eventData.EventType), jsonSerialiserSettings);
      39             :                 }
      40             : 
      41             :                 /// <summary>
      42             :                 /// Returns <see cref="DefaultSettings"/>
      43             :                 /// </summary>
      44             :                 /// <returns><see cref="DefaultSettings"/></returns>
      45           1 :                 protected virtual JsonSerializerSettings GetSerialisationSettings()
      46             :                 {
      47             :                         return DefaultSettings;
      48             :                 }
      49             :         }
      50             : }

Generated by: LCOV version 1.10