<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - doc-coverage.info - Cqrs.EventStore/ProjectionReader.cs</title>
  <link rel="stylesheet" type="text/css" href="../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">Documentation Coverage Report</td></tr>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../index.html">top level</a> - <a href="index.html">Cqrs.EventStore</a> - ProjectionReader.cs</td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Version:</td>
            <td class="headerValue">4.0</td>
            <td></td>
            <td class="headerItem">Artefacts:</td>
            <td class="headerCovTableEntry">4</td>
            <td class="headerCovTableEntry">4</td>
            <td class="headerCovTableEntryHi">100.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2021-04-11 22:05:22</td>
            <td></td>
          </tr>
          <tr><td><img src="../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<span class="lineNum">       1 </span>            : ﻿#region Copyright
<span class="lineNum">       2 </span>            : // // -----------------------------------------------------------------------
<span class="lineNum">       3 </span>            : // // &lt;copyright company=&quot;Chinchilla Software Limited&quot;&gt;
<span class="lineNum">       4 </span>            : // //   Copyright Chinchilla Software Limited. All rights reserved.
<span class="lineNum">       5 </span>            : // // &lt;/copyright&gt;
<span class="lineNum">       6 </span>            : // // -----------------------------------------------------------------------
<span class="lineNum">       7 </span>            : #endregion
<span class="lineNum">       8 </span>            : 
<span class="lineNum">       9 </span>            : using System;
<span class="lineNum">      10 </span>            : using System.Collections.Generic;
<span class="lineNum">      11 </span>            : using System.Linq;
<span class="lineNum">      12 </span>            : using System.Text;
<span class="lineNum">      13 </span>            : using EventStore.ClientAPI;
<span class="lineNum">      14 </span>            : using Newtonsoft.Json;
<span class="lineNum">      15 </span>            : 
<span class="lineNum">      16 </span>            : namespace Cqrs.EventStore
<span class="lineNum">      17 </span>            : {
<span class="lineNum">      18 </span>            :         /// &lt;summary&gt;
<span class="lineNum">      19 </span>            :         /// Reads projection streams from a Greg Young's Event sTore.
<span class="lineNum">      20 </span>            :         /// &lt;/summary&gt;
<span class="lineNum">      21 </span>            :         /// &lt;typeparam name=&quot;TAuthenticationToken&quot;&gt;The &lt;see cref=&quot;Type&quot;/&gt; of the authentication token.&lt;/typeparam&gt;
<span class="lineNum">      22 </span>            :         public abstract class ProjectionReader&lt;TAuthenticationToken&gt;
<span class="lineNum">      23 </span><span class="lineCov">          1 :         {</span>
<span class="lineNum">      24 </span>            :                 /// &lt;summary&gt;
<span class="lineNum">      25 </span>            :                 /// The &lt;see cref=&quot;IEventStoreConnection&quot;/&gt; used to read and write streams in the Greg Young Event Store.
<span class="lineNum">      26 </span>            :                 /// &lt;/summary&gt;
<span class="lineNum">      27 </span>            :                 protected IEventStoreConnectionHelper EventStoreConnectionHelper { get; set; }
<span class="lineNum">      28 </span>            : 
<span class="lineNum">      29 </span>            :                 /// &lt;summary&gt;
<span class="lineNum">      30 </span>            :                 /// The &lt;see cref=&quot;IEventDeserialiser{TAuthenticationToken}&quot;/&gt; used to deserialise events.
<span class="lineNum">      31 </span>            :                 /// &lt;/summary&gt;
<span class="lineNum">      32 </span>            :                 protected IEventDeserialiser&lt;TAuthenticationToken&gt; EventDeserialiser { get; set; }
<span class="lineNum">      33 </span>            : 
<span class="lineNum">      34 </span>            :                 /// &lt;summary&gt;
<span class="lineNum">      35 </span>            :                 /// Instantiates a new instance of &lt;see cref=&quot;ProjectionReader{TAuthenticationToken}&quot;/&gt;.
<span class="lineNum">      36 </span>            :                 /// &lt;/summary&gt;
<span class="lineNum">      37 </span><span class="lineCov">          1 :                 protected ProjectionReader(IEventStoreConnectionHelper eventStoreConnectionHelper, IEventDeserialiser&lt;TAuthenticationToken&gt; eventDeserialiser)</span>
<span class="lineNum">      38 </span>            :                 {
<span class="lineNum">      39 </span>            :                         EventStoreConnectionHelper = eventStoreConnectionHelper;
<span class="lineNum">      40 </span>            :                         EventDeserialiser = eventDeserialiser;
<span class="lineNum">      41 </span>            :                 }
<span class="lineNum">      42 </span>            : 
<span class="lineNum">      43 </span>            :                 /// &lt;summary&gt;
<span class="lineNum">      44 </span>            :                 /// Get a collection of data objects from a stream with the provided &lt;paramref name=&quot;streamName&quot;/&gt;.
<span class="lineNum">      45 </span>            :                 /// &lt;/summary&gt;
<span class="lineNum">      46 </span>            :                 /// &lt;param name=&quot;streamName&quot;&gt;The name of the stream to read events from.&lt;/param&gt;
<span class="lineNum">      47 </span><span class="lineCov">          1 :                 protected IEnumerable&lt;dynamic&gt; GetDataByStreamName(string streamName)</span>
<span class="lineNum">      48 </span>            :                 {
<span class="lineNum">      49 </span>            :                         StreamEventsSlice eventCollection;
<span class="lineNum">      50 </span>            :                         using (IEventStoreConnection connection = EventStoreConnectionHelper.GetEventStoreConnection())
<span class="lineNum">      51 </span>            :                         {
<span class="lineNum">      52 </span>            :                                 eventCollection = connection.ReadStreamEventsBackwardAsync(streamName, StreamPosition.End, 1, false).Result;
<span class="lineNum">      53 </span>            :                         }
<span class="lineNum">      54 </span>            :                         var jsonSerialiserSettings = EventDeserialiser.GetSerialisationSettings();
<span class="lineNum">      55 </span>            :                         var encoder = new UTF8Encoding();
<span class="lineNum">      56 </span>            :                         return
<span class="lineNum">      57 </span>            :                         (
<span class="lineNum">      58 </span>            :                                 (
<span class="lineNum">      59 </span>            :                                         (IEnumerable&lt;dynamic&gt;)eventCollection.Events
<span class="lineNum">      60 </span>            :                                         .Select(e =&gt; JsonConvert.DeserializeObject(((dynamic)encoder.GetString(e.Event.Data)), jsonSerialiserSettings))
<span class="lineNum">      61 </span>            :                                         .SingleOrDefault()
<span class="lineNum">      62 </span>            :                                 )
<span class="lineNum">      63 </span>            :                                         ??
<span class="lineNum">      64 </span>            :                                 (
<span class="lineNum">      65 </span>            :                                         Enumerable.Empty&lt;dynamic&gt;()
<span class="lineNum">      66 </span>            :                                 )
<span class="lineNum">      67 </span>            :                         )
<span class="lineNum">      68 </span>            :                         .Select(x =&gt; x.Value);
<span class="lineNum">      69 </span>            :                 }
<span class="lineNum">      70 </span>            : 
<span class="lineNum">      71 </span>            :                 /// &lt;summary&gt;
<span class="lineNum">      72 </span>            :                 /// Get a collection of &lt;typeparamref name=&quot;TData&quot;/&gt; from a stream with the provided &lt;paramref name=&quot;streamName&quot;/&gt;.
<span class="lineNum">      73 </span>            :                 /// &lt;/summary&gt;
<span class="lineNum">      74 </span>            :                 /// &lt;param name=&quot;streamName&quot;&gt;The name of the stream to read events from.&lt;/param&gt;
<span class="lineNum">      75 </span><span class="lineCov">          1 :                 protected IEnumerable&lt;TData&gt; GetDataByStreamName&lt;TData&gt;(string streamName)</span>
<span class="lineNum">      76 </span>            :                 {
<span class="lineNum">      77 </span>            :                         IList&lt;TData&gt; data = GetDataByStreamName(streamName)
<span class="lineNum">      78 </span>            :                                 .Select(e =&gt; JsonConvert.DeserializeObject&lt;TData&gt;(e.ToString()))
<span class="lineNum">      79 </span>            :                                 .Cast&lt;TData&gt;()
<span class="lineNum">      80 </span>            :                                 .ToList();
<span class="lineNum">      81 </span>            :                         return data;
<span class="lineNum">      82 </span>            :                 }
<span class="lineNum">      83 </span>            :         }
<span class="lineNum">      84 </span>            : }
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.13</a></td></tr>
  </table>
  <br>

</body>
</html>
