af1152b001
Refactored all C# test files to use explicit namespace declarations and moved all using directives inside the namespace block for consistency. Updated assembly info and cache files to reflect the new build. Adjusted MvcTestingAppManifest.json to use fully qualified assembly names. No functional changes; all updates are related to code style, organization, and project metadata.
80 lines
3.0 KiB
C#
80 lines
3.0 KiB
C#
// <copyright file="KeyframeRepository.cs" company="PlaceholderCompany">
|
|
// Copyright (c) PlaceholderCompany. All rights reserved.
|
|
// </copyright>
|
|
|
|
namespace Jellyfin.Server.Implementations.Item;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Jellyfin.Database.Implementations;
|
|
using Jellyfin.Database.Implementations.Entities;
|
|
using MediaBrowser.Controller.Persistence;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
/// <summary>
|
|
/// Repository for obtaining Keyframe data.
|
|
/// </summary>
|
|
public class KeyframeRepository : IKeyframeRepository
|
|
{
|
|
private readonly IDbContextFactory<JellyfinDbContext> _dbProvider;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="KeyframeRepository"/> class.
|
|
/// </summary>
|
|
/// <param name="dbProvider">The EFCore db factory.</param>
|
|
public KeyframeRepository(IDbContextFactory<JellyfinDbContext> dbProvider)
|
|
{
|
|
_dbProvider = dbProvider;
|
|
}
|
|
|
|
private static MediaEncoding.Keyframes.KeyframeData Map(KeyframeData entity)
|
|
{
|
|
return new MediaEncoding.Keyframes.KeyframeData(
|
|
entity.TotalDuration,
|
|
(entity.KeyframeTicks ?? []).ToList());
|
|
}
|
|
|
|
private KeyframeData Map(MediaEncoding.Keyframes.KeyframeData dto, Guid itemId)
|
|
{
|
|
return new()
|
|
{
|
|
ItemId = itemId,
|
|
TotalDuration = dto.TotalDuration,
|
|
KeyframeTicks = dto.KeyframeTicks.ToList()
|
|
};
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public IReadOnlyList<MediaEncoding.Keyframes.KeyframeData> GetKeyframeData(Guid itemId)
|
|
{
|
|
using var context = _dbProvider.CreateDbContext();
|
|
|
|
return context.KeyframeData.AsNoTracking().Where(e => e.ItemId.Equals(itemId)).Select(e => Map(e)).ToList();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task SaveKeyframeDataAsync(Guid itemId, MediaEncoding.Keyframes.KeyframeData data, CancellationToken cancellationToken)
|
|
{
|
|
using var context = _dbProvider.CreateDbContext();
|
|
var transaction = await context.Database.BeginTransactionAsync(cancellationToken).ConfigureAwait(false);
|
|
await using (transaction.ConfigureAwait(false))
|
|
{
|
|
await context.KeyframeData.Where(e => e.ItemId.Equals(itemId)).ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false);
|
|
await context.KeyframeData.AddAsync(Map(data, itemId), cancellationToken).ConfigureAwait(false);
|
|
await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
|
await transaction.CommitAsync(cancellationToken).ConfigureAwait(false);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task DeleteKeyframeDataAsync(Guid itemId, CancellationToken cancellationToken)
|
|
{
|
|
using var context = _dbProvider.CreateDbContext();
|
|
await context.KeyframeData.Where(e => e.ItemId.Equals(itemId)).ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false);
|
|
await context.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
|
|
}
|
|
}
|