Convert project to perfusion

This commit is contained in:
Nikolay Kochulin 2018-12-19 15:18:41 +03:00
parent 58be680e4f
commit 1394062930
No known key found for this signature in database
GPG Key ID: 740A804DEB1981AC
6 changed files with 24 additions and 19 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "perfusion"]
path = perfusion
url = http://lserver1/git/perfusion.git

View File

@ -1,9 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Linq; using System.Linq;
using Dapper; using Dapper;
using MySql.Data.MySqlClient; using MySql.Data.MySqlClient;
using Perfusion;
namespace JetKarmaBot namespace JetKarmaBot
{ {
@ -105,7 +106,7 @@ namespace JetKarmaBot
#endregion #endregion
#region service #region service
public Db(Config cfg) public Db([Inject(true)]Config cfg)
{ {
Log("Initializing..."); Log("Initializing...");
Conn = new MySqlConnection(cfg.ConnectionString); Conn = new MySqlConnection(cfg.ConnectionString);

View File

@ -1,4 +1,5 @@
using JetKarmaBot.Commands; using JetKarmaBot.Commands;
using Perfusion;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -21,10 +22,9 @@ namespace JetKarmaBot
foreach (var u in db.Chats) foreach (var u in db.Chats)
client.SendTextMessageAsync(u.Value.ChatId, message); client.SendTextMessageAsync(u.Value.ChatId, message);
} }
public JetKarmaBot(Config cfg, Db db) public JetKarmaBot([Inject(true)]Config cfg)
{ {
this.db = db;
var httpProxy = new WebProxy($"{cfg.ProxyUrl}:{cfg.ProxyPort}") var httpProxy = new WebProxy($"{cfg.ProxyUrl}:{cfg.ProxyPort}")
{ {
Credentials = new NetworkCredential(cfg.ProxyLogin, cfg.ProxyPassword) Credentials = new NetworkCredential(cfg.ProxyLogin, cfg.ProxyPassword)
@ -46,8 +46,9 @@ namespace JetKarmaBot
#endregion #endregion
#region service #region service
Db db { get; } [Inject(true)] Db db { get; set; }
TelegramBotClient client { get; } TelegramBotClient client { get; }
[Inject(true)] Container container { get; set; }
User me { get; } User me { get; }
ChatCommandRouter commands; ChatCommandRouter commands;
@ -65,10 +66,10 @@ namespace JetKarmaBot
void InitCommands() void InitCommands()
{ {
commands = new ChatCommandRouter(); commands = new ChatCommandRouter();
commands.Add(new StartCommand(db)); commands.Add(container.ResolveObject(new StartCommand(db)));
commands.Add(new EchoCommand(client)); commands.Add(container.ResolveObject(new EchoCommand(client)));
commands.Add(new DefineCommand(client)); commands.Add(container.ResolveObject(new DefineCommand(client)));
commands.Add(new AwardCommand(db, client, me)); commands.Add(container.ResolveObject(new AwardCommand(db, client, me)));
} }
#endregion #endregion

View File

@ -10,6 +10,7 @@
<PackageReference Include="MySql.Data" Version="8.0.13" /> <PackageReference Include="MySql.Data" Version="8.0.13" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="Telegram.Bot" Version="14.10.0" /> <PackageReference Include="Telegram.Bot" Version="14.10.0" />
<ProjectReference Include="..\perfusion\Perfusion\Perfusion.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,4 +1,5 @@
using System; using System;
using Perfusion;
namespace JetKarmaBot namespace JetKarmaBot
{ {
@ -6,23 +7,20 @@ namespace JetKarmaBot
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
Current = new App(new Config("karma.cfg.json")); Container c = new Container();
c.AddInstance(new Config("karma.cfg.json"));
Current = c.GetInstance(typeof(App)) as App;
Current.Run();
Console.ReadKey(); Console.ReadKey();
} }
public static App Current { get; private set; } public static App Current { get; private set; }
public App(Config cfg) public void Run()
{ {
Config = cfg;
Db = new Db(Config);
Watcher = new JetKarmaBot(Config, Db);
Console.WriteLine("JatKarmaBot started!"); Console.WriteLine("JatKarmaBot started!");
} }
Config Config { get; } [Inject(true)] JetKarmaBot Watcher { get; }
Db Db { get; }
JetKarmaBot Watcher { get; }
} }
} }

1
perfusion Submodule

@ -0,0 +1 @@
Subproject commit a9bd490c796b243245573ca4c9739a29364d2dde