public DefaultSqlConnectionTests()
        {
            var sqlServerDataStoreConfiguration = new SqlServerDataStoreConfiguration();

            sqlServerDataStoreConfiguration.ConnectionString = $"server={ServerName};Initial Catalog={DatabaseName};Integrated Security=true";
            _sqlConnectionFactory = new DefaultSqlConnectionFactory(new DefaultSqlConnectionStringProvider(sqlServerDataStoreConfiguration));
        }
        public SqlServerTransientFaultRetryPolicyFactory(
            SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration,
            IPollyRetryLoggerFactory pollyRetryLoggerFactory)
        {
            EnsureArg.IsNotNull(sqlServerDataStoreConfiguration, nameof(sqlServerDataStoreConfiguration));
            EnsureArg.IsNotNull(pollyRetryLoggerFactory, nameof(pollyRetryLoggerFactory));

            SqlServerTransientFaultRetryPolicyConfiguration transientFaultRetryPolicyConfiguration = sqlServerDataStoreConfiguration.TransientFaultRetryPolicy;

            IEnumerable <TimeSpan> sleepDurations = Backoff.ExponentialBackoff(
                transientFaultRetryPolicyConfiguration.InitialDelay,
                transientFaultRetryPolicyConfiguration.RetryCount,
                transientFaultRetryPolicyConfiguration.Factor,
                transientFaultRetryPolicyConfiguration.FastFirst);

            PolicyBuilder policyBuilder = Policy
                                          .Handle <SqlException>(sqlException => sqlException.IsTransient())
                                          .Or <TimeoutException>();

            Action <Exception, TimeSpan, int, Context> onRetryLogger = pollyRetryLoggerFactory.Create();

            _retryPolicy = policyBuilder.WaitAndRetryAsync(
                sleepDurations,
                onRetry: onRetryLogger);
        }
        public SqlServerFhirDataStore(
            SqlServerDataStoreConfiguration configuration,
            SqlServerFhirModel model,
            SearchParameterToSearchValueTypeMap searchParameterTypeMap,
            VLatest.UpsertResourceTvpGenerator <ResourceMetadata> upsertResourceTvpGeneratorVLatest,
            IOptions <CoreFeatureConfiguration> coreFeatures,
            SqlConnectionWrapperFactory sqlConnectionWrapperFactory,
            ILogger <SqlServerFhirDataStore> logger,
            SchemaInformation schemaInformation)
        {
            EnsureArg.IsNotNull(configuration, nameof(configuration));
            EnsureArg.IsNotNull(model, nameof(model));
            EnsureArg.IsNotNull(searchParameterTypeMap, nameof(searchParameterTypeMap));
            EnsureArg.IsNotNull(upsertResourceTvpGeneratorVLatest, nameof(upsertResourceTvpGeneratorVLatest));
            EnsureArg.IsNotNull(coreFeatures, nameof(coreFeatures));
            EnsureArg.IsNotNull(sqlConnectionWrapperFactory, nameof(sqlConnectionWrapperFactory));
            EnsureArg.IsNotNull(logger, nameof(logger));
            EnsureArg.IsNotNull(schemaInformation, nameof(schemaInformation));

            _configuration                     = configuration;
            _model                             = model;
            _searchParameterTypeMap            = searchParameterTypeMap;
            _upsertResourceTvpGeneratorVLatest = upsertResourceTvpGeneratorVLatest;
            _coreFeatures                      = coreFeatures.Value;
            _sqlConnectionWrapperFactory       = sqlConnectionWrapperFactory;
            _logger                            = logger;
            _schemaInformation                 = schemaInformation;

            _memoryStreamManager = new RecyclableMemoryStreamManager();
        }
        public SqlServerFhirModel(
            SqlServerDataStoreConfiguration configuration,
            SchemaInformation schemaInformation,
            ISearchParameterDefinitionManager searchParameterDefinitionManager,
            IOptions <SecurityConfiguration> securityConfiguration,
            ILogger <SqlServerFhirModel> logger)
        {
            EnsureArg.IsNotNull(configuration, nameof(configuration));
            EnsureArg.IsNotNull(schemaInformation, nameof(schemaInformation));
            EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager));
            EnsureArg.IsNotNull(securityConfiguration?.Value, nameof(securityConfiguration));
            EnsureArg.IsNotNull(logger, nameof(logger));

            _configuration     = configuration;
            _schemaInformation = schemaInformation;
            _logger            = logger;
            _searchParameterDefinitionManager = searchParameterDefinitionManager;
            _securityConfiguration            = securityConfiguration.Value;

            _initializationOperation = new RetryableInitializationOperation(Initialize);
            if (schemaInformation.Current != null)
            {
                // kick off initialization so that it can be ready for requests. Errors will be observed by requests when they call the method.
                EnsureInitialized();
            }
        }
