示例#1
0
        private IExtractionRequestFulfiller CreateRequestFulfiller(CohortExtractorOptions opts)
        {
            var c    = WhenIHaveA <ExtractionInformation>().CatalogueItem.Catalogue;
            var t    = c.GetTableInfoList(false).Single();
            var repo = Repository.CatalogueRepository;

            foreach (string requiredColumn in new string[]
            {
                QueryToExecuteColumnSet.DefaultImagePathColumnName,
                QueryToExecuteColumnSet.DefaultStudyIdColumnName,
                QueryToExecuteColumnSet.DefaultSeriesIdColumnName,
                QueryToExecuteColumnSet.DefaultInstanceIdColumnName,
            })
            {
                var ei = new ExtractionInformation(repo, new CatalogueItem(repo, c, "a"), new ColumnInfo(repo, requiredColumn, "varchar(10)", (TableInfo)t), requiredColumn);
                ei.ExtractionCategory = ExtractionCategory.Core;
                ei.SaveToDatabase();
            }

            c.ClearAllInjections();

            Assert.AreEqual(5, c.GetAllExtractionInformation(ExtractionCategory.Any).Length);

            var f         = new MicroserviceObjectFactory();
            var fulfiller = f.CreateInstance <IExtractionRequestFulfiller>(opts.RequestFulfillerType,
                                                                           typeof(IExtractionRequestFulfiller).Assembly,
                                                                           new object[] { new[] { c } });

            if (fulfiller != null)
            {
                fulfiller.Rejectors.Add(f.CreateInstance <IRejector>(opts.RejectorType, typeof(TestRejector).Assembly) ?? new RejectNone());
            }

            return(fulfiller);
        }
示例#2
0
        public IsIdentifiableHost(
            [NotNull] GlobalOptions globals,
            [NotNull] IsIdentifiableServiceOptions serviceOpts
            )
            : base(globals)
        {
            _consumerOptions = globals.IsIdentifiableOptions;

            string classifierTypename = globals.IsIdentifiableOptions.ClassifierType;
            string dataDirectory      = globals.IsIdentifiableOptions.DataDirectory;

            if (string.IsNullOrWhiteSpace(classifierTypename))
            {
                throw new ArgumentException("No IClassifier has been set in options.  Enter a value for ClassifierType", nameof(globals));
            }
            if (string.IsNullOrWhiteSpace(dataDirectory))
            {
                throw new ArgumentException("A DataDirectory must be set", nameof(globals));
            }

            var objectFactory = new MicroserviceObjectFactory();
            var classifier    = objectFactory.CreateInstance <IClassifier>(classifierTypename, typeof(IClassifier).Assembly, new DirectoryInfo(dataDirectory), serviceOpts);

            if (classifier == null)
            {
                throw new TypeLoadException($"Could not find IClassifier Type { classifierTypename }");
            }

            _producerModel = RabbitMqAdapter.SetupProducer(globals.IsIdentifiableOptions.IsIdentifiableProducerOptions, isBatch: false);

            Consumer = new IsIdentifiableQueueConsumer(_producerModel, globals.FileSystemOptions.FileSystemRoot, globals.FileSystemOptions.ExtractRoot, classifier);
        }
示例#3
0
        /// <summary>
        /// Loads logging, sets up fatal behaviour, subscribes rabbit etc.
        /// </summary>
        /// <param name="globals">Settings for the microservice (location of rabbit, queue names etc)</param>
        /// <param name="rabbitMqAdapter"></param>
        /// <param name="threaded"></param>
        protected MicroserviceHost(
            [NotNull] GlobalOptions globals,
            IRabbitMqAdapter rabbitMqAdapter = null,
            bool threaded = false)
        {
            if (globals == null || globals.FileSystemOptions == null || globals.RabbitOptions == null || globals.LoggingOptions == null)
            {
                throw new ArgumentException("All or part of the global options are null");
            }

            HostProcessName = SmiCliInit.HostProcessName;

            Logger = LogManager.GetLogger(GetType().Name);
            Logger.Info("Host logger created");

            HostProcessID = Process.GetCurrentProcess().Id;
            Logger.Info($"Starting {HostProcessName} (Host={Environment.MachineName} PID={HostProcessID} User={Environment.UserName})");

            // log centrally
            Globals = globals;
            Logger.Debug("Loaded global options:\n" + globals);

            // should also be centralized for non-host uses
            // Ensure this is false in case the default changes
            DicomTypeTranslater.SerializeBinaryData = false;

            _fatalLoggingProducerOptions = new ProducerOptions
            {
                ExchangeName = Globals.RabbitOptions.FatalLoggingExchange
            };

            //TODO This won't pass for testing with mocked filesystems
            //if(!Directory.Exists(options.FileSystemRoot))
            //    throw new ArgumentException("Could not locate the FileSystemRoot \"" + options.FileSystemRoot + "\"");

            OnFatal += (sender, args) => Fatal(args.Message, args.Exception);

            RabbitMqAdapter = rabbitMqAdapter;
            if (RabbitMqAdapter == null)
            {
                ConnectionFactory connectionFactory = globals.RabbitOptions.CreateConnectionFactory();
                RabbitMqAdapter         = new RabbitMqAdapter(connectionFactory, HostProcessName + HostProcessID, OnFatal, threaded);
                _controlMessageConsumer = new ControlMessageConsumer(connectionFactory, HostProcessName, HostProcessID, globals.RabbitOptions.RabbitMqControlExchangeName, this.Stop);
            }

            ObjectFactory = new MicroserviceObjectFactory();
            ObjectFactory.FatalHandler = (s, e) => Fatal(e.Message, e.Exception);
        }
示例#4
0
        public MapperSource([NotNull] GlobalOptions globalOptions, TriggerUpdatesFromMapperOptions cliOptions)
        {
            _cliOptions    = cliOptions;
            _globalOptions = globalOptions;

            FansiImplementations.Load();

            try
            {
                var objectFactory = new MicroserviceObjectFactory();
                _swapper = objectFactory.CreateInstance <ISwapIdentifiers>(globalOptions.IdentifierMapperOptions.SwapperType, typeof(ISwapIdentifiers).Assembly);
            }
            catch (System.Exception ex)
            {
                throw new System.Exception($"Could not create IdentifierMapper Swapper with SwapperType:{globalOptions.IdentifierMapperOptions?.SwapperType ?? "Null"}", ex);
            }

            if (_swapper == null)
            {
                throw new ArgumentException("No SwapperType has been specified in GlobalOptions.IdentifierMapperOptions");
            }
        }
示例#5
0
        private IAuditExtractions CreateAuditor(CohortExtractorOptions opts)
        {
            var f = new MicroserviceObjectFactory();

            return(f.CreateInstance <IAuditExtractions>(opts.AuditorType, typeof(IAuditExtractions).Assembly));
        }
示例#6
0
        public void TestCreatingByReflection()
        {
            var instance = new MicroserviceObjectFactory().CreateInstance <IProjectPathResolver>("Microservices.CohortExtractor.Execution.ProjectPathResolvers.NoSuffixProjectPathResolver", typeof(IProjectPathResolver).Assembly, RepositoryLocator);

            Assert.IsInstanceOf <NoSuffixProjectPathResolver>(instance);
        }