Line data Source code
1 : using System;
2 : using System.Collections.Generic;
3 : using cdmdotnet.Logging;
4 : using Cqrs.Authentication;
5 :
6 : namespace Cqrs.Configuration
7 : {
8 : public static class ITelemetryHelperExtensions
9 0 : {
10 : /// <summary>
11 : /// Send information about a request handled by the application.
12 : /// </summary>
13 : /// <param name="telemetryHelper">The <see cref="ITelemetryHelper"/> being extended.s</param>
14 : /// <param name="name">The request name.</param>
15 : /// <param name="token">The token with user identifiable information.</param>
16 : /// <param name="startTime">The time when the page was requested.</param>
17 : /// <param name="duration">The time taken by the application to handle the request.</param>
18 : /// <param name="responseCode">The response status code.</param>
19 : /// <param name="wasSuccessfull">True if the request was handled successfully by the application.</param>
20 : /// <param name="properties">Named string values you can use to search and classify events.</param>
21 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)
22 : where TAuthenticationToken : ISingleSignOnToken
23 : {
24 : TrackRequest(telemetryHelper, name, token == null ? null : token.Serialise(), startTime, duration, responseCode, wasSuccessfull, properties);
25 : }
26 :
27 : /// <summary>
28 : /// Send information about a request handled by the application.
29 : /// </summary>
30 : /// <param name="telemetryHelper">The <see cref="ITelemetryHelper"/> being extended.s</param>
31 : /// <param name="name">The request name.</param>
32 : /// <param name="token">The token with user identifiable information.</param>
33 : /// <param name="startTime">The time when the page was requested.</param>
34 : /// <param name="duration">The time taken by the application to handle the request.</param>
35 : /// <param name="responseCode">The response status code.</param>
36 : /// <param name="wasSuccessfull">True if the request was handled successfully by the application.</param>
37 : /// <param name="properties">Named string values you can use to search and classify events.</param>
38 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)
39 : {
40 : TrackRequest(telemetryHelper, name, token == null ? null : token.Value.ToString("N"), startTime, duration, responseCode, wasSuccessfull, properties);
41 : }
42 :
43 : /// <summary>
44 : /// Send information about a request handled by the application.
45 : /// </summary>
46 : /// <param name="telemetryHelper">The <see cref="ITelemetryHelper"/> being extended.s</param>
47 : /// <param name="name">The request name.</param>
48 : /// <param name="token">The token with user identifiable information.</param>
49 : /// <param name="startTime">The time when the page was requested.</param>
50 : /// <param name="duration">The time taken by the application to handle the request.</param>
51 : /// <param name="responseCode">The response status code.</param>
52 : /// <param name="wasSuccessfull">True if the request was handled successfully by the application.</param>
53 : /// <param name="properties">Named string values you can use to search and classify events.</param>
54 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)
55 : {
56 : TrackRequest(telemetryHelper, name, token == null ? null : token.Value.ToString(), startTime, duration, responseCode, wasSuccessfull, properties);
57 : }
58 :
59 : /// <summary>
60 : /// Send information about a request handled by the application.
61 : /// </summary>
62 : /// <param name="telemetryHelper">The <see cref="ITelemetryHelper"/> being extended.s</param>
63 : /// <param name="name">The request name.</param>
64 : /// <param name="token">The token with user identifiable information.</param>
65 : /// <param name="startTime">The time when the page was requested.</param>
66 : /// <param name="duration">The time taken by the application to handle the request.</param>
67 : /// <param name="responseCode">The response status code.</param>
68 : /// <param name="wasSuccessfull">True if the request was handled successfully by the application.</param>
69 : /// <param name="properties">Named string values you can use to search and classify events.</param>
70 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)
71 : {
72 : Uri url;
73 : try
74 : {
75 : url = new Uri(string.Format("cqrs://{0}", name));
76 : }
77 : catch
78 : {
79 : url = null;
80 : }
81 :
82 : telemetryHelper.TrackRequest(name, url, token, startTime, duration, responseCode, wasSuccessfull, properties);
83 : }
84 : }
85 : }
|