Documentation Coverage Report
Current view: top level - Azure/Cqrs.Azure.DocumentDb/Events - AzureDocumentDbEventStoreConnectionStringFactory.cs Hit Total Coverage
Version: 2.2 Artefacts: 7 7 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 cdmdotnet.Logging;
      11             : using Cqrs.Configuration;
      12             : using Cqrs.Events;
      13             : using Microsoft.Azure.Documents.Client;
      14             : 
      15             : namespace Cqrs.Azure.DocumentDb.Events
      16             : {
      17             :         /// <summary>
      18             :         /// A factory for getting connections and database names for <see cref="IEventStore{TAuthenticationToken}"/> access.
      19             :         /// </summary>
      20             :         public class AzureDocumentDbEventStoreConnectionStringFactory : IAzureDocumentDbEventStoreConnectionStringFactory
      21           1 :         {
      22             :                 /// <summary>
      23             :                 /// Gets or sets the <see cref="ILogger"/>.
      24             :                 /// </summary>
      25             :                 protected ILogger Logger { get; private set; }
      26             : 
      27             :                 /// <summary>
      28             :                 /// Gets or sets the <see cref="IConfigurationManager"/>.
      29             :                 /// </summary>
      30             :                 protected IConfigurationManager ConfigurationManager { get; private set; }
      31             : 
      32             :                 /// <summary>
      33             :                 /// Instantiates a new instance of <see cref="AzureDocumentDbEventStoreConnectionStringFactory"/>.
      34             :                 /// </summary>
      35           1 :                 public AzureDocumentDbEventStoreConnectionStringFactory(ILogger logger, IConfigurationManager configurationManager)
      36             :                 {
      37             :                         Logger = logger;
      38             :                         ConfigurationManager = configurationManager;
      39             :                 }
      40             : 
      41             :                 /// <summary>
      42             :                 /// Gets the current <see cref="DocumentClient"/>.
      43             :                 /// </summary>
      44           1 :                 public virtual DocumentClient GetEventStoreConnectionClient()
      45             :                 {
      46             :                         Logger.LogDebug("Getting Azure document client", "AzureDocumentDbEventStoreConnectionStringFactory\\GetEventStoreConnectionClient");
      47             :                         try
      48             :                         {
      49             :                                 return new DocumentClient(GetEventStoreConnectionUrl(), GetEventStoreConnectionAuthorisationKey());
      50             :                         }
      51             :                         finally
      52             :                         {
      53             :                                 Logger.LogDebug("Getting Azure document client... Done", "AzureDocumentDbEventStoreConnectionStringFactory\\GetEventStoreConnectionClient");
      54             :                         }
      55             :                 }
      56             : 
      57             :                 /// <summary>
      58             :                 /// Gets the current database name.
      59             :                 /// </summary>
      60           1 :                 public virtual string GetEventStoreConnectionDatabaseName()
      61             :                 {
      62             :                         return ConfigurationManager.GetSetting("Cqrs.EventStore.Azure.DocumentDb.DatabaseName") ?? ConfigurationManager.GetSetting("Cqrs.EventStore.Azure.DocumentDb.LogStreamName") ?? "CqrsEventStore";
      63             :                 }
      64             : 
      65             :                 /// <summary>
      66             :                 /// Gets the current collection name.
      67             :                 /// </summary>
      68           1 :                 public string GetEventStoreConnectionCollectionName()
      69             :                 {
      70             :                         return ConfigurationManager.GetSetting("Cqrs.EventStore.Azure.DocumentDb.CollectionName") ?? "CqrsEventStore";
      71             :                 }
      72             : 
      73             :                 /// <summary>
      74             :                 /// Gets the current connection <see cref="Uri"/> from the <see cref="ConfigurationManager"/>.
      75             :                 /// </summary>
      76           1 :                 protected virtual Uri GetEventStoreConnectionUrl()
      77             :                 {
      78             :                         return new Uri(ConfigurationManager.GetSetting("Cqrs.EventStore.Azure.DocumentDb.Url"));
      79             :                 }
      80             : 
      81             :                 /// <summary>
      82             :                 /// Gets the current connection authorisation key from the <see cref="ConfigurationManager"/>.
      83             :                 /// </summary>
      84           1 :                 protected virtual string GetEventStoreConnectionAuthorisationKey()
      85             :                 {
      86             :                         return ConfigurationManager.GetSetting("Cqrs.EventStore.Azure.DocumentDb.AuthorisationKey");
      87             :                 }
      88             :         }
      89             : }

Generated by: LCOV version 1.10