protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_consumers != null)
                {
                    _consumers.ForEach(c => c.DisposeSilently("Consumer", _logger));
                    _consumers.Clear();
                }

                if (_producerByTopic != null)
                {
                    _producerByTopic.Clear(producer =>
                    {
                        _logger.LogDebug("Closing EventHubClient for path {0}", producer.EventHubName);
                        try
                        {
                            producer.Close();
                        }
                        catch (Exception e)
                        {
                            _logger.LogError(e, "Error while closing EventHubClient for path {0}", producer.EventHubName);
                        }
                    });
                }
            }
            base.Dispose(disposing);
        }
Example #2
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_consumers.Any())
                {
                    _consumers.ForEach(c => c.DisposeSilently("Consumer", Log));
                    _consumers.Clear();
                }

                _producerByTopic.Clear(producer =>
                {
                    Log.DebugFormat(CultureInfo.InvariantCulture, "Closing EventHubClient for path {0}", producer.EventHubName);
                    try
                    {
                        producer.Close();
                    }
                    catch (Exception e)
                    {
                        Log.ErrorFormat(CultureInfo.InvariantCulture, "Error while closing EventHubClient for path {0}", e, producer.EventHubName);
                    }
                });
            }
            base.Dispose(disposing);
        }
Example #3
0
        protected override void OnDispose()
        {
            _disposing = true;

            if (_producersByTopic.Dictonary.Any())
            {
                foreach (var eventHubClient in _producersByTopic.Dictonary.Values)
                {
                    Log.DebugFormat("Closing EventHubClient for path {0}", eventHubClient.Path);
                    try
                    {
                        eventHubClient.Close();
                    }
                    catch (Exception e)
                    {
                        Log.ErrorFormat("Error while closing EventHubClient for path {0}", e, eventHubClient.Path);
                    }
                }
                _producersByTopic.Clear();
            }

            if (_consumers.Any())
            {
                _consumers.ForEach(c => c.DisposeSilently("Consumer", Log));
                _consumers.Clear();
            }

            base.OnDispose();
        }
Example #4
0
        public void ClearWorks()
        {
            var w = new SafeDictionaryWrapper <string, string>();

            w.GetOrAdd("a", x => "a");
            w.GetOrAdd("b", x => "b");

            // act
            w.Clear();

            // assert
            w.Dictonary.Count.ShouldBeEquivalentTo(0);
        }
Example #5
0
        public virtual void Dispose()
        {
            if (_consumerTask != null)
            {
                Stop();
            }

            _processors.Clear(x => x.DisposeSilently("processor", Log));

            // dispose the consumer
            if (_consumer != null)
            {
                _consumer.DisposeSilently("consumer", Log);
                _consumer = null;
            }
        }
        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_consumerTask != null)
                {
                    Stop();
                }

                _processors.Clear(x => x.DisposeSilently("processor", _logger));

                // dispose the consumer
                if (_consumer != null)
                {
                    _consumer.DisposeSilently("consumer", _logger);
                    _consumer = null;
                }
            }
        }
Example #7
0
        protected override void OnDispose()
        {
            if (_consumers.Any())
            {
                _consumers.ForEach(c => c.DisposeSilently("Consumer", Log));
                _consumers.Clear();
            }

            _producerByTopic.Clear(producer =>
            {
                Log.DebugFormat("Closing EventHubClient for path {0}", producer.Path);
                try
                {
                    producer.Close();
                }
                catch (Exception e)
                {
                    Log.ErrorFormat("Error while closing EventHubClient for path {0}", e, producer.Path);
                }
            });

            base.OnDispose();
        }
Example #8
0
        protected override void Dispose(bool disposing)
        {
            if (_consumers.Count > 0)
            {
                _consumers.ForEach(c => c.DisposeSilently("Consumer", Log));
                _consumers.Clear();
            }

            var disposeTasks = Enumerable.Empty <Task>();

            if (_producerByQueue.Dictonary.Count > 0)
            {
                disposeTasks = disposeTasks.Concat(_producerByQueue.Dictonary.Values.Select(x =>
                {
                    Log.DebugFormat(CultureInfo.InvariantCulture, "Closing {0} for name {1}", nameof(IQueueClient), x.Path);
                    return(x.CloseAsync());
                }));

                _producerByQueue.Clear();
            }

            if (_producerByTopic.Dictonary.Count > 0)
            {
                disposeTasks = disposeTasks.Concat(_producerByTopic.Dictonary.Values.Select(x =>
                {
                    Log.DebugFormat(CultureInfo.InvariantCulture, "Closing {0} for name {1}", nameof(ITopicClient), x.Path);
                    return(x.CloseAsync());
                }));

                _producerByTopic.Clear();
            }

            Task.WaitAll(disposeTasks.ToArray());

            base.Dispose(disposing);
        }