Documentation Coverage Report
Current view: top level - Cqrs.WebApi - CqrsEventApiController.cs Hit Total Coverage
Version: 2.2 Artefacts: 5 5 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 System.Collections.Generic;
      11             : using cdmdotnet.Logging;
      12             : using Cqrs.Authentication;
      13             : using Cqrs.Configuration;
      14             : using Cqrs.Events;
      15             : using Cqrs.Messages;
      16             : using Cqrs.Services;
      17             : 
      18             : namespace Cqrs.WebApi
      19             : {
      20             :         /// <summary>
      21             :         /// A <see cref="CqrsApiController"/> that includes an implementation of the <see cref="IEventService{TAuthenticationToken}.GetEventData"/> method
      22             :         /// </summary>
      23             :         public abstract class CqrsEventApiController<TSingleSignOnToken>
      24             :                 : CqrsApiController
      25             :                 , IEventService<TSingleSignOnToken>
      26           1 :         {
      27             :                 /// <summary>
      28             :                 /// Instantiates a new instance of <see cref="CqrsEventApiController{TSingleSignOnToken}"/>.
      29             :                 /// </summary>
      30           1 :                 protected CqrsEventApiController(ILogger logger, ICorrelationIdHelper correlationIdHelper, IAuthenticationTokenHelper<TSingleSignOnToken> authenticationTokenHelper, IEventStore<TSingleSignOnToken> eventStore, IConfigurationManager configurationManager)
      31             :                         : base(logger, correlationIdHelper, configurationManager)
      32             :                 {
      33             :                         AuthenticationTokenHelper = authenticationTokenHelper;
      34             :                         EventStore = eventStore;
      35             :                 }
      36             : 
      37             :                 /// <summary>
      38             :                 /// Gets or set the <see cref="IAuthenticationTokenHelper{TAuthenticationToken}"/>.
      39             :                 /// </summary>
      40             :                 protected IAuthenticationTokenHelper<TSingleSignOnToken> AuthenticationTokenHelper { get; private set; }
      41             : 
      42             :                 /// <summary>
      43             :                 /// Gets or set the <see cref="IEventStore{TAuthenticationToken}"/>.
      44             :                 /// </summary>
      45             :                 protected virtual IEventStore<TSingleSignOnToken> EventStore { get; private set; }
      46             : 
      47             : 
      48             :                 #region Implementation of IEventService<SingleSignOnToken>
      49             : 
      50             :                 /// <summary>
      51             :                 /// Get all <see cref="IEvent{TAuthenticationToken}">events</see>
      52             :                 /// raised with the same <see cref="IMessage.CorrelationId"/>.
      53             :                 /// </summary>
      54             :                 /// <param name="serviceRequest">The <see cref="IMessage.CorrelationId"/> of the <see cref="IEvent{TAuthenticationToken}">events</see> to find.</param>
      55             :                 /// <returns>A collection of <see cref="EventData">event data</see></returns>
      56             :                 IServiceResponseWithResultData<IEnumerable<EventData>> IEventService<TSingleSignOnToken>.GetEventData(IServiceRequestWithData<TSingleSignOnToken, Guid> serviceRequest)
      57             :                 {
      58             :                         return GetEventData(serviceRequest);
      59             :                 }
      60             : 
      61             :                 /// <summary>
      62             :                 /// Get all <see cref="IEvent{TAuthenticationToken}">events</see>
      63             :                 /// raised with the same <see cref="IMessage.CorrelationId"/>.
      64             :                 /// </summary>
      65             :                 /// <param name="serviceRequest">The <see cref="IMessage.CorrelationId"/> of the <see cref="IEvent{TAuthenticationToken}">events</see> to find.</param>
      66             :                 /// <returns>A collection of <see cref="EventData">event data</see></returns>
      67           1 :                 protected virtual IServiceResponseWithResultData<IEnumerable<EventData>> GetEventData(IServiceRequestWithData<TSingleSignOnToken, Guid> serviceRequest)
      68             :                 {
      69             :                         AuthenticationTokenHelper.SetAuthenticationToken(serviceRequest.AuthenticationToken);
      70             :                         CorrelationIdHelper.SetCorrelationId(serviceRequest.CorrelationId);
      71             : 
      72             :                         OnGetEventData(serviceRequest);
      73             :                         IEnumerable<EventData> results = EventStore.Get(serviceRequest.Data);
      74             :                         results = OnGotEventData(serviceRequest, results);
      75             : 
      76             :                         return new ServiceResponseWithResultData<IEnumerable<EventData>>
      77             :                         {
      78             :                                 State = ServiceResponseStateType.Succeeded,
      79             :                                 ResultData = results,
      80             :                                 CorrelationId = CorrelationIdHelper.GetCorrelationId()
      81             :                         };
      82             :                 }
      83             : 
      84             :                 #endregion
      85             : 
      86             :                 /// <summary>
      87             :                 /// Executed before calling the <see cref="IEventStore{TAuthenticationToken}.Get(System.Type,System.Guid,bool,int)"/> method on <see cref="EventStore"/>
      88             :                 /// in <see cref="GetEventData"/>.
      89             :                 /// </summary>
      90             :                 /// <param name="serviceRequest">The original <see cref="IServiceRequestWithData{TAuthenticationToken,Guid}"/>.</param>
      91           1 :                 protected virtual void OnGetEventData(IServiceRequestWithData<TSingleSignOnToken, Guid> serviceRequest) { }
      92             : 
      93             :                 /// <summary>
      94             :                 /// Executed after calling the <see cref="IEventStore{TAuthenticationToken}.Get(System.Type,System.Guid,bool,int)"/> method on <see cref="EventStore"/>
      95             :                 /// in <see cref="GetEventData"/>.
      96             :                 /// </summary>
      97             :                 /// <param name="serviceRequest">The original <see cref="IServiceRequestWithData{TAuthenticationToken,Guid}"/>.</param>
      98             :                 /// <param name="results">The collection of <see cref="IEvent{TAuthenticationToken}">events</see> from the <see cref="EventStore"/>.</param>
      99           1 :                 protected virtual IEnumerable<EventData> OnGotEventData(IServiceRequestWithData<TSingleSignOnToken, Guid> serviceRequest, IEnumerable<EventData> results)
     100             :                 {
     101             :                         return results;
     102             :                 }
     103             :         }
     104             : }

Generated by: LCOV version 1.12