diff --git a/src/Microsoft.Azure.ServiceBus/Amqp/AmqpConnectionHelper.cs b/src/Microsoft.Azure.ServiceBus/Amqp/AmqpConnectionHelper.cs index 5104d6c6..682e2074 100644 --- a/src/Microsoft.Azure.ServiceBus/Amqp/AmqpConnectionHelper.cs +++ b/src/Microsoft.Azure.ServiceBus/Amqp/AmqpConnectionHelper.cs @@ -7,6 +7,7 @@ namespace Microsoft.Azure.ServiceBus.Amqp using Microsoft.Azure.Amqp; using Microsoft.Azure.Amqp.Sasl; using Microsoft.Azure.Amqp.Transport; + using Microsoft.Azure.ServiceBus.Primitives; internal class AmqpConnectionHelper { @@ -100,12 +101,17 @@ public static TransportSettings CreateTcpTransportSettings( public static AmqpConnectionSettings CreateAmqpConnectionSettings(uint maxFrameSize, string containerId, string hostName) { - AmqpConnectionSettings connectionSettings = new AmqpConnectionSettings + var connectionSettings = new AmqpConnectionSettings { MaxFrameSize = maxFrameSize, ContainerId = containerId, HostName = hostName }; + + connectionSettings.AddProperty("product", ClientInfo.Product); + connectionSettings.AddProperty("version", ClientInfo.Version); + connectionSettings.AddProperty("framework", ClientInfo.Framework); + connectionSettings.AddProperty("platform", ClientInfo.Platform); return connectionSettings; } } diff --git a/src/Microsoft.Azure.ServiceBus/Primitives/ClientInfo.cs b/src/Microsoft.Azure.ServiceBus/Primitives/ClientInfo.cs new file mode 100644 index 00000000..b7743140 --- /dev/null +++ b/src/Microsoft.Azure.ServiceBus/Primitives/ClientInfo.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.Azure.ServiceBus.Primitives +{ + using System; + using System.Reflection; + using System.Runtime.Versioning; + + internal static class ClientInfo + { + internal static readonly string Product; + internal static readonly string Version; + internal static readonly string Framework; + internal static readonly string Platform; + + static ClientInfo() + { + try + { + Assembly assembly = typeof(ClientInfo).GetTypeInfo().Assembly; + Product = GetAssemblyAttributeValue(assembly, p => p.Product); + Version = GetAssemblyAttributeValue(assembly, v => v.Version); + Framework = GetAssemblyAttributeValue(assembly, f => f.FrameworkName); +#if NETSTANDARD1_3 + Platform = System.Runtime.InteropServices.RuntimeInformation.OSDescription; +#elif UAP10_0 + Platform = "UAP"; +#elif NET451 + Platform = Environment.OSVersion.VersionString; +#else + Platform = "Unknown"; +#endif + } + catch + { + // ignored + } + } + + static string GetAssemblyAttributeValue(Assembly assembly, Func getter) where T : Attribute + { + var attribute = assembly.GetCustomAttribute(typeof(T)) as T; + return attribute == null ? null : getter(attribute); + } + } +}