Exemple #5
0
        public ApplyCommand(
            SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration,
            BaseSchemaRunner baseSchemaRunner,
            ISchemaManagerDataStore schemaManagerDataStore,
            ISchemaClient schemaClient)
            : base(CommandNames.Apply, Resources.ApplyCommandDescription)
        {
            AddOption(CommandOptions.ConnectionStringOption());
            AddOption(CommandOptions.ServerOption());
            AddOption(CommandOptions.VersionOption());
            AddOption(CommandOptions.NextOption());
            AddOption(CommandOptions.LatestOption());
            AddOption(CommandOptions.ForceOption());

            Handler = CommandHandler.Create(
                (string connectionString, Uri server, MutuallyExclusiveType type, bool force, CancellationToken token)
                => HandlerAsync(connectionString, server, type, force, token));

            Argument.AddValidator(symbol => Validators.RequiredOptionValidator.Validate(symbol, CommandOptions.ConnectionStringOption(), Resources.ConnectionStringRequiredValidation));
            Argument.AddValidator(symbol => Validators.RequiredOptionValidator.Validate(symbol, CommandOptions.ServerOption(), Resources.ServerRequiredValidation));
            Argument.AddValidator(symbol => Validators.MutuallyExclusiveOptionValidator.Validate(symbol, new List <Option> {
                CommandOptions.VersionOption(), CommandOptions.NextOption(), CommandOptions.LatestOption()
            }, Resources.MutuallyExclusiveValidation));

            EnsureArg.IsNotNull(sqlServerDataStoreConfiguration);
            EnsureArg.IsNotNull(baseSchemaRunner);
            EnsureArg.IsNotNull(schemaManagerDataStore);
            EnsureArg.IsNotNull(schemaClient);

            _sqlServerDataStoreConfiguration = sqlServerDataStoreConfiguration;
            _baseSchemaRunner       = baseSchemaRunner;
            _schemaManagerDataStore = schemaManagerDataStore;
            _schemaClient           = schemaClient;
        }
