mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
misc clean-ing
This commit is contained in:
parent
cd5ceb668d
commit
de569d5e3c
9 changed files with 53 additions and 48 deletions
|
|
@ -1,31 +0,0 @@
|
|||
using System;
|
||||
using LibGit2Sharp;
|
||||
using MediatR;
|
||||
|
||||
namespace FilterLists.Agent.Application.Archiver
|
||||
{
|
||||
public static class CommitDownloadedLists
|
||||
{
|
||||
public class Command : IRequest
|
||||
{
|
||||
}
|
||||
|
||||
public class Handler : RequestHandler<Command>
|
||||
{
|
||||
private const string GitRepoDirectory = @"archives";
|
||||
|
||||
protected override void Handle(Command request)
|
||||
{
|
||||
if (!Repository.IsValid(GitRepoDirectory))
|
||||
Repository.Init(GitRepoDirectory);
|
||||
using (var repo = new Repository(GitRepoDirectory))
|
||||
{
|
||||
Commands.Stage(repo, "*");
|
||||
var utcNow = DateTime.UtcNow;
|
||||
var signature = new Signature("FilterLists.Agent", "noreply@filterlists.com", utcNow);
|
||||
repo.Commit(utcNow.ToShortDateString() + " FilterLists archive by FilterLists.Agent", signature, signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
using FilterLists.Agent.Infrastructure.Clients;
|
||||
using FilterLists.Agent.Core.Interfaces;
|
||||
using FilterLists.Agent.Infrastructure.Clients;
|
||||
using FilterLists.Agent.Infrastructure.Repositories;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
|
@ -10,22 +12,22 @@ public static class ServiceCollectionExtensions
|
|||
{
|
||||
public static void RegisterAgentServices(this IServiceCollection serviceCollection)
|
||||
{
|
||||
var configuration = GetConfiguration();
|
||||
var configurationRoot = BuildConfigurationRoot();
|
||||
serviceCollection.AddLogging(b =>
|
||||
{
|
||||
b.AddConsole();
|
||||
b.AddApplicationInsights(configuration["ApplicationInsights:InstrumentationKey"] ?? "");
|
||||
b.AddApplicationInsights(configurationRoot["ApplicationInsights:InstrumentationKey"] ?? "");
|
||||
});
|
||||
serviceCollection.AddMediatR(typeof(Program).Assembly);
|
||||
serviceCollection.AddHttpClient<AgentHttpClient>();
|
||||
serviceCollection.AddSingleton<IConfiguration>(configurationRoot);
|
||||
serviceCollection.AddSingleton<IFilterListsApiClient, FilterListsApiClient>();
|
||||
serviceCollection.AddTransient<IListInfoRepository, ListInfoRepository>();
|
||||
}
|
||||
|
||||
private static IConfigurationRoot GetConfiguration()
|
||||
private static IConfigurationRoot BuildConfigurationRoot()
|
||||
{
|
||||
return new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.Build();
|
||||
return new ConfigurationBuilder().AddEnvironmentVariables().Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
using FilterLists.Agent.Core.Interfaces;
|
||||
using MediatR;
|
||||
|
||||
namespace FilterLists.Agent.Application.Archiver
|
||||
namespace FilterLists.Agent.Features.Archiver
|
||||
{
|
||||
public static class CaptureLists
|
||||
{
|
||||
|
|
@ -18,15 +18,15 @@ public class Handler : AsyncRequestHandler<Command>
|
|||
|
||||
public Handler(IMediator mediator, IListInfoRepository listInfoRepository)
|
||||
{
|
||||
_repo = listInfoRepository;
|
||||
_mediator = mediator;
|
||||
_repo = listInfoRepository;
|
||||
}
|
||||
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
{
|
||||
var lists = await _repo.GetAll();
|
||||
await _mediator.Send(new DownloadLists.Command(lists), cancellationToken);
|
||||
await _mediator.Send(new CommitDownloadedLists.Command(), cancellationToken);
|
||||
await _mediator.Send(new CommitLists.Command(), cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
src/FilterLists.Agent/Features/Archiver/CommitLists.cs
Normal file
34
src/FilterLists.Agent/Features/Archiver/CommitLists.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using LibGit2Sharp;
|
||||
using MediatR;
|
||||
|
||||
namespace FilterLists.Agent.Features.Archiver
|
||||
{
|
||||
public static class CommitLists
|
||||
{
|
||||
public class Command : IRequest
|
||||
{
|
||||
}
|
||||
|
||||
public class Handler : RequestHandler<Command>
|
||||
{
|
||||
private const string RepoDirectory = @"archives";
|
||||
private const string SignatureName = @"FilterLists.Agent";
|
||||
private const string SignatureEmail = @"noreply@filterlists.com";
|
||||
private const string CommitMessageSuffix = " FilterLists archive by FilterLists.Agent";
|
||||
|
||||
protected override void Handle(Command request)
|
||||
{
|
||||
if (!Repository.IsValid(RepoDirectory))
|
||||
Repository.Init(RepoDirectory);
|
||||
using (var repo = new Repository(RepoDirectory))
|
||||
{
|
||||
Commands.Stage(repo, "*");
|
||||
var utcNow = DateTime.UtcNow;
|
||||
var signature = new Signature(SignatureName, SignatureEmail, utcNow);
|
||||
repo.Commit(utcNow.ToShortDateString() + CommitMessageSuffix, signature, signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
//TODO: upsert into MariaDB Rules table https://stackoverflow.com/questions/15271202/mysql-load-data-infile-with-on-duplicate-key-update
|
||||
|
||||
namespace FilterLists.Agent.Application.Archiver
|
||||
namespace FilterLists.Agent.Features.Archiver
|
||||
{
|
||||
public static class DownloadList
|
||||
{
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
using FilterLists.Agent.Core.Entities;
|
||||
using MediatR;
|
||||
|
||||
namespace FilterLists.Agent.Application.Archiver
|
||||
namespace FilterLists.Agent.Features.Archiver
|
||||
{
|
||||
public static class DownloadLists
|
||||
{
|
||||
|
|
@ -22,7 +22,7 @@ public Command(IEnumerable<ListInfo> listInfo)
|
|||
|
||||
public class Handler : AsyncRequestHandler<Command>
|
||||
{
|
||||
private const int MaxDegreeOfParallelism = 5; //TODO: tune
|
||||
private const int MaxDegreeOfParallelism = 5;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public Handler(IMediator mediator)
|
||||
|
|
@ -48,7 +48,7 @@ protected override async Task Handle(Command request, CancellationToken cancella
|
|||
private static IEnumerable<ListInfo> ShardByHost(IEnumerable<ListInfo> listInfo)
|
||||
{
|
||||
return listInfo.GroupBy(l => l.ViewUrl.Host)
|
||||
.SelectMany((g, gi) => g.Select((l, li) => new {Index = li, GroupIndex = gi, ListInfo = l}))
|
||||
.SelectMany((g, gi) => g.Select((l, i) => new {Index = i, GroupIndex = gi, ListInfo = l}))
|
||||
.OrderBy(a => a.Index)
|
||||
.ThenBy(a => a.GroupIndex)
|
||||
.Select(a => a.ListInfo);
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace FilterLists.Agent.Application.Archiver
|
||||
namespace FilterLists.Agent.Features.Archiver
|
||||
{
|
||||
public enum FileType
|
||||
{
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
using SharpCompress.Archives.SevenZip;
|
||||
using SharpCompress.Readers;
|
||||
|
||||
namespace FilterLists.Agent.Application.Archiver
|
||||
namespace FilterLists.Agent.Features.Archiver
|
||||
{
|
||||
public static class StreamExtensions
|
||||
{
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Application.Archiver;
|
||||
using FilterLists.Agent.Extensions;
|
||||
using FilterLists.Agent.Features.Archiver;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue