Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify postgresql samples #6943

Merged
merged 8 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
persistence.SqlDialect<SqlDialect.MsSqlServer>();
persistence.ConnectionBuilder(connectionBuilder: () => new SqlConnection(connectionString));
persistence.ConnectionBuilder(() => new SqlConnection(connectionString));

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
persistence.SqlDialect<SqlDialect.MsSqlServer>();
persistence.ConnectionBuilder(connectionBuilder: () => new SqlConnection(connectionString));
persistence.ConnectionBuilder(() => new SqlConnection(connectionString));

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void Apply(EndpointConfiguration endpointConfiguration)
var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistenceRenameSaga;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";

persistence.ConnectionBuilder(
connectionBuilder: () => new SqlConnection(connectionString));
() => new SqlConnection(connectionString));

endpointConfiguration.EnableInstallers();
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static void Apply(EndpointConfiguration endpointConfiguration)
var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistenceRenameSaga;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";

persistence.ConnectionBuilder(
connectionBuilder: () => new SqlConnection(connectionString));
() => new SqlConnection(connectionString));

endpointConfiguration.EnableInstallers();
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,21 @@

Console.Title = "EndpointMySql";

#region MySqlConfig

var endpointConfiguration = new EndpointConfiguration("Samples.SqlPersistence.EndpointMySql");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

#region MySqlConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();

var password = Environment.GetEnvironmentVariable("MySqlPassword");
if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'MySqlPassword' from Environment variables.");
}
var username = Environment.GetEnvironmentVariable("MySqlUserName");
if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'MySqlUserName' from Environment variables.");
}
var connection = $"server=localhost;user={username};database=sqlpersistencesample;port=3306;password={password};AllowUserVariables=True;AutoEnlist=false";
persistence.SqlDialect<SqlDialect.MySql>();
persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new MySqlConnection(connection);
});
var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

var connection = "server=localhost;user=root;database=sqlpersistencesample;port=3306;password=yourStrong(!)Password;AllowUserVariables=True;AutoEnlist=false";

persistence.ConnectionBuilder(() => new MySqlConnection(connection));
#endregion

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.EnableInstallers();

Expand All @@ -43,4 +29,4 @@
Console.WriteLine("Press any key to exit");
Console.ReadKey();

await endpointInstance.Stop();
await endpointInstance.Stop();
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,21 @@

Console.Title = "EndpointOracle";

#region OracleConfig

var endpointConfiguration = new EndpointConfiguration("EndpointOracle");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

#region OracleConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();

var password = Environment.GetEnvironmentVariable("OraclePassword");
if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'OraclePassword' from Environment variables.");
}

var username = Environment.GetEnvironmentVariable("OracleUserName");

if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'OracleUserName' from Environment variables.");
}

var connection = $"Data Source=localhost;User Id={username}; Password={password}; Enlist=false";

persistence.SqlDialect<SqlDialect.Oracle>();

persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new OracleConnection(connection);
});
var connection = $"Data Source=localhost;User Id=SYSTEM; Password=yourStrong(!)Password; Enlist=false";

persistence.ConnectionBuilder(() => new OracleConnection(connection));
#endregion

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

#endregion

endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.EnableInstallers();

Expand All @@ -48,4 +28,4 @@
Console.WriteLine("Press any key to exit");
Console.ReadKey();

await endpointInstance.Stop();
await endpointInstance.Stop();
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,17 @@

Console.Title = "EndpointPostgreSql";

#region PostgreSqlConfig

var endpointConfiguration = new EndpointConfiguration("EndpointPostgreSql");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();


#region PostgreSqlConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
var password = Environment.GetEnvironmentVariable("PostgreSqlPassword");

if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'PostgreSqlPassword' from Environment variables.");
}
var username = Environment.GetEnvironmentVariable("PostgreSqlUserName");

if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'PostgreSqlUserName' from Environment variables.");
}
var dialect = persistence.SqlDialect<SqlDialect.PostgreSql>();

var connection = $"Host=localhost;Username={username};Password={password};Database=NsbSamplesSqlPersistence";
var connection = "Host=localhost;Username=postgres;Password=yourStrong(!)Password;Database=NsbSamplesSqlPersistence";

var dialect = persistence.SqlDialect<SqlDialect.PostgreSql>();
persistence.ConnectionBuilder(() => new NpgsqlConnection(connection));
#endregion

dialect.JsonBParameterModifier(
modifier: parameter =>
Expand All @@ -37,17 +25,9 @@
npgsqlParameter.NpgsqlDbType = NpgsqlDbType.Jsonb;
});

persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new NpgsqlConnection(connection);
});

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

#endregion

endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.EnableInstallers();

Expand All @@ -58,4 +38,4 @@
Console.WriteLine("Press any key to exit");
Console.ReadKey();

await endpointInstance.Stop();
await endpointInstance.Stop();
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
// for SqlExpress use Data Source=.\SqlExpress;Initial Catalog=NsbSamplesSqlPersistence;Integrated Security=True;Encrypt=false
var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistence;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";
persistence.SqlDialect<SqlDialect.MsSqlServer>();
persistence.ConnectionBuilder(
connectionBuilder: () => new SqlConnection(connectionString));
var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

// for SqlExpress use Data Source=.\SqlExpress;Initial Catalog=NsbSamplesSqlPersistence;Integrated Security=True;Encrypt=false
var connectionString = "Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistence;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";

persistence.ConnectionBuilder(() => new SqlConnection(connectionString));
#endregion

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

SqlHelper.EnsureDatabaseExists(connectionString);

endpointConfiguration.UseTransport(new LearningTransport());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,21 @@

Console.Title = "EndpointMySql";

#region MySqlConfig

var endpointConfiguration = new EndpointConfiguration("Samples.SqlPersistence.EndpointMySql");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

#region MySqlConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();

var password = Environment.GetEnvironmentVariable("MySqlPassword");
if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'MySqlPassword' from Environment variables.");
}
var username = Environment.GetEnvironmentVariable("MySqlUserName");
if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'MySqlUserName' from Environment variables.");
}
var connection = $"server=localhost;user={username};database=sqlpersistencesample;port=3306;password={password};AllowUserVariables=True;AutoEnlist=false";
persistence.SqlDialect<SqlDialect.MySql>();
persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new MySqlConnection(connection);
});
var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

var connection = "server=localhost;user=root;database=sqlpersistencesample;port=3306;password=yourStrong(!)Password;AllowUserVariables=True;AutoEnlist=false";

persistence.ConnectionBuilder(() => new MySqlConnection(connection));
#endregion

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.EnableInstallers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,21 @@

Console.Title = "EndpointOracle";

#region OracleConfig

var endpointConfiguration = new EndpointConfiguration("EndpointOracle");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

#region OracleConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();

var password = Environment.GetEnvironmentVariable("OraclePassword");
if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'OraclePassword' from Environment variables.");
}

var username = Environment.GetEnvironmentVariable("OracleUserName");

if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'OracleUserName' from Environment variables.");
}

var connection = $"Data Source=localhost;User Id={username}; Password={password}; Enlist=false";

persistence.SqlDialect<SqlDialect.Oracle>();

persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new OracleConnection(connection);
});
var connection = "Data Source=localhost;User Id=SYSTEM; Password=yourStrong(!)Password; Enlist=false";

persistence.ConnectionBuilder(() => new OracleConnection(connection));
#endregion

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

#endregion

endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.EnableInstallers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,17 @@

Console.Title = "EndpointPostgreSql";

#region PostgreSqlConfig

var endpointConfiguration = new EndpointConfiguration("EndpointPostgreSql");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();


#region PostgreSqlConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
var password = Environment.GetEnvironmentVariable("PostgreSqlPassword");

if (string.IsNullOrWhiteSpace(password))
{
throw new Exception("Could not extract 'PostgreSqlPassword' from Environment variables.");
}
var username = Environment.GetEnvironmentVariable("PostgreSqlUserName");

if (string.IsNullOrWhiteSpace(username))
{
throw new Exception("Could not extract 'PostgreSqlUserName' from Environment variables.");
}
var dialect = persistence.SqlDialect<SqlDialect.PostgreSql>();

var connection = $"Host=localhost;Username={username};Password={password};Database=NsbSamplesSqlPersistence";
var connection = "Host=localhost;Username=postgres;Password=yourStrong(!)Password;Database=NsbSamplesSqlPersistence";

var dialect = persistence.SqlDialect<SqlDialect.PostgreSql>();
persistence.ConnectionBuilder(() => new NpgsqlConnection(connection));
#endregion

dialect.JsonBParameterModifier(
modifier: parameter =>
Expand All @@ -37,17 +25,9 @@
npgsqlParameter.NpgsqlDbType = NpgsqlDbType.Jsonb;
});

persistence.ConnectionBuilder(
connectionBuilder: () =>
{
return new NpgsqlConnection(connection);
});

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

#endregion

endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.EnableInstallers();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@

Console.Title = "EndpointSqlServer";

#region sqlServerConfig

var endpointConfiguration = new EndpointConfiguration("Samples.SqlPersistence.EndpointSqlServer");
endpointConfiguration.UseSerialization<SystemJsonSerializer>();

#region sqlServerConfig
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
// for SqlExpress use Data Source=.\SqlExpress;Initial Catalog=NsbSamplesSqlPersistence;Integrated Security=True;Encrypt=false
var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistence;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";
persistence.SqlDialect<SqlDialect.MsSqlServer>();
persistence.ConnectionBuilder(
connectionBuilder: () => new SqlConnection(connectionString));
var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

// for SqlExpress use Data Source=.\SqlExpress;Initial Catalog=NsbSamplesSqlPersistence;Integrated Security=True;Encrypt=false
var connectionString = "Server=localhost,1433;Initial Catalog=NsbSamplesSqlPersistence;User Id=SA;Password=yourStrong(!)Password;Encrypt=false";

persistence.ConnectionBuilder(() => new SqlConnection(connectionString));
#endregion

var subscriptions = persistence.SubscriptionSettings();
subscriptions.CacheFor(TimeSpan.FromMinutes(1));

SqlHelper.EnsureDatabaseExists(connectionString);

endpointConfiguration.UseTransport(new LearningTransport());
Expand Down
Loading