Exemple #6
0
        public SqlSchemaManagerTests()
        {
            _configuration = new SqlServerDataStoreConfiguration
            {
                ConnectionString = string.Empty,
            };

            _baseSchemaRunner.EnsureBaseSchemaExistsAsync(default).ReturnsForAnyArgs(Task.FromResult(true));
        public SqlConnectionWrapperFactory(SqlServerDataStoreConfiguration configuration, SqlTransactionHandler sqlTransactionHandler)
        {
            EnsureArg.IsNotNull(configuration, nameof(configuration));
            EnsureArg.IsNotNull(sqlTransactionHandler, nameof(sqlTransactionHandler));

            _configuration         = configuration;
            _sqlTransactionHandler = sqlTransactionHandler;
        }
Exemple #8
0
        public SchemaUpgradeRunner(SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration, ILogger <SchemaUpgradeRunner> logger)
        {
            EnsureArg.IsNotNull(sqlServerDataStoreConfiguration, nameof(sqlServerDataStoreConfiguration));
            EnsureArg.IsNotNull(logger, nameof(logger));

            _sqlServerDataStoreConfiguration = sqlServerDataStoreConfiguration;
            _logger = logger;
        }
        public ManagedIdentitySqlConnectionFactory(SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration, IAccessTokenHandler accessTokenHandler)
        {
            EnsureArg.IsNotNull(sqlServerDataStoreConfiguration, nameof(sqlServerDataStoreConfiguration));
            EnsureArg.IsNotNull(accessTokenHandler, nameof(accessTokenHandler));

            _sqlServerDataStoreConfiguration = sqlServerDataStoreConfiguration;
            _accessTokenHandler = accessTokenHandler;
        }
        public SqlServerHealthCheck(SqlServerDataStoreConfiguration configuration, ILogger <SqlServerHealthCheck> logger)
        {
            EnsureArg.IsNotNull(configuration, nameof(configuration));
            EnsureArg.IsNotNull(logger, nameof(logger));

            _configuration = configuration;
            _logger        = logger;
        }
        public SqlServerFhirStorageTestsFixture()
        {
            var initialConnectionString = Environment.GetEnvironmentVariable("SqlServer:ConnectionString") ?? LocalConnectionString;

            _databaseName           = $"FHIRINTEGRATIONTEST_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}_{BigInteger.Abs(new BigInteger(Guid.NewGuid().ToByteArray()))}";
            _masterConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = "master"
            }.ToString();
            TestConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = _databaseName
            }.ToString();

            var config = new SqlServerDataStoreConfiguration {
                ConnectionString = TestConnectionString, Initialize = true
            };

            var schemaUpgradeRunner = new SchemaUpgradeRunner(config, NullLogger <SchemaUpgradeRunner> .Instance);

            var schemaInformation = new SchemaInformation();

            _schemaInitializer = new SchemaInitializer(config, schemaUpgradeRunner, schemaInformation, NullLogger <SchemaInitializer> .Instance);

            var searchParameterDefinitionManager = Substitute.For <ISearchParameterDefinitionManager>();

            searchParameterDefinitionManager.AllSearchParameters.Returns(new[]
            {
                new SearchParameter {
                    Name = SearchParameterNames.Id, Type = SearchParamType.Token, Url = SearchParameterNames.IdUri.ToString()
                }.ToInfo(),
                new SearchParameter {
                    Name = SearchParameterNames.LastUpdated, Type = SearchParamType.Date, Url = SearchParameterNames.LastUpdatedUri.ToString()
                }.ToInfo(),
            });

            var securityConfiguration = new SecurityConfiguration {
                PrincipalClaims = { "oid" }
            };

            var sqlServerFhirModel = new SqlServerFhirModel(config, schemaInformation, searchParameterDefinitionManager, Options.Create(securityConfiguration), NullLogger <SqlServerFhirModel> .Instance);

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSqlServerTableRowParameterGenerators();
            serviceCollection.AddSingleton(sqlServerFhirModel);

            ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

            var upsertResourceTvpGenerator          = serviceProvider.GetRequiredService <V1.UpsertResourceTvpGenerator <ResourceMetadata> >();
            var searchParameterToSearchValueTypeMap = new SearchParameterToSearchValueTypeMap(searchParameterDefinitionManager);

            SqlTransactionHandler       = new SqlTransactionHandler();
            SqlConnectionWrapperFactory = new SqlConnectionWrapperFactory(config, SqlTransactionHandler);

            _fhirDataStore = new SqlServerFhirDataStore(config, sqlServerFhirModel, searchParameterToSearchValueTypeMap, upsertResourceTvpGenerator, Options.Create(new CoreFeatureConfiguration()), SqlConnectionWrapperFactory, NullLogger <SqlServerFhirDataStore> .Instance);
            _testHelper    = new SqlServerFhirStorageTestHelper(TestConnectionString);
        }
