wip
This commit is contained in:
parent
ddb6abc14e
commit
f3ab94eff1
6 changed files with 59 additions and 92 deletions
|
|
@ -3,20 +3,12 @@ using Microsoft.ApplicationInsights.Extensibility;
|
|||
|
||||
namespace PlanTempus.Core.Telemetry.Enrichers
|
||||
{
|
||||
|
||||
public class EnrichWithMetaTelemetry : ITelemetryProcessor
|
||||
public class EnrichWithMetaTelemetry(ITelemetryProcessor next) : ITelemetryProcessor
|
||||
{
|
||||
private readonly ITelemetryProcessor _next;
|
||||
|
||||
public EnrichWithMetaTelemetry(ITelemetryProcessor next)
|
||||
{
|
||||
_next = next;
|
||||
}
|
||||
|
||||
public void Process(ITelemetry item)
|
||||
{
|
||||
//nothing going on here yet :)
|
||||
_next.Process(item);
|
||||
next.Process(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,20 +3,12 @@ using Microsoft.ApplicationInsights.Channel;
|
|||
|
||||
namespace PlanTempus.Core.Telemetry
|
||||
{
|
||||
public class SeqTelemetryChannel : InMemoryChannel, ITelemetryChannel
|
||||
public class SeqTelemetryChannel(IMessageChannel<ITelemetry> messageChannel, TelemetryClient telemetryClient)
|
||||
: InMemoryChannel, ITelemetryChannel
|
||||
{
|
||||
private readonly IMessageChannel<ITelemetry> _messageChannel;
|
||||
private readonly TelemetryClient _telemetryClient;
|
||||
|
||||
public SeqTelemetryChannel(IMessageChannel<ITelemetry> messageChannel, TelemetryClient telemetryClient)
|
||||
{
|
||||
_messageChannel = messageChannel;
|
||||
_telemetryClient = telemetryClient;
|
||||
}
|
||||
public new void Send(ITelemetry telemetry)
|
||||
{
|
||||
|
||||
if (telemetry.Context.GlobalProperties.TryGetValue("OmitSeqTelemetryChannel", out string value))
|
||||
if (telemetry.Context.GlobalProperties.TryGetValue("OmitSeqTelemetryChannel", out var value))
|
||||
if (value == "true")
|
||||
{
|
||||
base.Send(telemetry);
|
||||
|
|
@ -25,7 +17,7 @@ namespace PlanTempus.Core.Telemetry
|
|||
|
||||
try
|
||||
{
|
||||
var writeTask = _messageChannel.Writer.WriteAsync(telemetry).AsTask();
|
||||
var writeTask = messageChannel.Writer.WriteAsync(telemetry).AsTask();
|
||||
writeTask.ContinueWith(t =>
|
||||
{
|
||||
if (t.Exception != null)
|
||||
|
|
@ -36,8 +28,10 @@ namespace PlanTempus.Core.Telemetry
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_telemetryClient.TrackException(e, new Dictionary<string, string> { { "OmitSeqTelemetryChannel", "true" } });
|
||||
telemetryClient.TrackException(e,
|
||||
new Dictionary<string, string> { { "OmitSeqTelemetryChannel", "true" } });
|
||||
}
|
||||
|
||||
base.Send(telemetry);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace PlanTempus.Components.Users.Create
|
|||
try
|
||||
{
|
||||
var sql = @"
|
||||
INSERT INTO system.users(email, password_hash, security_stamp, email_confirmed,
|
||||
INSERT INTO system.users(email , password_hash, security_stamp, email_confirmed,
|
||||
access_failed_count, lockout_enabled,
|
||||
is_active)
|
||||
VALUES(@Email, @PasswordHash, @SecurityStamp, @EmailConfirmed,
|
||||
|
|
|
|||
|
|
@ -22,24 +22,23 @@ namespace PlanTempus.SetupInfrastructure
|
|||
/// 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>;"
|
||||
/// "DefaultConnection": "Host=192.168.1.57;Port=5432;Database=ptdb01;User Id=[uid];Password=[secret];"
|
||||
/// </summary>
|
||||
internal class Program
|
||||
{
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var host = Host.CreateDefaultBuilder(args)
|
||||
.UseEnvironment("Dev")
|
||||
.UseServiceProviderFactory(new Autofac.Extensions.DependencyInjection.AutofacServiceProviderFactory())
|
||||
.UseServiceProviderFactory(
|
||||
new Autofac.Extensions.DependencyInjection.AutofacServiceProviderFactory())
|
||||
.ConfigureContainer<ContainerBuilder>((hostContext, builder) =>
|
||||
{
|
||||
var startup = new Startup();
|
||||
startup.ConfigureContainer(builder);
|
||||
})
|
||||
|
||||
.Build();
|
||||
|
||||
await host.StartAsync();
|
||||
|
|
@ -57,32 +56,24 @@ namespace PlanTempus.SetupInfrastructure
|
|||
}
|
||||
}
|
||||
}
|
||||
public class ConsoleService
|
||||
{
|
||||
|
||||
public class ConsoleService(
|
||||
IDbConnectionFactory connectionFactory,
|
||||
SetupDbAdmin setupDbAdmin,
|
||||
SetupIdentitySystem setupIdentitySystem,
|
||||
SetupConfiguration setupConfiguration,
|
||||
SetupApplicationUser setupApplicationUser)
|
||||
{
|
||||
static ConsoleColor _backgroundColor = Console.BackgroundColor;
|
||||
static ConsoleColor _foregroundColor = Console.ForegroundColor;
|
||||
private readonly IDbConnectionFactory _connectionFactory;
|
||||
private readonly SetupDbAdmin _setupDbAdmin;
|
||||
private readonly SetupIdentitySystem _setupIdentitySystem;
|
||||
private readonly SetupConfiguration _setupConfiguration;
|
||||
private readonly SetupApplicationUser _setupApplicationUser;
|
||||
|
||||
public ConsoleService(IDbConnectionFactory connectionFactory, SetupDbAdmin setupDbAdmin, SetupIdentitySystem setupIdentitySystem, SetupConfiguration setupConfiguration, SetupApplicationUser setupApplicationUser)
|
||||
{
|
||||
_connectionFactory = connectionFactory;
|
||||
_setupDbAdmin = setupDbAdmin;
|
||||
_setupIdentitySystem = setupIdentitySystem;
|
||||
_setupConfiguration = setupConfiguration;
|
||||
_setupApplicationUser = setupApplicationUser;
|
||||
}
|
||||
bool IsSuperAdmin(ConnectionStringParameters parameters)
|
||||
{
|
||||
Console.WriteLine("Testing db access...");
|
||||
|
||||
string query = @"SELECT usename, usesuper FROM pg_user WHERE usename = CURRENT_USER;";
|
||||
|
||||
using var conn = _connectionFactory.Create(parameters);
|
||||
using var conn = connectionFactory.Create(parameters);
|
||||
var result = (dynamic)conn.QuerySql(query).Single();
|
||||
|
||||
string username = result.usename;
|
||||
|
|
@ -131,9 +122,8 @@ namespace PlanTempus.SetupInfrastructure
|
|||
Console.Read();
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
static void Welcome()
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Blue;
|
||||
|
|
@ -151,7 +141,6 @@ namespace PlanTempus.SetupInfrastructure
|
|||
\/ \/ |__|");
|
||||
Console.WriteLine();
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
|
||||
}
|
||||
|
||||
public void Run()
|
||||
|
|
@ -165,7 +154,7 @@ namespace PlanTempus.SetupInfrastructure
|
|||
{
|
||||
Console.WriteLine("Input username:password for a superadmin role");
|
||||
userPass = Console.ReadLine() ?? string.Empty;
|
||||
} while (!userPass.Contains(":") || userPass.Split(":").Length != 2 ||
|
||||
} while (!userPass.Contains(':') || userPass.Split(":").Length != 2 ||
|
||||
string.IsNullOrEmpty(userPass.Split(":")[0]) ||
|
||||
string.IsNullOrEmpty(userPass.Split(":")[1]));
|
||||
|
||||
|
|
@ -182,7 +171,9 @@ namespace PlanTempus.SetupInfrastructure
|
|||
Console.Write("Database.Core.DCL.SetupDbAdmin...");
|
||||
sw.Start();
|
||||
|
||||
_setupDbAdmin.With(new SetupDbAdmin.Command { Password = "3911", Schema = "system", User = "heimdall" }, superUser);
|
||||
setupDbAdmin.With(
|
||||
new SetupDbAdmin.Command
|
||||
{ Password = "3911", Schema = "system", User = "heimdall" }, superUser);
|
||||
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
Console.WriteLine("::");
|
||||
|
|
@ -193,14 +184,14 @@ namespace PlanTempus.SetupInfrastructure
|
|||
//use application user, we use that role from now.
|
||||
var connParams = new ConnectionStringParameters(User: "heimdall", Pwd: "3911");
|
||||
|
||||
_setupIdentitySystem.With(new SetupIdentitySystem.Command { Schema = "system" }, connParams);
|
||||
setupIdentitySystem.With(new SetupIdentitySystem.Command { Schema = "system" }, connParams);
|
||||
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
Console.WriteLine("::");
|
||||
Console.WriteLine("::");
|
||||
Console.Write("Database.ConfigurationManagementSystem.SetupConfiguration...");
|
||||
sw.Restart();
|
||||
_setupConfiguration.With(new SetupConfiguration.Command(), connParams);
|
||||
setupConfiguration.With(new SetupConfiguration.Command(), connParams);
|
||||
Console.Write($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
|
||||
|
|
@ -209,7 +200,9 @@ namespace PlanTempus.SetupInfrastructure
|
|||
Console.Write("Database.Core.DCL.SetupApplicationUser...");
|
||||
sw.Start();
|
||||
|
||||
_setupApplicationUser.With(new SetupApplicationUser.Command { Password = "3911", Schema = "system", User = "sathumper" }, superUser);
|
||||
setupApplicationUser.With(
|
||||
new SetupApplicationUser.Command { Password = "3911", Schema = "system", User = "sathumper" },
|
||||
superUser);
|
||||
Console.WriteLine($"DONE, took: {sw.ElapsedMilliseconds} ms");
|
||||
|
||||
|
||||
|
|
@ -219,7 +212,6 @@ namespace PlanTempus.SetupInfrastructure
|
|||
|
||||
Console.ForegroundColor = _foregroundColor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
catch (Exception e)
|
||||
|
|
@ -227,12 +219,7 @@ namespace PlanTempus.SetupInfrastructure
|
|||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(e);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -46,18 +46,6 @@ public abstract class TestFixture
|
|||
protected virtual void CreateContainerBuilder()
|
||||
{
|
||||
var configuration = Configuration();
|
||||
|
||||
//var logger = new LoggerConfiguration()
|
||||
// .MinimumLevel.Verbose()
|
||||
// .MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning)
|
||||
// .MinimumLevel.Override("System", Serilog.Events.LogEventLevel.Error)
|
||||
// .WriteTo.Seq("http://localhost:5341", apiKey: "Gt8hS9ClGNfOCAdswDlW")
|
||||
// .WriteTo.ApplicationInsights(configuration.Get<string>("ApplicationInsights:ConnectionString"),
|
||||
// TelemetryConverter.Traces)
|
||||
// .Enrich.FromLogContext()
|
||||
// .Enrich.WithMachineName()
|
||||
// .CreateLogger();
|
||||
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
builder.RegisterGeneric(typeof(Logger<>))
|
||||
|
|
@ -90,10 +78,9 @@ public abstract class TestFixture
|
|||
var telemetryClient = Container.Resolve<TelemetryClient>();
|
||||
telemetryClient.Flush();
|
||||
|
||||
if (Container != null)
|
||||
{
|
||||
if (Container is null) return;
|
||||
|
||||
Container.Dispose();
|
||||
Container = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
7
global.json
Normal file
7
global.json
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"sdk": {
|
||||
"version": "9.0.0",
|
||||
"rollForward": "latestMajor",
|
||||
"allowPrerelease": true
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue