Enhancing telemetry in Seq and fixes namespaces
This commit is contained in:
parent
5568007237
commit
9f4996bc8f
65 changed files with 1122 additions and 1139 deletions
|
|
@ -7,7 +7,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Database\Database.csproj" />
|
||||
<ProjectReference Include="..\Database\PlanTempus.Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -1,88 +1,91 @@
|
|||
using Autofac;
|
||||
using Insight.Database;
|
||||
using PlanTempus.Database.ConfigurationManagementSystem;
|
||||
using PlanTempus.Database.Core.DCL;
|
||||
using PlanTempus.Database.Core.DDL;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace SetupInfrastructure
|
||||
namespace PlanTempus.SetupInfrastructure
|
||||
{
|
||||
/// <summary>
|
||||
/// SETUP APPLICATION USER NAMED sathumper
|
||||
///
|
||||
/// This should be handled on the Postgresql db server with a superadmin or similar.
|
||||
///
|
||||
/// Execute SQL CreateRole.txt
|
||||
///
|
||||
/// After that is executed it is time for running this main program
|
||||
/// Remember to use the newly created sathumper
|
||||
/// "ConnectionStrings": {
|
||||
/// "DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptdb01;User Id=<uid>;Password=<secret>;"
|
||||
/// </summary>
|
||||
internal class Program
|
||||
{
|
||||
static IContainer _container;
|
||||
static ConsoleColor _backgroundColor = Console.BackgroundColor;
|
||||
static ConsoleColor _foregroundColor = Console.ForegroundColor;
|
||||
/// <summary>
|
||||
/// SETUP APPLICATION USER NAMED sathumper
|
||||
///
|
||||
/// This should be handled on the Postgresql db server with a superadmin or similar.
|
||||
///
|
||||
/// Execute SQL CreateRole.txt
|
||||
///
|
||||
/// After that is executed it is time for running this main program
|
||||
/// Remember to use the newly created sathumper
|
||||
/// "ConnectionStrings": {
|
||||
/// "DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptdb01;User Id=<uid>;Password=<secret>;"
|
||||
/// </summary>
|
||||
internal class Program
|
||||
{
|
||||
static IContainer _container;
|
||||
static ConsoleColor _backgroundColor = Console.BackgroundColor;
|
||||
static ConsoleColor _foregroundColor = Console.ForegroundColor;
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Welcome();
|
||||
string userPass;
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
Welcome();
|
||||
string userPass;
|
||||
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
Console.WriteLine("Input username:password for a superadmin role");
|
||||
userPass = Console.ReadLine() ?? string.Empty;
|
||||
} while (!userPass.Contains(":") || userPass.Split(":").Length != 2 ||
|
||||
string.IsNullOrEmpty(userPass.Split(":")[0]) ||
|
||||
string.IsNullOrEmpty(userPass.Split(":")[1]));
|
||||
try
|
||||
{
|
||||
do
|
||||
{
|
||||
Console.WriteLine("Input username:password for a superadmin role");
|
||||
userPass = Console.ReadLine() ?? string.Empty;
|
||||
} while (!userPass.Contains(":") || userPass.Split(":").Length != 2 ||
|
||||
string.IsNullOrEmpty(userPass.Split(":")[0]) ||
|
||||
string.IsNullOrEmpty(userPass.Split(":")[1]));
|
||||
|
||||
var ctp = new Startup.ConnectionStringTemplateParameters(
|
||||
user: userPass.Split(":")[0],
|
||||
pwd: userPass.Split(":")[1]
|
||||
);
|
||||
_container = new Startup().ConfigureContainer(ctp);
|
||||
var ctp = new Startup.ConnectionStringTemplateParameters(
|
||||
user: userPass.Split(":")[0],
|
||||
pwd: userPass.Split(":")[1]
|
||||
);
|
||||
_container = new Startup().ConfigureContainer(ctp);
|
||||
|
||||
if (IsSuperAdmin())
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
var sw = new Stopwatch();
|
||||
if (IsSuperAdmin())
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
var sw = new Stopwatch();
|
||||
|
||||
Console.Write("Database.Core.DCL.SetupDbAdmin...");
|
||||
sw.Start();
|
||||
var setupDbAdmin = _container.Resolve<Database.Core.DCL.SetupDbAdmin>();
|
||||
setupDbAdmin.With(new Database.Core.DCL.SetupDbAdmin.Command { Password = "3911", Schema = "system", User = "heimdall" });
|
||||
var setupDbAdmin = _container.Resolve<SetupDbAdmin>();
|
||||
setupDbAdmin.With(new SetupDbAdmin.Command { Password = "3911", Schema = "system", User = "heimdall" });
|
||||
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
|
||||
Console.WriteLine("::");
|
||||
Console.WriteLine("::");
|
||||
Console.Write("Database.Core.DDL.SetupIdentitySystem...");
|
||||
sw.Restart();
|
||||
|
||||
//create new container with application user, we use that role from now.
|
||||
_container = new Startup().ConfigureContainer(new Startup.ConnectionStringTemplateParameters("heimdall", "3911"));
|
||||
Console.WriteLine("::");
|
||||
Console.WriteLine("::");
|
||||
Console.Write("Database.Core.DDL.SetupIdentitySystem...");
|
||||
sw.Restart();
|
||||
|
||||
var setupIdentitySystem = _container.Resolve<Database.Core.DDL.SetupIdentitySystem>();
|
||||
setupIdentitySystem.With(new Database.Core.DDL.SetupIdentitySystem.Command { Schema = "system"});
|
||||
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
//create new container with application user, we use that role from now.
|
||||
_container = new Startup().ConfigureContainer(new Startup.ConnectionStringTemplateParameters("heimdall", "3911"));
|
||||
|
||||
Console.WriteLine("::");
|
||||
Console.WriteLine("::");
|
||||
Console.Write("Database.ConfigurationManagementSystem.SetupConfiguration...");
|
||||
sw.Restart();
|
||||
var setupConfigurationSystem = _container.Resolve<Database.ConfigurationManagementSystem.SetupConfiguration>();
|
||||
setupConfigurationSystem.With(new Database.ConfigurationManagementSystem.SetupConfiguration.Command());
|
||||
Console.Write($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
var setupIdentitySystem = _container.Resolve<SetupIdentitySystem>();
|
||||
setupIdentitySystem.With(new SetupIdentitySystem.Command { Schema = "system" });
|
||||
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
Console.WriteLine("::");
|
||||
Console.WriteLine("::");
|
||||
Console.Write("Database.ConfigurationManagementSystem.SetupConfiguration...");
|
||||
sw.Restart();
|
||||
var setupConfigurationSystem = _container.Resolve<SetupConfiguration>();
|
||||
setupConfigurationSystem.With(new SetupConfiguration.Command());
|
||||
Console.Write($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
|
||||
Console.WriteLine("::");
|
||||
Console.WriteLine("::");
|
||||
Console.Write("Database.Core.DCL.SetupApplicationUser...");
|
||||
sw.Start();
|
||||
var setupApplicationUser = _container.Resolve<Database.Core.DCL.SetupApplicationUser>();
|
||||
setupApplicationUser.With(new Database.Core.DCL.SetupApplicationUser.Command { Password = "3911", Schema = "system", User = "sathumper" });
|
||||
var setupApplicationUser = _container.Resolve<SetupApplicationUser>();
|
||||
setupApplicationUser.With(new SetupApplicationUser.Command { Password = "3911", Schema = "system", User = "sathumper" });
|
||||
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
|
||||
|
|
@ -91,86 +94,86 @@ namespace SetupInfrastructure
|
|||
// input configurations!!! TODO:Missing
|
||||
|
||||
Console.ForegroundColor = _foregroundColor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(e);
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsSuperAdmin()
|
||||
{
|
||||
static bool IsSuperAdmin()
|
||||
{
|
||||
|
||||
|
||||
//test db access
|
||||
Console.WriteLine("Testing db access...");
|
||||
//test db access
|
||||
Console.WriteLine("Testing db access...");
|
||||
|
||||
string query = @"SELECT usename, usesuper FROM pg_user WHERE usename = CURRENT_USER;";
|
||||
string query = @"SELECT usename, usesuper FROM pg_user WHERE usename = CURRENT_USER;";
|
||||
|
||||
var conn = _container.Resolve<IDbConnection>();
|
||||
var result = (dynamic)conn.QuerySql(query).Single();
|
||||
var conn = _container.Resolve<IDbConnection>();
|
||||
var result = (dynamic)conn.QuerySql(query).Single();
|
||||
|
||||
string username = result.usename;
|
||||
bool isSuperuser = (bool)result.usesuper;
|
||||
string username = result.usename;
|
||||
bool isSuperuser = (bool)result.usesuper;
|
||||
|
||||
if ((bool)result.usesuper)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.BackgroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("TEST SUCCESSFULLY");
|
||||
Console.WriteLine();
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.BackgroundColor = _backgroundColor;
|
||||
Console.WriteLine("-------------------------------");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Username: {username}");
|
||||
Console.WriteLine($"Super admin: true");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("-------------------------------");
|
||||
if ((bool)result.usesuper)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.BackgroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("TEST SUCCESSFULLY");
|
||||
Console.WriteLine();
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.BackgroundColor = _backgroundColor;
|
||||
Console.WriteLine("-------------------------------");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Username: {username}");
|
||||
Console.WriteLine($"Super admin: true");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("-------------------------------");
|
||||
|
||||
|
||||
Console.WriteLine("Press any key to start database setup");
|
||||
Console.Read();
|
||||
Console.WriteLine("Press any key to start database setup");
|
||||
Console.Read();
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.BackgroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("TEST WAS NOT SUCCESSFULLY");
|
||||
Console.WriteLine();
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.BackgroundColor = _backgroundColor;
|
||||
Console.WriteLine("-------------------------------");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Username: {username}");
|
||||
Console.WriteLine($"Super admin: false");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("-------------------------------");
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.BackgroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("TEST WAS NOT SUCCESSFULLY");
|
||||
Console.WriteLine();
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.BackgroundColor = _backgroundColor;
|
||||
Console.WriteLine("-------------------------------");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"Username: {username}");
|
||||
Console.WriteLine($"Super admin: false");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("-------------------------------");
|
||||
|
||||
|
||||
Console.WriteLine("User is required to be super admin");
|
||||
Console.Read();
|
||||
Console.WriteLine("User is required to be super admin");
|
||||
Console.Read();
|
||||
|
||||
return false;
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
static void Welcome()
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Blue;
|
||||
Console.WriteLine(@"__________.__ ___________
|
||||
}
|
||||
static void Welcome()
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Blue;
|
||||
Console.WriteLine(@"__________.__ ___________
|
||||
\______ \ | _____ ___\__ ___/___ _____ ______ __ __ ______
|
||||
| ___/ | \__ \ / \| |_/ __ \ / \\____ \| | \/ ___/
|
||||
| | | |__/ __ \| | \ |\ ___/| Y Y \ |_> > | /\___ \
|
||||
|
|
@ -182,9 +185,9 @@ namespace SetupInfrastructure
|
|||
/ \ ___/| | | | / |_> >
|
||||
/_______ /\___ >__| |____/| __/
|
||||
\/ \/ |__|");
|
||||
Console.WriteLine();
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Console.WriteLine();
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,45 +1,46 @@
|
|||
using Autofac;
|
||||
using Core.Configurations;
|
||||
using Core.Configurations.JsonConfigProvider;
|
||||
using PlanTempus.Core.Configurations;
|
||||
using PlanTempus.Core.Configurations.JsonConfigProvider;
|
||||
using PlanTempus.Core.ModuleRegistry;
|
||||
using PlanTempus.Database.Core;
|
||||
|
||||
|
||||
namespace SetupInfrastructure
|
||||
namespace PlanTempus.SetupInfrastructure
|
||||
{
|
||||
public class Startup
|
||||
{
|
||||
public virtual IConfigurationRoot Configuration()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.json")
|
||||
.Build();
|
||||
public class Startup
|
||||
{
|
||||
public virtual IConfigurationRoot Configuration()
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile("appconfiguration.json")
|
||||
.Build();
|
||||
|
||||
return configuration;
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
public IContainer ConfigureContainer(ConnectionStringTemplateParameters ctp)
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
var configuration = Configuration();
|
||||
public IContainer ConfigureContainer(ConnectionStringTemplateParameters ctp)
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
var configuration = Configuration();
|
||||
|
||||
|
||||
builder.RegisterModule(new Database.ModuleRegistry.DbPostgreSqlModule
|
||||
{
|
||||
ConnectionString = configuration.GetConnectionString("DefaultConnection").Replace("{usr}", ctp.user).Replace("{pwd}", ctp.pwd)
|
||||
});
|
||||
builder.RegisterModule(new Database.ModuleRegistry.DbPostgreSqlModule
|
||||
{
|
||||
ConnectionString = configuration.GetConnectionString("DefaultConnection").Replace("{usr}", ctp.user).Replace("{pwd}", ctp.pwd)
|
||||
});
|
||||
|
||||
builder.RegisterModule(new Core.ModuleRegistry.TelemetryModule
|
||||
{
|
||||
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<Core.ModuleRegistry.TelemetryConfig>()
|
||||
});
|
||||
builder.RegisterModule(new TelemetryModule
|
||||
{
|
||||
TelemetryConfig = configuration.GetSection("ApplicationInsights").ToObject<TelemetryConfig>()
|
||||
});
|
||||
|
||||
builder.RegisterAssemblyTypes(typeof(Database.Core.IDbConfigure<>).Assembly)
|
||||
.AsClosedTypesOf(typeof(Database.Core.IDbConfigure<>))
|
||||
.AsSelf();
|
||||
builder.RegisterAssemblyTypes(typeof(IDbConfigure<>).Assembly)
|
||||
.AsClosedTypesOf(typeof(IDbConfigure<>))
|
||||
.AsSelf();
|
||||
|
||||
|
||||
return builder.Build();
|
||||
}
|
||||
return builder.Build();
|
||||
}
|
||||
|
||||
public record ConnectionStringTemplateParameters(string user, string pwd);
|
||||
}
|
||||
public record ConnectionStringTemplateParameters(string user, string pwd);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue