コード例 #1
0
 public EmbeddedDatabaseFixture()
 {
     PgServer = new PgServer(PostgreSQLVersion,
                             port: Port,
                             clearInstanceDirOnStop: true,
                             addLocalUserAccessPermission: true);
     PgServer.Start();
 }
コード例 #2
0
        public EmbeddedDatabaseFixture()
        {
            var serverParams = new Dictionary <string, string>();

            PgServer = new PgServer(PostgreSQLVersion,
                                    port: Port,
                                    clearInstanceDirOnStop: true,
                                    addLocalUserAccessPermission: true,
                                    instanceId: Guid.Empty,
                                    pgServerParams: serverParams);
            PgServer.Start();
        }
コード例 #3
0
        public void Start()
        {
            _server.Start();

            CreateSchema();
        }
コード例 #4
0
        public async Task InitializeAsync()
        {
            bool useDefaultDirectory = false;

            if (bool.TryParse(
                    Environment.GetEnvironmentVariable("urn:milou:deployer:web:tests:pgsql:AddLocalUserAccessPermission"),
                    out bool addUser))
            {
                AddLocalUserAccessPermission = addUser;
            }

            if (bool.TryParse(
                    Environment.GetEnvironmentVariable("urn:milou:deployer:web:tests:pgsql:DefaultDirectory"),
                    out bool useDefaultDirectoryEnabled))
            {
                useDefaultDirectory = useDefaultDirectoryEnabled;
            }

            string version = Environment.GetEnvironmentVariable("urn:milou:deployer:web:tests:pgsql:version")
                             .WithDefault("10.5.1");

            DirectoryInfo postgresqlDbDir;

            if (useDefaultDirectory)
            {
                postgresqlDbDir = null;
            }
            else
            {
                postgresqlDbDir = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
                                                                 "tools",
                                                                 "MysticMind.PostgresEmbed", version)).EnsureExists();
            }

            Console.WriteLine(typeof(MartenConfiguration));
            Console.WriteLine(typeof(Milou.Deployer.Web.IisHost.Areas.Deployment.Controllers.DeployController));

            try
            {
                try
                {
                    _pgServer = new PgServer(
                        version,
                        PostgresqlUser,
                        dbDir: postgresqlDbDir?.FullName ?? "",
                        addLocalUserAccessPermission: AddLocalUserAccessPermission,
                        clearInstanceDirOnStop: true);
                    _pgServer.Start();
                }
                finally
                {
                    _cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(CancellationTimeoutInSeconds));
                }

                string connStr = string.Format(ConnectionStringFormat, _pgServer.PgPort, PostgresqlUser);

                Environment.SetEnvironmentVariable("urn:milou:deployer:web:marten:singleton:connection-string", connStr);
                Environment.SetEnvironmentVariable("urn:milou:deployer:web:marten:singleton:enabled", "true");

                await BeforeInitialize(_cancellationTokenSource.Token);

                IReadOnlyCollection <string> args = await RunSetupAsync();

                if (CancellationToken.IsCancellationRequested)
                {
                    throw new Core.DeployerAppException("The cancellation token is already cancelled, skipping before start");
                }

                try
                {
                    _diagnosticMessageSink.OnMessage(new DiagnosticMessage("Running before start"));

                    await BeforeStartAsync(args);
                }
                catch (Exception ex) when(!ex.IsFatal())
                {
                    _diagnosticMessageSink.OnMessage(new DiagnosticMessage(ex.ToString()));
                    _cancellationTokenSource.Cancel();
                    throw new Core.DeployerAppException("Before start exception", ex);
                }

                if (CancellationToken.IsCancellationRequested)
                {
                    throw new Core.DeployerAppException("The cancellation token is already cancelled, skipping start");
                }

                await StartAsync(args);

                await Task.Delay(TimeSpan.FromSeconds(1));

                if (CancellationToken.IsCancellationRequested)
                {
                    throw new Core.DeployerAppException("The cancellation token is already cancelled, skipping run");
                }

                await RunAsync();

                if (CancellationToken.IsCancellationRequested)
                {
                    throw new Core.DeployerAppException("The cancellation token is already cancelled, skipping after run");
                }

                await AfterRunAsync();
            }
            catch (Exception ex) when(!ex.IsFatal())
            {
                Exception = ex;
                OnException(ex);
            }
        }