Skip to content

Commit

Permalink
Added sync for sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
Zexuz committed Apr 22, 2019
1 parent 2ee6d1a commit d0d19c2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion SnackTime.Core/Database/DatabaseFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace SnackTime.Core.Database
{
public class DatabaseFactory
{
private const string ConnectionString = "../Media.db";
private const string ConnectionString = "Media.db";

public LiteDatabase GetDatabase()
{
Expand Down
18 changes: 14 additions & 4 deletions SnackTime.WebApi/Controllers/SessionController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SnackTime.Core.Session;
using SnackTime.WebApi.Services;

namespace SnackTime.WebApi.Controllers
{
Expand All @@ -9,19 +11,27 @@ namespace SnackTime.WebApi.Controllers
public class SessionController : ControllerBase
{
private readonly ILogger<SessionController> _logger;
private readonly SessionService _sessionService;
private readonly SessionService _sessionService;
private readonly SessionSyncService _sessionSyncService;

public SessionController(ILogger<SessionController> logger, SessionService sessionService)
public SessionController(ILogger<SessionController> logger, SessionService sessionService, SessionSyncService sessionSyncService)
{
_logger = logger;
_sessionService = sessionService;
_sessionSyncService = sessionSyncService;
}

[HttpGet("")]
public ActionResult GetSettings()
public ActionResult GetAll()
{
return Ok(_sessionService.GetAll());
}

[HttpGet("sync")]
public async Task<ActionResult> SyncSession()
{
await _sessionSyncService.Sync();
return Ok();
}
}
}
5 changes: 4 additions & 1 deletion SnackTime.WebApi/DependencyModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected override void Load(ContainerBuilder builder)
builder.RegisterType<MediaPlayerObserver>().As<IHostedService>().SingleInstance();

builder.RegisterType<FileService>().AsSelf();
builder.RegisterType<SessionSyncService>().AsSelf();
builder.RegisterType<FileDownloadService>().AsSelf();
}
}
Expand Down Expand Up @@ -65,7 +66,9 @@ private Channel GetChannel()
}

_lastAddress = address;
return new Channel(_lastAddress, 50052, ChannelCredentials.Insecure);
_lastChannel = new Channel(_lastAddress, 50052, ChannelCredentials.Insecure);

return _lastChannel;
}
}
}
10 changes: 6 additions & 4 deletions SnackTime.WebApi/Services/FileDownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,12 @@ public async Task DownloadFile(MediaFileId id)
hash = BitConverter.ToString(byteHash).Replace("-", "").ToLowerInvariant();
}

if (hash != res.Done.Hash)
{
throw new HashMismatchException(res.Done.Hash, hash);
}
// TODO
//This needs to be the zip:ed file, else there will be a missmatch.
// if (hash != res.Done.Hash)
// {
// throw new HashMismatchException(res.Done.Hash, hash);
// }

_logger.LogDebug($"Combined files in {sw.Elapsed:g}");
sw.Stop();
Expand Down
2 changes: 1 addition & 1 deletion SnackTime.WebApi/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public Startup(IConfiguration configuration)

public void ConfigureContainer(ContainerBuilder builder)
{
builder.RegisterModule(new DependencyModule());
builder.RegisterModule(new Mpv.JsonIpc.DependencyModule());
builder.RegisterModule(new Core.DependencyModule());
builder.RegisterModule(new DependencyModule());
}

public void ConfigureServices(IServiceCollection services)
Expand Down

0 comments on commit d0d19c2

Please sign in to comment.