Exemplo n.º 1
0
        internal static string GetUserAgentName(object source, ClientOptions options)
        {
            const string PackagePrefix = "Azure.";

            Assembly assembly = source.GetType().Assembly !;

            AssemblyInformationalVersionAttribute?versionAttribute = assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>();

            if (versionAttribute == null)
            {
                throw new InvalidOperationException($"{nameof(AssemblyInformationalVersionAttribute)} is required on client SDK assembly '{assembly.FullName}' (inferred from the use of options type '{options.GetType().FullName}').");
            }

            string version = versionAttribute.InformationalVersion;

            string assemblyName = assembly.GetName().Name !;

            if (assemblyName.StartsWith(PackagePrefix, StringComparison.Ordinal))
            {
                assemblyName = assemblyName.Substring(PackagePrefix.Length);
            }

            int hashSeparator = version.IndexOfOrdinal('+');

            if (hashSeparator != -1)
            {
                version = version.Substring(0, hashSeparator);
            }

            return(GetUserAgentName(assemblyName, version, options.Diagnostics.ApplicationId));
        }