/// <summary>
 ///   Initializes a new instance of the <see cref="EventHubConnection"/> class.
 /// </summary>
 ///
 /// <param name="fullyQualifiedNamespace">The fully qualified Event Hubs namespace to connect to.  This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param>
 /// <param name="eventHubName">The name of the specific Event Hub to associate the connection with.</param>
 /// <param name="credential">The <see cref="EventHubsSharedAccessKeyCredential"/> to use for authorization.  Access controls may be specified by the Event Hubs namespace or the requested Event Hub, depending on Azure configuration.</param>
 /// <param name="connectionOptions">A set of options to apply when configuring the connection.</param>
 ///
 internal EventHubConnection(string fullyQualifiedNamespace,
                             string eventHubName,
                             EventHubsSharedAccessKeyCredential credential,
                             EventHubConnectionOptions connectionOptions = default) : this(fullyQualifiedNamespace,
                                                                                           eventHubName,
                                                                                           TranslateSharedKeyCredential(credential, fullyQualifiedNamespace, eventHubName, connectionOptions?.TransportType),
                                                                                           connectionOptions)
 {
 }
        /// <summary>
        ///   Translates an <see cref="EventHubsSharedAccessKeyCredential"/> into the equivalent shared access signature credential.
        /// </summary>
        ///
        /// <param name="credential">The credential to translate.</param>
        /// <param name="fullyQualifiedNamespace">The fully qualified Event Hubs namespace being connected to.</param>
        /// <param name="eventHubName">The name of the Event Hub being connected to.</param>
        /// <param name="transportType">The type of transport being used for the connection.</param>
        ///
        /// <returns>The <see cref="SharedAccessSignatureCredential" /> which the <paramref name="credential" /> was translated into, if the parameters were populated; otherwise, <c>null</c>.</returns>
        ///
        internal static SharedAccessSignatureCredential TranslateSharedKeyCredential(EventHubsSharedAccessKeyCredential credential,
                                                                                     string fullyQualifiedNamespace,
                                                                                     string eventHubName,
                                                                                     EventHubsTransportType?transportType)
        {
            if ((credential == null) || (string.IsNullOrEmpty(fullyQualifiedNamespace)) || (string.IsNullOrEmpty(eventHubName)))
            {
                return(null);
            }

            return(credential.AsSharedAccessSignatureCredential(BuildConnectionAudience(transportType ?? DefaultCredentialTransportType, fullyQualifiedNamespace, eventHubName)));
        }