Documentation Coverage Report
Current view: top level - Cqrs/Configuration - ConfigurationManager.cs Hit Total Coverage
Version: 4.0 Artefacts: 6 6 100.0 %
Date: 2019-11-24 03:15:41

          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             : 
      11             : namespace Cqrs.Configuration
      12             : {
      13             :         /// <summary>
      14             :         /// Provides access to configuration settings from the app settings of an app.config or web.config... i.e. <see cref="System.Configuration.ConfigurationManager.AppSettings"/>
      15             :         /// </summary>
      16             :         public class ConfigurationManager : IConfigurationManager
      17           1 :         {
      18             :                 #region Implementation of IConfigurationManager
      19             : 
      20             :                 /// <summary>
      21             :                 /// Read the setting named <paramref name="key"/>.
      22             :                 /// </summary>
      23             :                 /// <param name="key">The key (or name) of the setting to read.</param>
      24           1 :                 public virtual string GetSetting(string key)
      25             :                 {
      26             :                         return System.Configuration.ConfigurationManager.AppSettings[key];
      27             :                 }
      28             : 
      29             :                 /// <summary>
      30             :                 /// Read the setting named <paramref name="key"/>.
      31             :                 /// </summary>
      32             :                 /// <param name="key">The key (or name) of the setting to read.</param>
      33             :                 /// <param name="value">When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param>
      34             :                 /// <returns>true if the an element with the specified key exists; otherwise, false.</returns>
      35           1 :                 public virtual bool TryGetSetting(string key, out string value)
      36             :                 {
      37             :                         try
      38             :                         {
      39             :                                 value = GetSetting(key);
      40             :                                 return true;
      41             :                         }
      42             :                         catch (Exception)
      43             :                         {
      44             :                                 value = null;
      45             :                                 return false;
      46             :                         }
      47             :                 }
      48             : 
      49             :                 /// <summary>
      50             :                 /// Read the setting named <paramref name="key"/>.
      51             :                 /// </summary>
      52             :                 /// <param name="key">The key (or name) of the setting to read.</param>
      53             :                 /// <param name="value">When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.</param>
      54             :                 /// <returns>true if the an element with the specified key exists; otherwise, false.</returns>
      55           1 :                 public virtual bool TryGetSetting(string key, out bool value)
      56             :                 {
      57             :                         string rawValue;
      58             :                         if (TryGetSetting(key, out rawValue))
      59             :                         {
      60             :                                 if (bool.TryParse(rawValue, out value))
      61             :                                 {
      62             :                                         return true;
      63             :                                 }
      64             :                         }
      65             :                         value = false;
      66             :                         return false;
      67             :                 }
      68             : 
      69             :                 /// <summary>
      70             :                 /// Read the configuration string named <paramref name="connectionStringName"/>.
      71             :                 /// </summary>
      72             :                 /// <param name="connectionStringName">The name (or key) of the connection string to read.</param>
      73           1 :                 public virtual string GetConnectionString(string connectionStringName)
      74             :                 {
      75             :                         return System.Configuration.ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
      76             :                 }
      77             : 
      78             :                 /// <summary>
      79             :                 /// Read the configuration string where the name (or key) of the connection string is stored in a setting, first obtained with a call to <see cref="GetSetting(string)"/>
      80             :                 /// </summary>
      81             :                 /// <param name="key">The key (or name) of the setting that has the name (or key) of the connection string to read.</param>
      82           1 :                 public virtual string GetConnectionStringBySettingKey(string key)
      83             :                 {
      84             :                         return GetConnectionString(GetSetting(key));
      85             :                 }
      86             : 
      87             :                 #endregion
      88             :         }
      89             : }

Generated by: LCOV version 1.13