Exemple #12
0
        public static IDicomServerBuilder AddSqlServer(
            this IDicomServerBuilder dicomServerBuilder,
            IConfiguration configurationRoot,
            Action <SqlServerDataStoreConfiguration> configureAction = null)
        {
            EnsureArg.IsNotNull(dicomServerBuilder, nameof(dicomServerBuilder));
            IServiceCollection services = dicomServerBuilder.Services;

            services.AddSqlServerBase <SchemaVersion>(configurationRoot);
            services.AddSqlServerApi();

            var config = new SqlServerDataStoreConfiguration();

            configurationRoot?.GetSection("SqlServer").Bind(config);

            services.Add(provider =>
            {
                configureAction?.Invoke(config);
                return(config);
            })
            .Singleton()
            .AsSelf();

            services.Add(provider => new SchemaInformation((int)SchemaVersion.V1, (int)SchemaVersion.V1))
            .Singleton()
            .AsSelf();

            services.Add <SqlIndexSchema>()
            .Singleton()
            .AsSelf();

            services.Add <SqlIndexDataStore>()
            .Scoped()
            .AsSelf()
            .AsImplementedInterfaces();

            // TODO: Ideally, the logger can be registered in the API layer since it's agnostic to the implementation.
            // However, the current implementation of the decorate method requires the concrete type to be already registered,
            // so we need to register here. Need to some more investigation to see how we might be able to do this.
            services.Decorate <IIndexDataStore, LoggingIndexDataStore>();

            services.Add <SqlQueryStore>()
            .Scoped()
            .AsSelf()
            .AsImplementedInterfaces();

            services.Add <SqlInstanceStore>()
            .Scoped()
            .AsSelf()
            .AsImplementedInterfaces();

            services.Add <SqlChangeFeedStore>()
            .Scoped()
            .AsSelf()
            .AsImplementedInterfaces();

            return(dicomServerBuilder);
        }
