blob: ba40662f7aa21c5d8343c0f14e99e379cf3afd4b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
namespace marlin.web.Services;
using System.Diagnostics;
using System.Text;
using core.functional;
using core.models;
using Data;
using Microsoft.EntityFrameworkCore;
public class VersionControlSyncService : BackgroundService
{
private readonly ILogger<VersionControlSyncService> _logger;
private readonly IServiceProvider _services;
private ICollection<VersionControlSource> _sources;
private Dictionary<Guid, DateTime> _nextPoll;
public VersionControlSyncService(ILogger<VersionControlSyncService> logger, IServiceProvider services)
{
this._logger = logger;
this._services = services;
this._sources = new List<VersionControlSource>();
this._nextPoll = new();
}
public async Task FetchSources()
{
await using var scoped = this._services.CreateAsyncScope();
var dbContext = scoped.ServiceProvider.GetRequiredService<ApplicationDbContext>();
this._sources = await dbContext.Sources.ToListAsync();
}
private async Task SyncSource(VersionControlSource source, ApplicationDbContext db)
{
IGitClient client = new GitBinaryClient();
var refs = await client.GetRemoteRefs(source.UpstreamUrl);
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await this.FetchSources();
while (!stoppingToken.IsCancellationRequested)
{
}
}
}
|