/// <summary>
        /// This method returns a new listener.
        /// </summary>
        /// <returns>
        /// The queue listener.
        /// </returns>
        public override IListener GetListener()
        {
            var listener = new AzureServiceBusTopicListener();

            listener.Connection = Connection;

            return(listener);
        }
        /// <summary>
        /// Gets a listener agent for the bridge.
        /// </summary>
        /// <param name="properties">The service bus extended properties.</param>
        /// <returns>
        /// Returns the listener agent.
        /// </returns>
        public override IListener GetListener(AzureServiceBusExtendedProperties properties)
        {
            var listener = new AzureServiceBusTopicListener();

            listener.Connection = Connection;
            listener.EntityName = properties.EntityName;

            return(listener);
        }
        /// <summary>
        /// Attaches the azure service bus topic listener.
        /// </summary>
        /// <typeparam name="C"></typeparam>
        /// <param name="cpipe">The cpipe.</param>
        /// <param name="connectionName">Name of the connection.</param>
        /// <param name="serviceBusConnection">The service bus connection.</param>
        /// <param name="subscriptionId">The subscription identifier.</param>
        /// <param name="isDeadLetterListener">if set to <c>true</c> [is dead letter listener].</param>
        /// <param name="deleteOnStop">if set to <c>true</c> [delete on stop].</param>
        /// <param name="listenOnOriginatorId">if set to <c>true</c> [listen on originator identifier].</param>
        /// <param name="mappingChannelId">The mapping channel identifier.</param>
        /// <param name="deleteOnIdleTime">The delete on idle time.</param>
        /// <param name="priorityPartitions">The priority partitions.</param>
        /// <param name="resourceProfiles">The resource profiles.</param>
        /// <param name="onCreate">The on create.</param>
        /// <param name="setFromChannelProperties">if set to <c>true</c> [set from channel properties].</param>
        /// <returns>Returns the pipeline.</returns>
        public static C AttachAzureServiceBusTopicListener <C>(this C cpipe
                                                               , string connectionName       = null
                                                               , string serviceBusConnection = null
                                                               , string subscriptionId       = null
                                                               , bool isDeadLetterListener   = false
                                                               , bool deleteOnStop           = true
                                                               , bool listenOnOriginatorId   = false
                                                               , string mappingChannelId     = null
                                                               , TimeSpan?deleteOnIdleTime   = null
                                                               , IEnumerable <ListenerPartitionConfig> priorityPartitions = null
                                                               , IEnumerable <ResourceProfile> resourceProfiles           = null
                                                               , Action <AzureServiceBusTopicListener> onCreate           = null
                                                               , bool setFromChannelProperties = true)
            where C : IPipelineChannelIncoming <IPipeline>
        {
            var     component = new AzureServiceBusTopicListener();
            Channel channel   = cpipe.ToChannel(ChannelDirection.Incoming);

            component.ConfigureAzureMessaging(
                channel.Id
                , priorityPartitions ?? channel.Partitions.Cast <ListenerPartitionConfig>()
                , resourceProfiles
                , connectionName ?? channel.Id
                , serviceBusConnection ?? cpipe.Pipeline.Configuration.ServiceBusConnection()
                );

            component.IsDeadLetterListener = isDeadLetterListener;

            component.DeleteOnIdleTime     = deleteOnIdleTime;
            component.DeleteOnStop         = deleteOnStop;
            component.ListenOnOriginatorId = listenOnOriginatorId;

            //component.SubscriptionId
            //var component = new AzureSBTopicListener(
            //      cpipe.Channel.Id
            //    , cpipe.Pipeline.Configuration.ServiceBusConnectionValidate(serviceBusConnection)
            //    , connectionName
            //    , priorityPartitions ?? cpipe.Channel.Partitions.Cast<ListenerPartitionConfig>().ToList()
            //    , subscriptionId
            //    , isDeadLetterListener
            //    , deleteOnStop
            //    , listenOnOriginatorId
            //    , mappingChannelId
            //    , deleteOnIdleTime
            //    , resourceProfiles ?? cpipe.Channel.ResourceProfiles);

            onCreate?.Invoke(component);

            cpipe.AttachListener(component, setFromChannelProperties: setFromChannelProperties);

            return(cpipe);
        }