Exemple #13
0
        // Only 1 public constructor is allowed for test fixture.
        internal SqlDataStoreTestsFixture(string databaseName)
        {
            EnsureArg.IsNotNullOrEmpty(databaseName, nameof(databaseName));
            _databaseName = databaseName;
            string initialConnectionString = Environment.GetEnvironmentVariable("SqlServer:ConnectionString") ?? LocalConnectionString;

            _masterConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = "master"
            }.ToString();
            TestConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = _databaseName
            }.ToString();

            var config = new SqlServerDataStoreConfiguration
            {
                ConnectionString = TestConnectionString,
                Initialize       = true,
                SchemaOptions    = new SqlServerSchemaOptions
                {
                    AutomaticUpdatesEnabled = true,
                },
            };

            var scriptProvider = new ScriptProvider <SchemaVersion>();

            var baseScriptProvider = new BaseScriptProvider();

            var mediator = Substitute.For <IMediator>();

            var sqlConnectionStringProvider = new DefaultSqlConnectionStringProvider(config);

            var sqlConnectionFactory = new DefaultSqlConnectionFactory(sqlConnectionStringProvider);

            var schemaManagerDataStore = new SchemaManagerDataStore(sqlConnectionFactory);

            var schemaUpgradeRunner = new SchemaUpgradeRunner(scriptProvider, baseScriptProvider, mediator, NullLogger <SchemaUpgradeRunner> .Instance, sqlConnectionFactory, schemaManagerDataStore);

            var schemaInformation = new SchemaInformation(SchemaVersionConstants.Min, SchemaVersionConstants.Max);

            _schemaInitializer = new SchemaInitializer(config, schemaUpgradeRunner, schemaInformation, sqlConnectionFactory, sqlConnectionStringProvider, NullLogger <SchemaInitializer> .Instance);

            SqlTransactionHandler = new SqlTransactionHandler();

            SqlConnectionWrapperFactory = new SqlConnectionWrapperFactory(SqlTransactionHandler, new SqlCommandWrapperFactory(), sqlConnectionFactory);

            SqlIndexDataStoreFactory = new SqlIndexDataStoreFactory(
                schemaInformation,
                new[] { new SqlIndexDataStoreV1(SqlConnectionWrapperFactory), new SqlIndexDataStoreV2(SqlConnectionWrapperFactory) });

            InstanceStore = new SqlInstanceStore(SqlConnectionWrapperFactory);

            ExtendedQueryTagStore = new SqlExtendedQueryTagStore(SqlConnectionWrapperFactory, schemaInformation, NullLogger <SqlExtendedQueryTagStore> .Instance);

            TestHelper = new SqlIndexDataStoreTestHelper(TestConnectionString);
        }
        public SqlDataStoreTestsFixture()
        {
            string initialConnectionString = Environment.GetEnvironmentVariable("SqlServer:ConnectionString") ?? LocalConnectionString;

            _databaseName           = $"DICOMINTEGRATIONTEST_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}_{BigInteger.Abs(new BigInteger(Guid.NewGuid().ToByteArray()))}";
            _masterConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = "master"
            }.ToString();
            TestConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = _databaseName
            }.ToString();

            var config = new SqlServerDataStoreConfiguration
            {
                ConnectionString = TestConnectionString,
                Initialize       = true,
                SchemaOptions    = new SqlServerSchemaOptions
                {
                    AutomaticUpdatesEnabled = true,
                },
            };

            var scriptProvider = new ScriptProvider <SchemaVersion>();

            var baseScriptProvider = new BaseScriptProvider();

            var mediator = Substitute.For <IMediator>();

            var sqlConnectionStringProvider = new DefaultSqlConnectionStringProvider(config);

            var sqlConnectionFactory = new DefaultSqlConnectionFactory(sqlConnectionStringProvider);

            var schemaManagerDataStore = new SchemaManagerDataStore(sqlConnectionFactory);

            var schemaUpgradeRunner = new SchemaUpgradeRunner(scriptProvider, baseScriptProvider, mediator, NullLogger <SchemaUpgradeRunner> .Instance, sqlConnectionFactory, schemaManagerDataStore);

            var schemaInformation = new SchemaInformation((int)SchemaVersion.V1, (int)SchemaVersion.V1);

            _schemaInitializer = new SchemaInitializer(config, schemaUpgradeRunner, schemaInformation, sqlConnectionFactory, sqlConnectionStringProvider, NullLogger <SchemaInitializer> .Instance);

            var dicomSqlIndexSchema = new SqlIndexSchema(schemaInformation, NullLogger <SqlIndexSchema> .Instance);

            SqlTransactionHandler = new SqlTransactionHandler();

            SqlConnectionWrapperFactory = new SqlConnectionWrapperFactory(SqlTransactionHandler, new SqlCommandWrapperFactory(), sqlConnectionFactory);

            IndexDataStore = new SqlIndexDataStore(
                dicomSqlIndexSchema,
                SqlConnectionWrapperFactory);

            InstanceStore = new SqlInstanceStore(SqlConnectionWrapperFactory);

            TestHelper = new SqlIndexDataStoreTestHelper(TestConnectionString);
        }
Exemple #15
0
 public SchemaInitializer(SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration, SchemaUpgradeRunner schemaUpgradeRunner, SchemaInformation schemaInformation, ISqlConnectionFactory sqlConnectionFactory, ISqlConnectionStringProvider sqlConnectionStringProvider, IMediator mediator, ILogger <SchemaInitializer> logger)
 {
     _sqlServerDataStoreConfiguration = EnsureArg.IsNotNull(sqlServerDataStoreConfiguration, nameof(sqlServerDataStoreConfiguration));
     _schemaUpgradeRunner             = EnsureArg.IsNotNull(schemaUpgradeRunner, nameof(schemaUpgradeRunner));
     _schemaInformation           = EnsureArg.IsNotNull(schemaInformation, nameof(schemaInformation));
     _sqlConnectionFactory        = EnsureArg.IsNotNull(sqlConnectionFactory, nameof(sqlConnectionFactory));
     _sqlConnectionStringProvider = EnsureArg.IsNotNull(sqlConnectionStringProvider, nameof(sqlConnectionStringProvider));
     _mediator = EnsureArg.IsNotNull(mediator, nameof(mediator));
     _logger   = EnsureArg.IsNotNull(logger, nameof(logger));
 }
        private SchemaInitializer CreateSchemaInitializer(string testConnectionString)
        {
            var config = new SqlServerDataStoreConfiguration {
                ConnectionString = testConnectionString, Initialize = true
            };
            var schemaUpgradeRunner = new SchemaUpgradeRunner(config, NullLogger <SchemaUpgradeRunner> .Instance);
            var schemaInformation   = new SchemaInformation();

            return(new SchemaInitializer(config, schemaUpgradeRunner, schemaInformation, NullLogger <SchemaInitializer> .Instance));
        }
