async fixes (#128)

* refactor local metadata provider

* resolve async warnings

* more async fixes
This commit is contained in:
Jason Dove
2021-04-03 11:01:20 -05:00
committed by GitHub
parent 633586ddba
commit d4a2197dfa
38 changed files with 525 additions and 649 deletions
+13 -11
View File
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using ErsatzTV.Core.Domain;
using LanguageExt;
@@ -8,7 +10,7 @@ namespace ErsatzTV.Infrastructure.Data
{
public static class DbInitializer
{
public static Unit Initialize(TvContext context)
public static async Task<Unit> Initialize(TvContext context, CancellationToken cancellationToken)
{
if (context.Resolutions.Any())
{
@@ -22,28 +24,28 @@ namespace ErsatzTV.Infrastructure.Data
new() { Id = 3, Name = "1920x1080", Width = 1920, Height = 1080 },
new() { Id = 4, Name = "3840x2160", Width = 3840, Height = 2160 }
};
context.Resolutions.AddRange(resolutions);
context.SaveChanges();
await context.Resolutions.AddRangeAsync(resolutions, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
var resolutionConfig = new ConfigElement
{
Key = ConfigElementKey.FFmpegDefaultResolutionId.Key,
Value = "3" // 1920x1080
};
context.ConfigElements.Add(resolutionConfig);
context.SaveChanges();
await context.ConfigElements.AddAsync(resolutionConfig, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
var defaultProfile = FFmpegProfile.New("1920x1080 x264 ac3", resolutions[2]);
context.FFmpegProfiles.Add(defaultProfile);
context.SaveChanges();
await context.FFmpegProfiles.AddAsync(defaultProfile, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
var profileConfig = new ConfigElement
{
Key = ConfigElementKey.FFmpegDefaultProfileId.Key,
Value = defaultProfile.Id.ToString()
};
context.ConfigElements.Add(profileConfig);
context.SaveChanges();
await context.ConfigElements.AddAsync(profileConfig, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
var defaultChannel = new Channel(Guid.NewGuid())
{
@@ -52,8 +54,8 @@ namespace ErsatzTV.Infrastructure.Data
FFmpegProfile = defaultProfile,
StreamingMode = StreamingMode.TransportStream
};
context.Channels.Add(defaultChannel);
context.SaveChanges();
await context.Channels.AddAsync(defaultChannel, cancellationToken);
await context.SaveChangesAsync(cancellationToken);
// TODO: create looping static image that mentions configuring via web
return Unit.Default;
@@ -64,10 +64,10 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.ThenInclude(mm => mm.Artwork)
.ToListAsync();
public async Task Update(Channel channel)
public Task Update(Channel channel)
{
_dbContext.Channels.Update(channel);
await _dbContext.SaveChangesAsync();
return _dbContext.SaveChangesAsync();
}
public async Task Delete(int channelId)
@@ -31,16 +31,16 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
public Task<Option<T>> GetValue<T>(ConfigElementKey key) =>
Get(key).MapT(ce => (T) Convert.ChangeType(ce.Value, typeof(T)));
public async Task Update(ConfigElement configElement)
public Task Update(ConfigElement configElement)
{
_dbContext.ConfigElements.Update(configElement);
await _dbContext.SaveChangesAsync();
return _dbContext.SaveChangesAsync();
}
public async Task Delete(ConfigElement configElement)
public Task Delete(ConfigElement configElement)
{
_dbContext.ConfigElements.Remove(configElement);
await _dbContext.SaveChangesAsync();
return _dbContext.SaveChangesAsync();
}
}
}
@@ -32,10 +32,10 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.Include(p => p.Resolution)
.ToListAsync();
public async Task Update(FFmpegProfile ffmpegProfile)
public Task Update(FFmpegProfile ffmpegProfile)
{
_dbContext.FFmpegProfiles.Update(ffmpegProfile);
await _dbContext.SaveChangesAsync();
return _dbContext.SaveChangesAsync();
}
public async Task Delete(int ffmpegProfileId)
@@ -124,10 +124,10 @@ namespace ErsatzTV.Infrastructure.Data.Repositories
.ToListAsync();
}
public async Task Update(Playout playout)
public Task Update(Playout playout)
{
_dbContext.Playouts.Update(playout);
await _dbContext.SaveChangesAsync();
return _dbContext.SaveChangesAsync();
}
public async Task Delete(int playoutId)