Documentation Coverage Report
Current view: top level - Cqrs/Configuration - ITelemetryHelperExtensions.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             : 
      14             : namespace Cqrs.Configuration
      15             : {
      16             :         /// <summary>
      17             :         /// A collection of extension methods for <see cref="ITelemetryHelper"/>.
      18             :         /// </summary>
      19             :         public static class ITelemetryHelperExtensions
      20           1 :         {
      21             :                 /// <summary>
      22             :                 /// Send information about a request handled by the application.
      23             :                 /// </summary>
      24             :                 /// <param name="telemetryHelper">The <see cref="ITelemetryHelper"/> being extended.s</param>
      25             :                 /// <param name="name">The request name.</param>
      26             :                 /// <param name="token">The token with user identifiable information.</param>
      27             :                 /// <param name="startTime">The time when the page was requested.</param>
      28             :                 /// <param name="duration">The time taken by the application to handle the request.</param>
      29             :                 /// <param name="responseCode">The response status code.</param>
      30             :                 /// <param name="wasSuccessfull">True if the request was handled successfully by the application.</param>
      31             :                 /// <param name="properties">Named string values you can use to search and classify events.</param>
      32           1 :                 public static void TrackRequest<TAuthenticationToken>(this ITelemetryHelper telemetryHelper, string name, TAuthenticationToken token, DateTimeOffset startTime, TimeSpan duration, string responseCode, bool wasSuccessfull, IDictionary<string, string> properties = null)
      33             :                         where TAuthenticationToken : ISingleSignOnToken
      34             :                 {
      35             :                         TrackRequest(telemetryHelper, name, token == null ? null : token.Serialise(), startTime, duration, responseCode, wasSuccessfull, properties);
      36             :                 }
      37             : 
      38             :                 /// <summary>
      39             :                 /// Send information about a request handled by the application.
      40             :                 /// </summary>
      41             :                 /// <param name="telemetryHelper">The <see cref="ITelemetryHelper"/> being extended.s</param>
      42             :                 /// <param name="name">The request name.</param>
      43             :                 /// <param name="token">The token with user identifiable information.</param>
      44             :                 /// <param name="startTime">The time when the page was requested.</param>
      45             :                 /// <param name="duration">The time taken by the application to handle the request.</param>
      46             :                 /// <param name="responseCode">The response status code.</param>
      47             :                 /// <param name="wasSuccessfull">True if the request was handled successfully by the application.</param>
      48             :                 /// <param name="properties">Named string values you can use to search and classify events.</param>
      49           1 :                 public static void TrackRequest(this ITelemetryHelper telemetryHelper, string name, Guid? token, DateTimeOffset startTime, TimeSpan duration, string responseCode, bool wasSuccessfull, IDictionary<string, string> properties = null)
      50             :                 {
      51             :                         TrackRequest(telemetryHelper, name, token == null ? null : token.Value.ToString("N"), startTime, duration, responseCode, wasSuccessfull, properties);
      52             :                 }
      53             : 
      54             :                 /// <summary>
      55             :                 /// Send information about a request handled by the application.
      56             :                 /// </summary>
      57             :                 /// <param name="telemetryHelper">The <see cref="ITelemetryHelper"/> being extended.s</param>
      58             :                 /// <param name="name">The request name.</param>
      59             :                 /// <param name="token">The token with user identifiable information.</param>
      60             :                 /// <param name="startTime">The time when the page was requested.</param>
      61             :                 /// <param name="duration">The time taken by the application to handle the request.</param>
      62             :                 /// <param name="responseCode">The response status code.</param>
      63             :                 /// <param name="wasSuccessfull">True if the request was handled successfully by the application.</param>
      64             :                 /// <param name="properties">Named string values you can use to search and classify events.</param>
      65           1 :                 public static void TrackRequest(this ITelemetryHelper telemetryHelper, string name, int? token, DateTimeOffset startTime, TimeSpan duration, string responseCode, bool wasSuccessfull, IDictionary<string, string> properties = null)
      66             :                 {
      67             :                         TrackRequest(telemetryHelper, name, token == null ? null : token.Value.ToString(), startTime, duration, responseCode, wasSuccessfull, properties);
      68             :                 }
      69             : 
      70             :                 /// <summary>
      71             :                 /// Send information about a request handled by the application.
      72             :                 /// </summary>
      73             :                 /// <param name="telemetryHelper">The <see cref="ITelemetryHelper"/> being extended.s</param>
      74             :                 /// <param name="name">The request name.</param>
      75             :                 /// <param name="token">The token with user identifiable information.</param>
      76             :                 /// <param name="startTime">The time when the page was requested.</param>
      77             :                 /// <param name="duration">The time taken by the application to handle the request.</param>
      78             :                 /// <param name="responseCode">The response status code.</param>
      79             :                 /// <param name="wasSuccessfull">True if the request was handled successfully by the application.</param>
      80             :                 /// <param name="properties">Named string values you can use to search and classify events.</param>
      81           1 :                 public static void TrackRequest(this ITelemetryHelper telemetryHelper, string name, string token, DateTimeOffset startTime, TimeSpan duration, string responseCode, bool wasSuccessfull, IDictionary<string, string> properties = null)
      82             :                 {
      83             :                         Uri url;
      84             :                         try
      85             :                         {
      86             :                                 url = new Uri(string.Format("cqrs://{0}", name));
      87             :                         }
      88             :                         catch
      89             :                         {
      90             :                                 url = null;
      91             :                         }
      92             : 
      93             :                         string sessionId;
      94             :                         try
      95             :                         {
      96             :                                 sessionId = string.Format("{0}::{1}", properties["CorrelationId"], token);
      97             :                         }
      98             :                         catch
      99             :                         {
     100             :                                 sessionId = null;
     101             :                         }
     102             : 
     103             :                         telemetryHelper.TrackRequest(name, url, token, startTime, duration, responseCode, wasSuccessfull, properties, sessionId);
     104             :                 }
     105             :         }
     106             : }

Generated by: LCOV version 1.12