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

Generated by: LCOV version 1.12