Exemple #17
0
        public async Task GivenValidSqlServerDataStoreConfiguration_GetSqlConnectionString_ReturnsConnectionString(string sqlConnectionString)
        {
            var sqlServerDataStoreConfiguration = new SqlServerDataStoreConfiguration()
            {
                ConnectionString = sqlConnectionString
            };
            ISqlConnectionStringProvider sqlConnectionStringProvider = new DefaultSqlConnectionStringProvider(sqlServerDataStoreConfiguration);

            Assert.Equal(sqlConnectionString, await sqlConnectionStringProvider.GetSqlConnectionString(CancellationToken.None));
        }
Exemple #18
0
        public SqlServerHealthCheck(SqlServerDataStoreConfiguration configuration, ISqlConnectionFactory sqlConnectionFactory, ILogger <SqlServerHealthCheck> logger)
        {
            EnsureArg.IsNotNull(configuration, nameof(configuration));
            EnsureArg.IsNotNull(sqlConnectionFactory, nameof(sqlConnectionFactory));
            EnsureArg.IsNotNull(logger, nameof(logger));

            _configuration        = configuration;
            _sqlConnectionFactory = sqlConnectionFactory;
            _logger = logger;
        }
        public SchemaJobWorkerBackgroundService(SchemaJobWorker schemaJobWorker, SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration, SchemaInformation schemaInformation)
        {
            EnsureArg.IsNotNull(schemaJobWorker, nameof(schemaJobWorker));
            EnsureArg.IsNotNull(sqlServerDataStoreConfiguration, nameof(sqlServerDataStoreConfiguration));
            EnsureArg.IsNotNull(schemaInformation, nameof(schemaInformation));

            _schemaJobWorker = schemaJobWorker;
            _sqlServerDataStoreConfiguration = sqlServerDataStoreConfiguration;
            _schemaInformation = schemaInformation;
            _instanceName      = Guid.NewGuid() + "-" + Process.GetCurrentProcess().Id.ToString();
        }
        public ManagedIdentitySqlConnectionTests()
        {
            var accessTokenHandler = Substitute.For <IAccessTokenHandler>();

            accessTokenHandler.GetAccessTokenAsync(AzureResource).Returns(Task.FromResult(TestAccessToken));

            SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration = new SqlServerDataStoreConfiguration();

            sqlServerDataStoreConfiguration.ConnectionString   = $"Server={ServerName};Database={DatabaseName};";
            sqlServerDataStoreConfiguration.AuthenticationType = SqlServerAuthenticationType.ManagedIdentity;
            _sqlConnectionFactory = new ManagedIdentitySqlConnectionFactory(new DefaultSqlConnectionStringProvider(sqlServerDataStoreConfiguration), accessTokenHandler);
        }
Exemple #21
0
        public SqlServerSchemaDataStore(
            SqlConnectionWrapperFactory sqlConnectionWrapperFactory,
            SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration,
            ILogger <SqlServerSchemaDataStore> logger)
        {
            EnsureArg.IsNotNull(sqlConnectionWrapperFactory, nameof(sqlConnectionWrapperFactory));
            EnsureArg.IsNotNull(sqlServerDataStoreConfiguration, nameof(sqlServerDataStoreConfiguration));
            EnsureArg.IsNotNull(logger, nameof(logger));

            _sqlConnectionWrapperFactory = sqlConnectionWrapperFactory;
            _configuration = sqlServerDataStoreConfiguration;
            _logger        = logger;
        }
