Skip to content

Commit 285ba9a

Browse files
committed
Init
1 parent d10dcd7 commit 285ba9a

25 files changed

+543
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,4 @@ ASALocalRun/
328328

329329
# MFractors (Xamarin productivity tool) working folder
330330
.mfractor/
331+
Emb.Cli.NetCore/appsettings.json
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using System.IO;
3+
using System.Reflection;
4+
using Emb.Core.Constants;
5+
using Emb.Core.Models;
6+
using Emb.Core.Services;
7+
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Logging;
10+
11+
namespace Emb.Cli.NetCore.DependencyInjection
12+
{
13+
public static class ContainerConfiguration
14+
{
15+
private static ILoggerFactory CreateLoggerFactory(ApplicationSettings applicationSettings)
16+
{
17+
var loggerFactory = new LoggerFactory();
18+
var logPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? throw new InvalidOperationException(), applicationSettings.LogDirectoryName, "log-{Date}.txt");
19+
loggerFactory
20+
.AddConsole(applicationSettings.LogLevel)
21+
.AddFile(logPath, applicationSettings.LogLevel, retainedFileCountLimit: 10);
22+
return loggerFactory;
23+
}
24+
25+
public static void ConfigureServices(IServiceCollection services, IConfigurationRoot configurationRoot)
26+
{
27+
var applicationSettings = configurationRoot.GetSection(Defaults.ConfigurationSectionName).Get<ApplicationSettings>();
28+
services
29+
.AddSingleton<IConfigurationRoot>(configurationRoot)
30+
.AddSingleton<ApplicationSettings>(applicationSettings)
31+
.AddScoped<ILoggerFactory>(c => CreateLoggerFactory(applicationSettings))
32+
.AddScoped<PluginManager>()
33+
.AddScoped<MessageBrokerService>();
34+
}
35+
}
36+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
9+
<LangVersion>7.3</LangVersion>
10+
</PropertyGroup>
11+
12+
<ItemGroup>
13+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
14+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
15+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
16+
<PackageReference Include="Serilog.Extensions.Logging.File" Version="1.1.0" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\Emb.Core\Emb.Core.csproj" />
21+
</ItemGroup>
22+
23+
<ItemGroup>
24+
<None Update="appsettings.json">
25+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
26+
</None>
27+
</ItemGroup>
28+
29+
</Project>

Emb.Cli.NetCore/Program.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System.IO;
2+
using System.Reflection;
3+
using System.Threading.Tasks;
4+
using Emb.Cli.NetCore.DependencyInjection;
5+
using Emb.Core.Constants;
6+
using Emb.Core.Models;
7+
using Emb.Core.Services;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.DependencyInjection;
10+
11+
namespace Emb.Cli.NetCore
12+
{
13+
internal static class Program
14+
{
15+
private static IConfigurationRoot GetConfigurationRoot()
16+
{
17+
var currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
18+
var configurationBuilder = new ConfigurationBuilder()
19+
.SetBasePath(currentDirectory)
20+
.AddJsonFile(Defaults.ConfigurationFileName);
21+
var configurationRoot = configurationBuilder.Build();
22+
return configurationRoot;
23+
}
24+
25+
private static ServiceProvider CreateServiceProvider(IConfigurationRoot configurationRoot)
26+
{
27+
var serviceCollection = new ServiceCollection();
28+
ContainerConfiguration.ConfigureServices(serviceCollection, configurationRoot);
29+
var serviceProvider = serviceCollection.BuildServiceProvider();
30+
return serviceProvider;
31+
}
32+
33+
private static async Task Main(string[] args)
34+
{
35+
var configurationRoot = GetConfigurationRoot();
36+
var serviceProvider = CreateServiceProvider(configurationRoot);
37+
38+
var applicationSettings = configurationRoot.GetSection(Defaults.ConfigurationSectionName).Get<ApplicationSettings>();
39+
var messageBrokerService = serviceProvider.GetService<MessageBrokerService>();
40+
await messageBrokerService.RunOnceAsync(applicationSettings.DataFlows);
41+
}
42+
}
43+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"EmbConfiguration": {
3+
"DataFlows": [
4+
{
5+
"Name": "Task1",
6+
"Source": {
7+
"ProviderName": "DvachDataSourceProvider",
8+
"EndpointOptions": "b"
9+
},
10+
"Targets": [
11+
{
12+
"ProviderName": "FileTargetProvider",
13+
"EndpointOptions": "2ch_b_threads"
14+
}
15+
]
16+
}
17+
],
18+
"LogLevel": "Debug",
19+
"LogDirectoryName": "logs"
20+
}
21+
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
3+
namespace Emb.Common.Abstractions
4+
{
5+
public interface IDataFetchResult
6+
{
7+
IEnumerable<string> Items { get; set; }
8+
string State { get; set; }
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.Extensions.Configuration;
3+
4+
namespace Emb.Common.Abstractions
5+
{
6+
public interface IDataSourceProvider
7+
{
8+
Task<IDataFetchResult> GetNewItemsAsPlainTextAsync(IConfigurationRoot configurationRoot, string options);
9+
}
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Emb.Common.Abstractions
2+
{
3+
public interface IEndpointInfo
4+
{
5+
string ProviderName { get; set; }
6+
string EndpointOptions { get; set; }
7+
}
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.Extensions.Configuration;
3+
4+
namespace Emb.Common.Abstractions
5+
{
6+
public interface ITargetProvider
7+
{
8+
Task SendAsync(IConfigurationRoot configurationRoot, string options, string text);
9+
}
10+
}

Emb.Common/Emb.Common.csproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
9+
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.1.1" />
10+
<PackageReference Include="System.Composition" Version="1.2.0" />
11+
</ItemGroup>
12+
13+
</Project>

0 commit comments

Comments
 (0)