コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventHubTransmitter"/> class.
        /// </summary>
        /// <param name="buffer">A transmission buffer instance.</param>
        /// <param name="sender">A transmission sender instance.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="buffer"/> must not be <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="sender"/> must not be <c>null</c>.
        /// </exception>
        internal EventHubTransmitter(ITransmissionBuffer <EventData> buffer,
                                     ITransmissionSender <EventData> sender)
        {
            _buffer = buffer ?? throw new ArgumentNullException(nameof(buffer));
            _sender = sender ?? throw new ArgumentNullException(nameof(sender));

            StartAsyncSending();
        }
コード例 #2
0
        /// <summary>
        /// Enqueues a single telemetry data object.
        /// </summary>
        /// <param name="buffer">A transmission buffer instance.</param>
        /// <param name="data">A telemetry data object.</param>
        public static Task EnqueueAsync <TData>(this ITransmissionBuffer <TData> buffer, TData data)
            where TData : class
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            return(buffer.EnqueueAsync(data, CancellationToken.None));
        }
コード例 #3
0
        /// <summary>
        /// Dequeues a telemetry data batch from the buffer.
        /// </summary>
        /// <param name="buffer">A transmission buffer instance.</param>
        /// <returns>A telemetry data batch.</returns>
        public static Task <IEnumerable <TData> > DequeueAsync <TData>(this ITransmissionBuffer <TData> buffer)
            where TData : class
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            return(buffer.DequeueAsync(CancellationToken.None));
        }
コード例 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventHubTransmitter"/> class.
        /// </summary>
        /// <param name="client">A <c>Azure</c> <c>EventHub</c> client instance.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="client"/> must not be <c>null</c>.
        /// </exception>
        public EventHubTransmitter(EventHubClient client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            _buffer = new EventHubTransmissionBuffer(client);
            _sender = new EventHubTransmissionSender(client);

            StartAsyncSending();
        }
コード例 #5
0
        public void Constructor_NoException()
        {
            // assert
            IMemoryBuffer <EventData> buffer = Mock.Of <IMemoryBuffer <EventData> >();
            ITransmissionBuffer <EventData, EventDataBatch> aggregator = Mock.Of <ITransmissionBuffer <EventData, EventDataBatch> >();
            ITransmissionSender <EventDataBatch>            sender     = Mock.Of <ITransmissionSender <EventDataBatch> >();
            ITransmissionStorage <EventData> storage = Mock.Of <ITransmissionStorage <EventData> >();

            // act
            Action verify = () => new EventHubTransmitter(
                buffer, aggregator, sender, storage);

            // arrange
            Assert.Null(Record.Exception(verify));
        }
コード例 #6
0
        public void Constructor_StorageNull()
        {
            // assert
            IMemoryBuffer <EventData> buffer = Mock.Of <IMemoryBuffer <EventData> >();
            ITransmissionBuffer <EventData, EventDataBatch> aggregator = Mock.Of <ITransmissionBuffer <EventData, EventDataBatch> >();
            ITransmissionSender <EventDataBatch>            sender     = Mock.Of <ITransmissionSender <EventDataBatch> >();
            ITransmissionStorage <EventData> storage = null;

            // act
            Action verify = () => new EventHubTransmitter(
                buffer, aggregator, sender, storage);

            // arrange
            Assert.Throws <ArgumentNullException>("storage", verify);
        }
コード例 #7
0
        public void Dispose()
        {
            // arrange
            IMemoryBuffer <EventData> buffer = new Mock <IMemoryBuffer <EventData> >().Object;
            ITransmissionBuffer <EventData, EventDataBatch> aggregator = Mock.Of <ITransmissionBuffer <EventData, EventDataBatch> >();
            ITransmissionSender <EventDataBatch>            sender     = new Mock <ITransmissionSender <EventDataBatch> >().Object;
            ITransmissionStorage <EventData> storage = new Mock <ITransmissionStorage <EventData> >().Object;
            EventHubTransmitter transmitter          = new EventHubTransmitter(
                buffer, aggregator, sender, storage);

            // act
            Action verify = () => transmitter.Dispose();

            // assert
            Assert.Null(Record.Exception(verify));
        }
コード例 #8
0
        public void Enqueue_NoException()
        {
            // assert
            IMemoryBuffer <EventData> buffer = new Mock <IMemoryBuffer <EventData> >().Object;
            ITransmissionBuffer <EventData, EventDataBatch> aggregator = Mock.Of <ITransmissionBuffer <EventData, EventDataBatch> >();
            ITransmissionSender <EventDataBatch>            sender     = new Mock <ITransmissionSender <EventDataBatch> >().Object;
            ITransmissionStorage <EventData> storage = new Mock <ITransmissionStorage <EventData> >().Object;
            TelemetryEvent data = new TelemetryEvent();

            // act
            Action verify = () => new EventHubTransmitter(
                buffer, aggregator, sender, storage);

            // arrange
            Assert.Null(Record.Exception(verify));
        }
コード例 #9
0
        public void Enqueue_DataNull()
        {
            // arrange
            IMemoryBuffer <EventData> buffer = new Mock <IMemoryBuffer <EventData> >().Object;
            ITransmissionBuffer <EventData, EventDataBatch> aggregator = Mock.Of <ITransmissionBuffer <EventData, EventDataBatch> >();
            ITransmissionSender <EventDataBatch>            sender     = new Mock <ITransmissionSender <EventDataBatch> >().Object;
            ITransmissionStorage <EventData> storage     = new Mock <ITransmissionStorage <EventData> >().Object;
            ITelemetryEventTransmitter       transmitter = new EventHubTransmitter(
                buffer, aggregator, sender, storage);
            TelemetryEvent data = null;

            // act
            Action verify = () => transmitter.Enqueue(data);

            // assert
            Assert.Throws <ArgumentNullException>("data", verify);
        }
コード例 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventHubTransmitter"/> class.
        /// </summary>
        public EventHubTransmitter(
            IMemoryBuffer <EventData> buffer,
            ITransmissionBuffer <EventData, EventDataBatch> aggregator,
            ITransmissionSender <EventDataBatch> sender,
            ITransmissionStorage <EventData> storage)
        {
            _buffer     = buffer ?? throw new ArgumentNullException(nameof(buffer));
            _aggregator = aggregator ?? throw new ArgumentNullException(nameof(aggregator));
            _sender     = sender ?? throw new ArgumentNullException(nameof(sender));
            _storage    = storage ?? throw new ArgumentNullException(nameof(storage));

            _storeTask = TaskHelper
                         .StartLongRunning(StoreAsync, _disposeToken.Token);
            _aggregateTask = TaskHelper
                             .StartLongRunning(AggregateAsync, _disposeToken.Token);
            _sendTask = TaskHelper
                        .StartLongRunning(SendAsync, _disposeToken.Token);
        }