Exemple #22
0
        public SqlIntegrationTestBase(ITestOutputHelper outputHelper)
        {
            Output       = outputHelper;
            DatabaseName = $"IntegrationTests_BaseSchemaRunner_{Guid.NewGuid().ToString().Replace("-", string.Empty)}";
            Config       = new SqlServerDataStoreConfiguration
            {
                ConnectionString      = Environment.GetEnvironmentVariable("TestSqlConnectionString") ?? $"server=(local);Initial Catalog={DatabaseName};Integrated Security=true",
                AllowDatabaseCreation = true,
            };

            ConnectionStringProvider = Substitute.For <ISqlConnectionStringProvider>();
            ConnectionStringProvider.GetSqlConnectionString(Arg.Any <CancellationToken>()).ReturnsForAnyArgs(Config.ConnectionString);
        }
        public BaseSchemaRunner(
            ISqlConnectionFactory sqlConnectionFactory,
            ISchemaManagerDataStore schemaManagerDataStore,
            SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration)
        {
            EnsureArg.IsNotNull(sqlConnectionFactory);
            EnsureArg.IsNotNull(schemaManagerDataStore);
            EnsureArg.IsNotNull(sqlServerDataStoreConfiguration);

            _sqlConnectionFactory            = sqlConnectionFactory;
            _schemaManagerDataStore          = schemaManagerDataStore;
            _sqlServerDataStoreConfiguration = sqlServerDataStoreConfiguration;
        }
Exemple #24
0
 public SqlSchemaManager(
     SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration,
     IBaseSchemaRunner baseSchemaRunner,
     ISchemaManagerDataStore schemaManagerDataStore,
     ISchemaClient schemaClient,
     ILogger<SqlSchemaManager> logger)
 {
     _sqlServerDataStoreConfiguration = EnsureArg.IsNotNull(sqlServerDataStoreConfiguration, nameof(sqlServerDataStoreConfiguration));
     _baseSchemaRunner = EnsureArg.IsNotNull(baseSchemaRunner, nameof(baseSchemaRunner));
     _schemaManagerDataStore = EnsureArg.IsNotNull(schemaManagerDataStore, nameof(schemaManagerDataStore));
     _schemaClient = EnsureArg.IsNotNull(schemaClient, nameof(schemaClient));
     _logger = EnsureArg.IsNotNull(logger, nameof(logger));
 }
        private SchemaInitializer CreateSchemaInitializer(string testConnectionString)
        {
            var schemaOptions = new SqlServerSchemaOptions {
                AutomaticUpdatesEnabled = true
            };
            var config = new SqlServerDataStoreConfiguration {
                ConnectionString = testConnectionString, Initialize = true, SchemaOptions = schemaOptions
            };
            var schemaInformation   = new SchemaInformation((int)SchemaVersion.V1, (int)SchemaVersion.V3);
            var scriptProvider      = new ScriptProvider <SchemaVersion>();
            var schemaUpgradeRunner = new SchemaUpgradeRunner(scriptProvider, config, NullLogger <SchemaUpgradeRunner> .Instance);

            return(new SchemaInitializer(config, schemaUpgradeRunner, schemaInformation, NullLogger <SchemaInitializer> .Instance));
        }
        public SchemaInitializer(SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration, SchemaUpgradeRunner schemaUpgradeRunner, SchemaInformation schemaInformation, ISqlConnectionFactory sqlConnectionFactory, ILogger <SchemaInitializer> logger)
        {
            EnsureArg.IsNotNull(sqlServerDataStoreConfiguration, nameof(sqlServerDataStoreConfiguration));
            EnsureArg.IsNotNull(schemaUpgradeRunner, nameof(schemaUpgradeRunner));
            EnsureArg.IsNotNull(schemaInformation, nameof(schemaInformation));
            EnsureArg.IsNotNull(sqlConnectionFactory, nameof(sqlConnectionFactory));
            EnsureArg.IsNotNull(logger, nameof(logger));

            _sqlServerDataStoreConfiguration = sqlServerDataStoreConfiguration;
            _schemaUpgradeRunner             = schemaUpgradeRunner;
            _schemaInformation    = schemaInformation;
            _sqlConnectionFactory = sqlConnectionFactory;
            _logger = logger;
        }
        public SchemaJobWorkerBackgroundService(SchemaJobWorker schemaJobWorker, SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration, SchemaInformation schemaInformation)
        {
            EnsureArg.IsNotNull(schemaJobWorker, nameof(schemaJobWorker));
            EnsureArg.IsNotNull(sqlServerDataStoreConfiguration, nameof(sqlServerDataStoreConfiguration));
            EnsureArg.IsNotNull(schemaInformation, nameof(schemaInformation));

            _schemaJobWorker = schemaJobWorker;
            _sqlServerDataStoreConfiguration = sqlServerDataStoreConfiguration;
            _schemaInformation = schemaInformation;
#if NET5_0_OR_GREATER
            _instanceName = Guid.NewGuid() + "-" + Environment.ProcessId;
#else
            _instanceName = Guid.NewGuid() + "-" + System.Diagnostics.Process.GetCurrentProcess().Id;
#endif
        }
