using System;
using OwlCore.Services;
using StrixMusic.Cores.Files.Models;
using StrixMusic.Sdk.CoreModels;
using StrixMusic.Sdk.FileMetadata.Models;
namespace StrixMusic.Cores.Files.Services
{
///
/// Contains caches for all instance created across all core instances.
///
///
/// A "file core" has the possibility of using a folder which is a subfolder of the root selected in another core instance.
/// This means the same exact data will appear in two different core instances.
///
/// Data from multiple different core instances are merged together by the Strix SDK, but this is computationally expensive.
///
/// By using a shared repository between all core instances, we reduce remove extra overhead when a single file is updated.
///
public static class InstanceCache
{
///
/// A cache of all albums across all core instances.
///
public static AlbumCacheRepo Albums { get; set; } = new AlbumCacheRepo();
///
/// A cache of all artists across all core instances.
///
public static ArtistCacheRepo Artists { get; set; } = new ArtistCacheRepo();
///
/// A cache of all tracks across all core instances.
///
public static TrackCacheRepo Tracks { get; set; } = new TrackCacheRepo();
///
/// A cache of all images across all core instances.
///
public static ImageCacheRepo Images { get; set; } = new ImageCacheRepo();
///
/// A cache of all playlists across all core instances.
///
public static PlaylistCacheRepo Playlists { get; set; } = new PlaylistCacheRepo();
}
///
/// A cache of all albums across all core instances.
///
public class AlbumCacheRepo : InstanceCacheRepository
{
///
public FilesCoreAlbum GetOrCreate(string id, ICore sourceCore, AlbumMetadata albumMetadata)
{
return GetOrCreate(id, () => new FilesCoreAlbum(sourceCore, albumMetadata));
}
}
///
/// A cache of all artists across all core instances.
///
public class ArtistCacheRepo : InstanceCacheRepository
{
///
public FilesCoreArtist GetOrCreate(string id, ICore sourceCore, ArtistMetadata artistMetadata)
{
return GetOrCreate(id, () => new FilesCoreArtist(sourceCore, artistMetadata));
}
}
///
/// A cache of all tracks across all core instances.
///
public class TrackCacheRepo : InstanceCacheRepository
{
///
public FilesCoreTrack GetOrCreate(string id, ICore sourceCore, TrackMetadata trackMetadata)
{
return GetOrCreate(id, () => new FilesCoreTrack(sourceCore, trackMetadata));
}
}
///
/// A cache of all images across all core instances.
///
public class ImageCacheRepo : InstanceCacheRepository
{
///
public FilesCoreImage GetOrCreate(string id, ICore sourceCore, ImageMetadata imageMetadata)
{
return GetOrCreate(id, () => new FilesCoreImage(sourceCore, imageMetadata));
}
}
///
/// A cache of all playlists across all core instances.
///
public class PlaylistCacheRepo : InstanceCacheRepository
{
///
public LocalFilesCorePlaylist GetOrCreate(string id, ICore sourceCore, PlaylistMetadata playlistMetadata)
{
return GetOrCreate(id, () => new LocalFilesCorePlaylist(sourceCore, playlistMetadata));
}
}
}