added boostrapper

This commit is contained in:
Nicolas Constant 2021-04-11 02:15:13 -04:00
parent 11adfa6c7d
commit 8d0a612238
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
4 changed files with 117 additions and 9 deletions

1
.gitignore vendored
View File

@ -351,3 +351,4 @@ MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
/src/BSLManager/Properties/launchSettings.json

View File

@ -6,7 +6,16 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Lamar" Version="5.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
<PackageReference Include="Terminal.Gui" Version="1.0.0-beta.11" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BirdsiteLive.Common\BirdsiteLive.Common.csproj" />
<ProjectReference Include="..\DataAccessLayers\BirdsiteLive.DAL.Postgres\BirdsiteLive.DAL.Postgres.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,62 @@
using System;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.Common.Structs;
using BirdsiteLive.DAL.Contracts;
using BirdsiteLive.DAL.Postgres.DataAccessLayers;
using BirdsiteLive.DAL.Postgres.Settings;
using Lamar;
namespace BSLManager
{
public class Bootstrapper
{
private readonly DbSettings _settings;
#region Ctor
public Bootstrapper(DbSettings settings)
{
_settings = settings;
}
#endregion
public Container Init()
{
var container = new Container(x =>
{
if (string.Equals(_settings.Type, DbTypes.Postgres, StringComparison.OrdinalIgnoreCase))
{
var connString = $"Host={_settings.Host};Username={_settings.User};Password={_settings.Password};Database={_settings.Name}";
var postgresSettings = new PostgresSettings
{
ConnString = connString
};
x.For<PostgresSettings>().Use(x => postgresSettings);
x.For<ITwitterUserDal>().Use<TwitterUserPostgresDal>().Singleton();
x.For<IFollowersDal>().Use<FollowersPostgresDal>().Singleton();
x.For<IDbInitializerDal>().Use<DbInitializerPostgresDal>().Singleton();
}
else
{
throw new NotImplementedException($"{_settings.Type} is not supported");
}
x.Scan(_ =>
{
//_.Assembly("BirdsiteLive.Twitter");
//_.Assembly("BirdsiteLive.Domain");
_.Assembly("BirdsiteLive.DAL");
_.Assembly("BirdsiteLive.DAL.Postgres");
//_.Assembly("BirdsiteLive.Moderation");
//_.Assembly("BirdsiteLive.Pipeline");
_.TheCallingAssembly();
_.WithDefaultConventions();
_.LookForRegistries();
});
});
return container;
}
}
}

View File

@ -1,7 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using BirdsiteLive.Common.Settings;
using BirdsiteLive.DAL.Contracts;
using Microsoft.Extensions.Configuration;
using NStack;
using Terminal.Gui;
@ -9,10 +14,35 @@ namespace BSLManager
{
class Program
{
static void Main(string[] args)
static async Task Main(string[] args)
{
Console.OutputEncoding = Encoding.Default;
var settings = GetSettings();
var bootstrapper = new Bootstrapper(settings);
var container = bootstrapper.Init();
var followersDal = container.GetInstance<IFollowersDal>();
await LaunchAppAsync(followersDal);
}
private static DbSettings GetSettings()
{
var builder = new ConfigurationBuilder()
.AddEnvironmentVariables();
var configuration = builder.Build();
var dbSettings = configuration.GetSection("Db").Get<DbSettings>();
return dbSettings;
}
private static async Task LaunchAppAsync(IFollowersDal followersDal)
{
var followers = await followersDal.GetAllFollowersAsync();
var orderedFollowers = followers.OrderByDescending(x => x.Followings.Count).ToList();
Application.Init();
var top = Application.Top;
@ -30,9 +60,14 @@ namespace BSLManager
top.Add(win);
// Creates a menubar, the item "New" has a help menu.
var menu = new MenuBar(new MenuBarItem[] {
new MenuBarItem ("_File", new MenuItem [] {
new MenuItem ("_Quit", "", () => { if (Quit ()) top.Running = false; })
var menu = new MenuBar(new MenuBarItem[]
{
new MenuBarItem("_File", new MenuItem[]
{
new MenuItem("_Quit", "", () =>
{
if (Quit()) top.Running = false;
})
}),
//new MenuBarItem ("_Edit", new MenuItem [] {
// new MenuItem ("_Copy", "", null),
@ -47,11 +82,11 @@ namespace BSLManager
var n = MessageBox.Query(50, 7, "Quit BSL Manager", "Are you sure you want to quit?", "Yes", "No");
return n == 0;
}
var listData = new List<string>();
for (var i = 0; i < 100; i++)
foreach (var follower in orderedFollowers)
{
listData.Add($"@User{i}@Instance.tld {i*3}");
listData.Add($"@{follower.Acct}@{follower.Host} {follower.Followings.Count}");
}
var list = new ListView(listData)
@ -102,7 +137,8 @@ namespace BSLManager
if (okpressed)
{
listData.RemoveAt(el);
typeof(Application).GetMethod("TerminalResized", BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, null);
typeof(Application).GetMethod("TerminalResized", BindingFlags.Static | BindingFlags.NonPublic)
.Invoke(null, null);
}
}
};
@ -114,6 +150,6 @@ namespace BSLManager
);
Application.Run();
}
}
}
}