Exemple #28
0
        public SchemaJobWorker(
            IServiceProvider services,
            SqlServerDataStoreConfiguration sqlServerDataStoreConfiguration,
            IMediator mediator,
            ILogger <SchemaJobWorker> logger)
        {
            EnsureArg.IsNotNull(services, nameof(services));
            EnsureArg.IsNotNull(sqlServerDataStoreConfiguration, nameof(sqlServerDataStoreConfiguration));
            EnsureArg.IsNotNull(mediator, nameof(mediator));
            EnsureArg.IsNotNull(logger, nameof(logger));

            _serviceProvider = services;
            _sqlServerDataStoreConfiguration = sqlServerDataStoreConfiguration;
            _mediator = mediator;
            _logger   = logger;
        }
Exemple #29
0
        private SchemaInitializer CreateSchemaInitializer(string testConnectionString)
        {
            var schemaOptions = new SqlServerSchemaOptions {
                AutomaticUpdatesEnabled = true
            };
            var config = new SqlServerDataStoreConfiguration {
                ConnectionString = testConnectionString, Initialize = true, SchemaOptions = schemaOptions
            };
            var schemaInformation   = new SchemaInformation(SchemaVersionConstants.Min, SchemaVersionConstants.Max);
            var scriptProvider      = new ScriptProvider <SchemaVersion>();
            var baseScriptProvider  = new BaseScriptProvider();
            var mediator            = Substitute.For <IMediator>();
            var schemaUpgradeRunner = new SchemaUpgradeRunner(scriptProvider, baseScriptProvider, config, mediator, NullLogger <SchemaUpgradeRunner> .Instance);

            return(new SchemaInitializer(config, schemaUpgradeRunner, schemaInformation, NullLogger <SchemaInitializer> .Instance));
        }
        public SqlServerFhirModel(
            SqlServerDataStoreConfiguration configuration,
            SchemaInformation schemaInformation,
            SupportedSearchParameterDefinitionManagerResolver searchParameterDefinitionManagerResolver,
            IOptions <SecurityConfiguration> securityConfiguration,
            ILogger <SqlServerFhirModel> logger)
            : base(configuration, schemaInformation, logger)
        {
            EnsureArg.IsNotNull(searchParameterDefinitionManagerResolver, nameof(searchParameterDefinitionManagerResolver));
            EnsureArg.IsNotNull(securityConfiguration?.Value, nameof(securityConfiguration));
            EnsureArg.IsNotNull(logger, nameof(logger));

            _searchParameterDefinitionManager = searchParameterDefinitionManagerResolver();
            _securityConfiguration            = securityConfiguration.Value;
            _logger = logger;
        }