Esempio n. 1
0
        private void CheckAckNackCounts(DicomTagReaderConsumer consumer, int desiredAckCount, int desiredNackCount)
        {
            var mockdeliverArgs = Mock.Of <BasicDeliverEventArgs>();

            mockdeliverArgs.DeliveryTag     = 1;
            mockdeliverArgs.Body            = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(_helper.TestAccessionDirectoryMessage));
            mockdeliverArgs.BasicProperties = new BasicProperties {
                Headers = new Dictionary <string, object>()
            };

            var header = new MessageHeader();

            header.Populate(mockdeliverArgs.BasicProperties.Headers);

            // Have to convert these to bytes since RabbitMQ normally does that when sending
            mockdeliverArgs.BasicProperties.Headers["MessageGuid"]            = Encoding.UTF8.GetBytes(header.MessageGuid.ToString());
            mockdeliverArgs.BasicProperties.Headers["ProducerExecutableName"] = Encoding.UTF8.GetBytes(header.ProducerExecutableName);
            mockdeliverArgs.BasicProperties.Headers["Parents"] = Encoding.UTF8.GetBytes(string.Join("->", header.Parents));

            var fatalCalled = false;

            consumer.OnFatal += (sender, args) => fatalCalled = true;

            consumer.SetModel(_mockModel);
            consumer.ProcessMessage(mockdeliverArgs);

            Assert.AreEqual(desiredAckCount, consumer.AckCount);
            Assert.AreEqual(desiredNackCount, consumer.NackCount);
            Assert.False(fatalCalled);
        }
Esempio n. 2
0
        public DicomTagReaderHost(GlobalOptions options)
            : base(options)
        {
            if (!Directory.Exists(options.FileSystemOptions.FileSystemRoot))
            {
                throw new ArgumentException("Cannot find the FileSystemRoot specified in the given MicroservicesOptions (" + options.FileSystemOptions.FileSystemRoot + ")");
            }

            Logger.Debug("Creating DicomTagReaderHost with FileSystemRoot: " + options.FileSystemOptions.FileSystemRoot);
            Logger.Debug("NackIfAnyFileErrors option set to " + options.DicomTagReaderOptions.NackIfAnyFileErrors);

            IProducerModel seriesProducerModel;
            IProducerModel imageProducerModel;

            try
            {
                Logger.Debug("Creating seriesProducerModel with ExchangeName: " + options.DicomTagReaderOptions.SeriesProducerOptions.ExchangeName);
                seriesProducerModel = RabbitMqAdapter.SetupProducer(options.DicomTagReaderOptions.SeriesProducerOptions, true);

                Logger.Debug("Creating imageProducerModel with ExchangeName: " + options.DicomTagReaderOptions.ImageProducerOptions.ExchangeName);
                imageProducerModel = RabbitMqAdapter.SetupProducer(options.DicomTagReaderOptions.ImageProducerOptions, true);
            }
            catch (Exception e)
            {
                throw new ApplicationException("Couldn't create series producer model on startup", e);
            }

            Logger.Debug("Creating AccessionDirectoryMessageConsumer");

            switch (options.DicomTagReaderOptions.TagProcessorMode)
            {
            case TagProcessorMode.Serial:
                _tagReader = new SerialTagReader(options.DicomTagReaderOptions, options.FileSystemOptions, seriesProducerModel, imageProducerModel, new FileSystem());
                break;

            case TagProcessorMode.Parallel:
                _tagReader = new ParallelTagReader(options.DicomTagReaderOptions, options.FileSystemOptions, seriesProducerModel, imageProducerModel, new FileSystem());
                break;

            default:
                throw new ArgumentException($"No case for mode {options.DicomTagReaderOptions.TagProcessorMode}");
            }

            // Setup our consumer
            AccessionDirectoryMessageConsumer = new DicomTagReaderConsumer(_tagReader, options);
        }