added boostrapper
This commit is contained in:
parent
11adfa6c7d
commit
8d0a612238
4 changed files with 117 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -351,3 +351,4 @@ MigrationBackup/
|
||||||
|
|
||||||
# Ionide (cross platform F# VS Code tools) working folder
|
# Ionide (cross platform F# VS Code tools) working folder
|
||||||
.ionide/
|
.ionide/
|
||||||
|
/src/BSLManager/Properties/launchSettings.json
|
||||||
|
|
|
@ -6,7 +6,16 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<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" />
|
<PackageReference Include="Terminal.Gui" Version="1.0.0-beta.11" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BirdsiteLive.Common\BirdsiteLive.Common.csproj" />
|
||||||
|
<ProjectReference Include="..\DataAccessLayers\BirdsiteLive.DAL.Postgres\BirdsiteLive.DAL.Postgres.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
62
src/BSLManager/Bootstrapper.cs
Normal file
62
src/BSLManager/Bootstrapper.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,12 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using BirdsiteLive.Common.Settings;
|
||||||
|
using BirdsiteLive.DAL.Contracts;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using NStack;
|
using NStack;
|
||||||
using Terminal.Gui;
|
using Terminal.Gui;
|
||||||
|
|
||||||
|
@ -9,10 +14,35 @@ namespace BSLManager
|
||||||
{
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
Console.OutputEncoding = Encoding.Default;
|
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();
|
Application.Init();
|
||||||
var top = Application.Top;
|
var top = Application.Top;
|
||||||
|
|
||||||
|
@ -30,9 +60,14 @@ namespace BSLManager
|
||||||
top.Add(win);
|
top.Add(win);
|
||||||
|
|
||||||
// Creates a menubar, the item "New" has a help menu.
|
// Creates a menubar, the item "New" has a help menu.
|
||||||
var menu = new MenuBar(new MenuBarItem[] {
|
var menu = new MenuBar(new MenuBarItem[]
|
||||||
new MenuBarItem ("_File", new MenuItem [] {
|
{
|
||||||
new MenuItem ("_Quit", "", () => { if (Quit ()) top.Running = false; })
|
new MenuBarItem("_File", new MenuItem[]
|
||||||
|
{
|
||||||
|
new MenuItem("_Quit", "", () =>
|
||||||
|
{
|
||||||
|
if (Quit()) top.Running = false;
|
||||||
|
})
|
||||||
}),
|
}),
|
||||||
//new MenuBarItem ("_Edit", new MenuItem [] {
|
//new MenuBarItem ("_Edit", new MenuItem [] {
|
||||||
// new MenuItem ("_Copy", "", null),
|
// 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");
|
var n = MessageBox.Query(50, 7, "Quit BSL Manager", "Are you sure you want to quit?", "Yes", "No");
|
||||||
return n == 0;
|
return n == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var listData = new List<string>();
|
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)
|
var list = new ListView(listData)
|
||||||
|
@ -102,7 +137,8 @@ namespace BSLManager
|
||||||
if (okpressed)
|
if (okpressed)
|
||||||
{
|
{
|
||||||
listData.RemoveAt(el);
|
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();
|
Application.Run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue