/// <summary>
 ///   Initializes a new instance of the <see cref="ServiceBusConnection"/> class.
 /// </summary>
 ///
 /// <param name="fullyQualifiedNamespace">The fully qualified Service Bus namespace to connect to.  This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param>
 /// <param name="credential">The <see cref="ServiceBusSharedAccessKeyCredential"/> credential to use for authorization.  Access controls may be specified by the Service Bus namespace or the requested Service Bus entity, depending on Azure configuration.</param>
 /// <param name="options">A set of options to apply when configuring the connection.</param>
 internal ServiceBusConnection(
     string fullyQualifiedNamespace,
     ServiceBusSharedAccessKeyCredential credential,
     ServiceBusClientOptions options)
     : this(
         fullyQualifiedNamespace,
         TranslateSharedKeyCredential(credential, fullyQualifiedNamespace, null, options.TransportType),
         options)
 {
 }
        /// <summary>
        ///   Translates an <see cref="ServiceBusSharedAccessKeyCredential"/> into the equivalent shared access signature credential.
        /// </summary>
        ///
        /// <param name="credential">The credential to translate.</param>
        /// <param name="fullyQualifiedNamespace">The fully qualified Service Bus namespace being connected to.</param>
        /// <param name="entityPath">The path of the entity 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.</returns>
        ///
        internal static SharedAccessSignatureCredential TranslateSharedKeyCredential(ServiceBusSharedAccessKeyCredential credential,
                                                                                     string fullyQualifiedNamespace,
                                                                                     string entityPath,
                                                                                     ServiceBusTransportType transportType)
        {
            if ((credential == null) || (string.IsNullOrEmpty(fullyQualifiedNamespace)))
            {
                return(null);
            }

            return(credential.AsSharedAccessSignatureCredential(BuildConnectionResource(transportType, fullyQualifiedNamespace, entityPath)));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceBusClient"/> class.
 /// </summary>
 ///
 /// <param name="fullyQualifiedNamespace">The fully qualified Service Bus namespace to connect to.
 /// This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param>
 /// <param name="credential">The <see cref="ServiceBusSharedAccessKeyCredential"/> to use for authorization.  Access controls may be specified by the Service Bus namespace.</param>
 /// <param name="options">The set of <see cref="ServiceBusClientOptions"/> to use for configuring this <see cref="ServiceBusClient"/>.</param>
 internal ServiceBusClient(
     string fullyQualifiedNamespace,
     ServiceBusSharedAccessKeyCredential credential,
     ServiceBusClientOptions options)
 {
     _options = options?.Clone() ?? new ServiceBusClientOptions();
     Logger.ClientCreateStart(typeof(ServiceBusClient), fullyQualifiedNamespace);
     Identifier = DiagnosticUtilities.GenerateIdentifier(fullyQualifiedNamespace);
     Connection = new ServiceBusConnection(
         fullyQualifiedNamespace,
         credential,
         _options);
     Plugins = _options.Plugins;
     Logger.ClientCreateComplete(typeof(ServiceBusClient), Identifier);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ServiceBusClient"/> class.
 /// </summary>
 ///
 /// <param name="fullyQualifiedNamespace">The fully qualified Service Bus namespace to connect to.
 /// This is likely to be similar to <c>{yournamespace}.servicebus.windows.net</c>.</param>
 /// <param name="credential">The <see cref="ServiceBusSharedAccessKeyCredential"/> to use for authorization.  Access controls may be specified by the Service Bus namespace.</param>
 internal ServiceBusClient(string fullyQualifiedNamespace, ServiceBusSharedAccessKeyCredential credential) :
     this(fullyQualifiedNamespace, credential, new ServiceBusClientOptions())
 {
 }