Made repository methods asynchronous. Simplified playlist repository. Use playlist manager in the app, and left playlist repository to only be used by the playlist manager.
This commit is contained in:
@@ -6,26 +6,26 @@ public class PlaylistRepository : JsonFileRepository<Playlist>, IPlaylistReposit
|
||||
{
|
||||
protected override string DirectoryName => Path.Combine("Playlists");
|
||||
|
||||
public PlaylistRepository()
|
||||
{
|
||||
List<Playlist> playlists = Get();
|
||||
//public PlaylistRepository()
|
||||
//{
|
||||
// List<Playlist> playlists = Get();
|
||||
|
||||
foreach (Playlist playlist in playlists)
|
||||
{
|
||||
playlist.PlaylistUpdated += OnPlaylistUpdated;
|
||||
}
|
||||
// foreach (Playlist playlist in playlists)
|
||||
// {
|
||||
// playlist.PlaylistUpdated += OnPlaylistUpdated;
|
||||
// }
|
||||
|
||||
if (playlists.Count == 0)
|
||||
AddPlaylist();
|
||||
}
|
||||
// if (playlists.Count == 0)
|
||||
// AddPlaylist();
|
||||
//}
|
||||
|
||||
private void OnPlaylistUpdated(object? sender, PlaylistUpdatedEventArgs e)
|
||||
{
|
||||
if (sender is not Playlist playlist)
|
||||
return;
|
||||
//private void OnPlaylistUpdated(object? sender, PlaylistUpdatedEventArgs e)
|
||||
//{
|
||||
// if (sender is not Playlist playlist)
|
||||
// return;
|
||||
|
||||
Save(playlist);
|
||||
}
|
||||
// Save(playlist);
|
||||
//}
|
||||
|
||||
public Playlist? GetPlaylist(PlaylistSong playlistSong)
|
||||
{
|
||||
@@ -46,27 +46,27 @@ public class PlaylistRepository : JsonFileRepository<Playlist>, IPlaylistReposit
|
||||
throw new Exception("Unable to determine new fileName");
|
||||
}
|
||||
|
||||
public event EventHandler<PlaylistAddedEventArgs>? PlaylistAdded;
|
||||
public event EventHandler<PlaylistRemovedEventArgs>? PlaylistRemoved;
|
||||
//public event EventHandler<PlaylistAddedEventArgs>? PlaylistAdded;
|
||||
//public event EventHandler<PlaylistRemovedEventArgs>? PlaylistRemoved;
|
||||
|
||||
public void AddPlaylist()
|
||||
{
|
||||
Playlist playlist = new()
|
||||
{
|
||||
Name = "New Playlist"
|
||||
};
|
||||
//public void AddPlaylist()
|
||||
//{
|
||||
// Playlist playlist = new()
|
||||
// {
|
||||
// Name = "New Playlist"
|
||||
// };
|
||||
|
||||
playlist.PlaylistUpdated += OnPlaylistUpdated;
|
||||
// playlist.PlaylistUpdated += OnPlaylistUpdated;
|
||||
|
||||
Save(playlist);
|
||||
PlaylistAdded?.Invoke(this, new(playlist));
|
||||
}
|
||||
// Save(playlist);
|
||||
// PlaylistAdded?.Invoke(this, new(playlist));
|
||||
//}
|
||||
|
||||
public void RemovePlaylist(Playlist playlist)
|
||||
{
|
||||
playlist.PlaylistUpdated -= OnPlaylistUpdated;
|
||||
//public void RemovePlaylist(Playlist playlist)
|
||||
//{
|
||||
// playlist.PlaylistUpdated -= OnPlaylistUpdated;
|
||||
|
||||
Delete(playlist);
|
||||
PlaylistRemoved?.Invoke(this, new(playlist));
|
||||
}
|
||||
// Delete(playlist);
|
||||
// PlaylistRemoved?.Invoke(this, new(playlist));
|
||||
//}
|
||||
}
|
||||
Reference in New Issue
Block a user