< Summary

Class:Azure.Messaging.ServiceBus.Core.ClientLibraryInformation
Assembly:Azure.Messaging.ServiceBus
File(s):C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Core\ClientLibraryInformation.cs
Covered lines:0
Uncovered lines:18
Coverable lines:18
Total lines:103
Line coverage:0% (0 of 18)
Covered branches:0
Total branches:8
Branch coverage:0% (0 of 8)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_Current()-0%100%
get_Product()-0%100%
get_Version()-0%100%
get_Framework()-0%100%
get_Platform()-0%100%
get_UserAgent()-0%100%
.ctor()-0%0%
EnumerateProperties()-0%100%
GetTelemetryName(...)-0%0%

File(s)

C:\Git\azure-sdk-for-net\sdk\servicebus\Azure.Messaging.ServiceBus\src\Core\ClientLibraryInformation.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4using System.Collections.Generic;
 5using System.ComponentModel;
 6using System.Linq;
 7using System.Reflection;
 8using System.Runtime.Versioning;
 9
 10namespace Azure.Messaging.ServiceBus.Core
 11{
 12    /// <summary>
 13    ///   The set of information describing the active version of the
 14    ///   client library.
 15    /// </summary>
 16    ///
 17    internal sealed class ClientLibraryInformation
 18    {
 19        /// <summary>
 20        ///   The current set of information.
 21        /// </summary>
 22        ///
 023        public static ClientLibraryInformation Current { get; } = new ClientLibraryInformation();
 24
 25        /// <summary>
 26        ///   The name of the client library product.
 27        ///  </summary>
 28        ///
 029        public string Product { get; }
 30
 31        /// <summary>
 32        ///   The version of the client library.
 33        /// </summary>
 34        ///
 035        public string Version { get; }
 36
 37        /// <summary>
 38        ///   The version of the framework on which the client library was
 39        ///   built.
 40        /// </summary>
 41        ///
 042        public string Framework { get; }
 43
 44        /// <summary>
 45        ///  The name of the platform on which the client library is currently running.
 46        /// </summary>
 47        ///
 048        public string Platform { get; }
 49
 50        /// <summary>
 51        ///  The client library information, formatted in the standard form used by SDK
 52        ///  user agents when interacting with Azure services.
 53        /// </summary>
 54        ///
 55        [Description("user-agent")]
 056        public string UserAgent => $"azsdk-net-{ Product }/{ Version } ({ Framework }; { Platform })";
 57
 58        /// <summary>
 59        ///   Prevents a default instance of the <see cref="ClientLibraryInformation"/> class from being created.
 60        /// </summary>
 61        ///
 062        private ClientLibraryInformation()
 63        {
 064            Assembly assembly = typeof(ClientLibraryInformation).Assembly;
 65
 066            Product = $"{ nameof(Messaging) }.{ nameof(ServiceBus) }";
 067            Version = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version;
 068            Framework = assembly.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName;
 69
 70#if FullNetFx
 71            Platform = Environment.OSVersion.VersionString;
 72#else
 073            Platform = System.Runtime.InteropServices.RuntimeInformation.OSDescription;
 74#endif
 075        }
 76
 77        /// <summary>
 78        ///   Enumerates the client library properties, normalizing the property names.
 79        /// </summary>
 80        ///
 81        /// <returns>An enumerable set of the properties, with name and value.</returns>
 82        ///
 83        public IEnumerable<KeyValuePair<string, string>> EnumerateProperties() =>
 084            typeof(ClientLibraryInformation)
 085                .GetProperties(BindingFlags.Instance | BindingFlags.Public)
 086                .Select(property => new KeyValuePair<string, string>(GetTelemetryName(property), (string)property.GetVal
 87
 88        /// <summary>
 89        ///   Gets the name of the property, as it should appear in telemetry
 90        ///   information.
 91        /// </summary>
 92        ///
 93        /// <param name="property">The property to consider.</param>
 94        ///
 95        /// <returns>The name of the property for use as telemetry for the client library.</returns>
 96        ///
 97        private static string GetTelemetryName(PropertyInfo property)
 98        {
 099            string name = property.GetCustomAttribute<DescriptionAttribute>(false)?.Description;
 0100            return ((string.IsNullOrEmpty(name)) ? property.Name : name).ToLowerInvariant();
 101        }
 102    }
 103}