Documentation Coverage Report
Current view: top level - Cqrs/Events - SnapshotDeserialiser.cs Hit Total Coverage
Version: 2.2 Artefacts: 3 3 100.0 %
Date: 2018-08-07 15:04:50

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

Generated by: LCOV version 1.12