Skip to content

Commit d0d19c2

Browse files
committed
Added sync for sessions
1 parent 2ee6d1a commit d0d19c2

5 files changed

Lines changed: 26 additions & 11 deletions

File tree

SnackTime.Core/Database/DatabaseFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace SnackTime.Core.Database
44
{
55
public class DatabaseFactory
66
{
7-
private const string ConnectionString = "../Media.db";
7+
private const string ConnectionString = "Media.db";
88

99
public LiteDatabase GetDatabase()
1010
{
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
using System.Threading.Tasks;
2+
using Microsoft.AspNetCore.Mvc;
23
using Microsoft.Extensions.Logging;
34
using SnackTime.Core.Session;
5+
using SnackTime.WebApi.Services;
46

57
namespace SnackTime.WebApi.Controllers
68
{
@@ -9,19 +11,27 @@ namespace SnackTime.WebApi.Controllers
911
public class SessionController : ControllerBase
1012
{
1113
private readonly ILogger<SessionController> _logger;
12-
private readonly SessionService _sessionService;
14+
private readonly SessionService _sessionService;
15+
private readonly SessionSyncService _sessionSyncService;
1316

14-
public SessionController(ILogger<SessionController> logger, SessionService sessionService)
17+
public SessionController(ILogger<SessionController> logger, SessionService sessionService, SessionSyncService sessionSyncService)
1518
{
1619
_logger = logger;
1720
_sessionService = sessionService;
21+
_sessionSyncService = sessionSyncService;
1822
}
1923

2024
[HttpGet("")]
21-
public ActionResult GetSettings()
25+
public ActionResult GetAll()
2226
{
2327
return Ok(_sessionService.GetAll());
2428
}
2529

30+
[HttpGet("sync")]
31+
public async Task<ActionResult> SyncSession()
32+
{
33+
await _sessionSyncService.Sync();
34+
return Ok();
35+
}
2636
}
2737
}

SnackTime.WebApi/DependencyModule.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ protected override void Load(ContainerBuilder builder)
1818
builder.RegisterType<MediaPlayerObserver>().As<IHostedService>().SingleInstance();
1919

2020
builder.RegisterType<FileService>().AsSelf();
21+
builder.RegisterType<SessionSyncService>().AsSelf();
2122
builder.RegisterType<FileDownloadService>().AsSelf();
2223
}
2324
}
@@ -65,7 +66,9 @@ private Channel GetChannel()
6566
}
6667

6768
_lastAddress = address;
68-
return new Channel(_lastAddress, 50052, ChannelCredentials.Insecure);
69+
_lastChannel = new Channel(_lastAddress, 50052, ChannelCredentials.Insecure);
70+
71+
return _lastChannel;
6972
}
7073
}
7174
}

SnackTime.WebApi/Services/FileDownloadService.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,12 @@ public async Task DownloadFile(MediaFileId id)
112112
hash = BitConverter.ToString(byteHash).Replace("-", "").ToLowerInvariant();
113113
}
114114

115-
if (hash != res.Done.Hash)
116-
{
117-
throw new HashMismatchException(res.Done.Hash, hash);
118-
}
115+
// TODO
116+
//This needs to be the zip:ed file, else there will be a missmatch.
117+
// if (hash != res.Done.Hash)
118+
// {
119+
// throw new HashMismatchException(res.Done.Hash, hash);
120+
// }
119121

120122
_logger.LogDebug($"Combined files in {sw.Elapsed:g}");
121123
sw.Stop();

SnackTime.WebApi/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public Startup(IConfiguration configuration)
2424

2525
public void ConfigureContainer(ContainerBuilder builder)
2626
{
27-
builder.RegisterModule(new DependencyModule());
2827
builder.RegisterModule(new Mpv.JsonIpc.DependencyModule());
2928
builder.RegisterModule(new Core.DependencyModule());
29+
builder.RegisterModule(new DependencyModule());
3030
}
3131

3232
public void ConfigureServices(IServiceCollection services)

0 commit comments

Comments
 (0)