Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<AnalysisLevel>latest-minimum</AnalysisLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion WaveBox.Core/src/BaseClasses.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static string QueryText(this InsertType insertType) {
case InsertType.Replace:
return "REPLACE";
default:
throw new ArgumentOutOfRangeException("InsertType");
throw new ArgumentOutOfRangeException(nameof(insertType));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion WaveBox.Core/src/Extensions/IListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static string ToCSV(this IList<string> list, bool quoted = false) {
}
}

return buffer.Trim(new char[] {' ', ','});
return buffer.Trim(' ', ',');
}
}
}
4 changes: 3 additions & 1 deletion WaveBox.Core/src/Logging/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ private Microsoft.Extensions.Logging.ILogger Logger {
private void Write(LogLevel level, object message, Exception exception) {
Microsoft.Extensions.Logging.ILogger current = Logger;
if (current != null) {
current.Log(level, exception, "{Message}", message);
if (current.IsEnabled(level)) {
current.Log(level, exception, "{Message}", message);
}
} else {
// Host not built yet; write straight to the console so early startup isn't silent
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss,fff") + " " + level + " " + category + " - " + message + (exception != null ? Environment.NewLine + exception : ""));
Expand Down
2 changes: 1 addition & 1 deletion WaveBox.Core/src/Model/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Folder ParentFolder() {
return Injection.Get<IFolderRepository>().FolderForId((int)ParentFolderId);
}

public void Scan() {
public static void Scan() {
// TO DO: scanning! yay!
}

Expand Down
18 changes: 9 additions & 9 deletions WaveBox.Core/src/Model/Playlist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public string CalculateHash() {

foreach (PlaylistItem playlistItem in result) {
itemIds.Append(playlistItem.ItemId);
itemIds.Append("|");
itemIds.Append('|');
}
} catch (Exception e) {
logger.Error(e);
Expand Down Expand Up @@ -152,9 +152,9 @@ public IList<IMediaItem> ListOfMediaItems() {
conn = Injection.Get<IDatabase>().GetSqliteConnection();
var result = conn.DeferredQuery<PlaylistItem>("SELECT * FROM PlaylistItem WHERE PlaylistId = ? ORDER BY ItemPosition", PlaylistId);

IList<IMediaItem> items = new List<IMediaItem>();
List<IMediaItem> items = new List<IMediaItem>();
foreach (PlaylistItem playlistItem in result) {
if (!ReferenceEquals(playlistItem.ItemId, null)) {
if (playlistItem.ItemId != null) {
IMediaItem item = Injection.Get<IMediaItemRepository>().MediaItemForId((int)playlistItem.ItemId);
if (!ReferenceEquals(item, null)) {
items.Add(item);
Expand All @@ -177,7 +177,7 @@ public void RemoveMediaItem(IMediaItem item) {
}

public void RemoveMediaItems(IList<IMediaItem> items) {
IList<int> indexes = new List<int>();
List<int> indexes = new List<int>();
if (PlaylistId == 0 || items == null) {
return;
}
Expand Down Expand Up @@ -356,7 +356,7 @@ public void AddMediaItem(int itemId, bool updateDatabase = true) {
}

public void AddMediaItems(IList<int> itemIds) {
IList<IMediaItem> items = new List<IMediaItem>();
List<IMediaItem> items = new List<IMediaItem>();
foreach (int itemId in itemIds) {
logger.IfInfo("Checking item id " + itemId);
IMediaItem item = Injection.Get<IMediaItemRepository>().MediaItemForId(itemId);
Expand All @@ -376,15 +376,15 @@ public void InsertMediaItem(int itemId, int index) {

public void InsertMediaItem(IMediaItem item, int index) {
// make sure the input is within bounds and is not null
if (ReferenceEquals(item, null) || index > PlaylistCount || index < 0 || ReferenceEquals(PlaylistId, null)) {
if (ReferenceEquals(item, null) || index > PlaylistCount || index < 0 || PlaylistId == null) {
return;
}

ISQLiteConnection conn = null;
try {
int? id = Injection.Get<IItemRepository>().GenerateItemId(ItemType.PlaylistItem);

if (!ReferenceEquals(id, null)) {
if (id != null) {
// to do - better way of knowing whether or not a query has been successfully completed.
conn = Injection.Get<IDatabase>().GetSqliteConnection();
conn.BeginTransaction();
Expand Down Expand Up @@ -446,13 +446,13 @@ public void ClearPlaylist() {
}

public void CreatePlaylist() {
if (ReferenceEquals(PlaylistId, null)) {
if (PlaylistId == null) {
UpdateDatabase();
}
}

public void DeletePlaylist() {
if (ReferenceEquals(PlaylistId, null)) {
if (PlaylistId == null) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions WaveBox.Core/src/Model/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public bool HasPermission(Role role) {
return this.Role >= role ? true : false;
}

public bool UpdateSession(string sessionId) {
public static bool UpdateSession(string sessionId) {
// Update user's session based on its session ID
Session s = Injection.Get<ISessionRepository>().SessionForSessionId(sessionId);

Expand Down Expand Up @@ -224,7 +224,7 @@ public bool CreateSession(string password, string clientName) {
}

public bool Delete() {
if (ReferenceEquals(UserId, null)) {
if (UserId == null) {
return true;
}

Expand Down
16 changes: 5 additions & 11 deletions WaveBox.Core/src/Repository/AlbumArtistRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,9 @@ public class AlbumArtistRepository : IAlbumArtistRepository {
private readonly ISongRepository songRepository;

public AlbumArtistRepository(IDatabase database, IItemRepository itemRepository, ISongRepository songRepository) {
if (database == null) {
throw new ArgumentNullException("database");
}
if (itemRepository == null) {
throw new ArgumentNullException("itemRepository");
}
if (songRepository == null) {
throw new ArgumentNullException("songRepository");
}
ArgumentNullException.ThrowIfNull(database);
ArgumentNullException.ThrowIfNull(itemRepository);
ArgumentNullException.ThrowIfNull(songRepository);

this.database = database;
this.itemRepository = itemRepository;
Expand Down Expand Up @@ -156,11 +150,11 @@ public IList<Song> SinglesForAlbumArtistId(int albumArtistId) {
try {
conn = database.GetSqliteConnection();

IList<Song> songs;
List<Song> songs;
songs = conn.Query<Song>("SELECT ItemId FROM Song WHERE AlbumArtistId = ? AND AlbumId IS NULL", albumArtistId);

if (songs.Count > 0) {
IList<int> songIds = new List<int>();
List<int> songIds = new List<int>();
foreach (Song song in songs) {
songIds.Add((int)song.ItemId);
}
Expand Down
8 changes: 2 additions & 6 deletions WaveBox.Core/src/Repository/AlbumRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ public class AlbumRepository : IAlbumRepository {
private readonly IItemRepository itemRepository;

public AlbumRepository(IDatabase database, IItemRepository itemRepository) {
if (database == null) {
throw new ArgumentNullException("database");
}
if (itemRepository == null) {
throw new ArgumentNullException("itemRepository");
}
ArgumentNullException.ThrowIfNull(database);
ArgumentNullException.ThrowIfNull(itemRepository);

this.database = database;
this.itemRepository = itemRepository;
Expand Down
4 changes: 1 addition & 3 deletions WaveBox.Core/src/Repository/ArtRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ public class ArtRepository : IArtRepository {
private readonly IDatabase database;

public ArtRepository(IDatabase database) {
if (database == null) {
throw new ArgumentNullException("database");
}
ArgumentNullException.ThrowIfNull(database);

this.database = database;
}
Expand Down
8 changes: 2 additions & 6 deletions WaveBox.Core/src/Repository/ArtistRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,8 @@ public class ArtistRepository : IArtistRepository {
private readonly IItemRepository itemRepository;

public ArtistRepository(IDatabase database, IItemRepository itemRepository) {
if (database == null) {
throw new ArgumentNullException("database");
}
if (itemRepository == null) {
throw new ArgumentNullException("itemRepository");
}
ArgumentNullException.ThrowIfNull(database);
ArgumentNullException.ThrowIfNull(itemRepository);

this.database = database;
this.itemRepository = itemRepository;
Expand Down
56 changes: 19 additions & 37 deletions WaveBox.Core/src/Repository/FavoriteRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,16 @@ public class FavoriteRepository : IFavoriteRepository {
private readonly IItemRepository itemRepository;

public FavoriteRepository(IDatabase database, IAlbumArtistRepository albumArtistRepository, IAlbumRepository albumRepository, IArtistRepository artistRepository, IFolderRepository folderRepository, IGenreRepository genreRepository, IPlaylistRepository playlistRepository, ISongRepository songRepository, IVideoRepository videoRepository, IItemRepository itemRepository) {
if (database == null) {
throw new ArgumentNullException("database");
}
if (albumRepository == null) {
throw new ArgumentNullException("albumRepository");
}
if (albumArtistRepository == null) {
throw new ArgumentNullException("albumArtistRepository");
}
if (artistRepository == null) {
throw new ArgumentNullException("artistRepository");
}
if (folderRepository == null) {
throw new ArgumentNullException("folderRepository");
}
if (genreRepository == null) {
throw new ArgumentNullException("genreRepository");
}
if (playlistRepository == null) {
throw new ArgumentNullException("playlistRepository");
}
if (songRepository == null) {
throw new ArgumentNullException("songRepository");
}
if (videoRepository == null) {
throw new ArgumentNullException("videoRepository");
}
if (itemRepository == null) {
throw new ArgumentNullException("itemRepository");
}
ArgumentNullException.ThrowIfNull(database);
ArgumentNullException.ThrowIfNull(albumRepository);
ArgumentNullException.ThrowIfNull(albumArtistRepository);
ArgumentNullException.ThrowIfNull(artistRepository);
ArgumentNullException.ThrowIfNull(folderRepository);
ArgumentNullException.ThrowIfNull(genreRepository);
ArgumentNullException.ThrowIfNull(playlistRepository);
ArgumentNullException.ThrowIfNull(songRepository);
ArgumentNullException.ThrowIfNull(videoRepository);
ArgumentNullException.ThrowIfNull(itemRepository);

this.database = database;
this.albumArtistRepository = albumArtistRepository;
Expand Down Expand Up @@ -94,19 +74,21 @@ public IList<Favorite> FavoritesForUserId(int userId) {

public IList<Favorite> FavoritesForArtistId(int? artistId, int? userId) {
if (artistId == null) {
throw new ArgumentNullException("artistId");
} else if (userId == null) {
throw new ArgumentNullException("userId");
throw new ArgumentNullException(nameof(artistId));
}
if (userId == null) {
throw new ArgumentNullException(nameof(userId));
}

return this.database.GetList<Favorite>("SELECT * FROM Favorite LEFT JOIN Song ON Song.ItemId = Favorite.FavoriteItemId WHERE Song.ArtistId = ? AND Favorite.FavoriteUserId = ?", artistId, userId);
}

public IList<Favorite> FavoritesForAlbumArtistId(int? albumArtistId, int? userId) {
if (albumArtistId == null) {
throw new ArgumentNullException("artistId");
} else if (userId == null) {
throw new ArgumentNullException("userId");
throw new ArgumentNullException(nameof(albumArtistId));
}
if (userId == null) {
throw new ArgumentNullException(nameof(userId));
}

return this.database.GetList<Favorite>("SELECT * FROM Favorite LEFT JOIN Song ON Song.ItemId = Favorite.FavoriteItemId WHERE Song.AlbumArtistId = ? AND Favorite.FavoriteUserId = ?", albumArtistId, userId);
Expand All @@ -117,7 +99,7 @@ public IList<IItem> ItemsForFavorites(IList<Favorite> favorites) {
return null;
}

IList<IItem> items = new List<IItem>();
List<IItem> items = new List<IItem>();
foreach (Favorite fav in favorites) {
switch (fav.FavoriteItemType) {
case ItemType.AlbumArtist:
Expand Down
16 changes: 4 additions & 12 deletions WaveBox.Core/src/Repository/FolderRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,10 @@ public class FolderRepository : IFolderRepository {
private readonly IVideoRepository videoRepository;

public FolderRepository(IDatabase database, IServerSettings serverSettings, ISongRepository songRepository, IVideoRepository videoRepository) {
if (database == null) {
throw new ArgumentNullException("database");
}
if (serverSettings == null) {
throw new ArgumentNullException("serverSettings");
}
if (songRepository == null) {
throw new ArgumentNullException("songRepository");
}
if (videoRepository == null) {
throw new ArgumentNullException("videoRepository");
}
ArgumentNullException.ThrowIfNull(database);
ArgumentNullException.ThrowIfNull(serverSettings);
ArgumentNullException.ThrowIfNull(songRepository);
ArgumentNullException.ThrowIfNull(videoRepository);

this.database = database;
this.serverSettings = serverSettings;
Expand Down
4 changes: 1 addition & 3 deletions WaveBox.Core/src/Repository/GenreRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ public class GenreRepository : IGenreRepository {
private readonly IDatabase database;

public GenreRepository(IDatabase database) {
if (database == null) {
throw new ArgumentNullException("database");
}
ArgumentNullException.ThrowIfNull(database);

this.database = database;
}
Expand Down
4 changes: 1 addition & 3 deletions WaveBox.Core/src/Repository/ItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public class ItemRepository : IItemRepository {
private readonly IDatabase database;

public ItemRepository(IDatabase database) {
if (database == null) {
throw new ArgumentNullException("database");
}
ArgumentNullException.ThrowIfNull(database);

this.database = database;
}
Expand Down
12 changes: 3 additions & 9 deletions WaveBox.Core/src/Repository/MediaItemRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,9 @@ public class MediaItemRepository : IMediaItemRepository {
private readonly IVideoRepository videoRepository;

public MediaItemRepository(IItemRepository itemRepository, ISongRepository songRepository, IVideoRepository videoRepository) {
if (itemRepository == null) {
throw new ArgumentNullException("itemRepository");
}
if (songRepository == null) {
throw new ArgumentNullException("songRepository");
}
if (videoRepository == null) {
throw new ArgumentNullException("videoRepository");
}
ArgumentNullException.ThrowIfNull(itemRepository);
ArgumentNullException.ThrowIfNull(songRepository);
ArgumentNullException.ThrowIfNull(videoRepository);

this.itemRepository = itemRepository;
this.songRepository = songRepository;
Expand Down
4 changes: 1 addition & 3 deletions WaveBox.Core/src/Repository/PlaylistRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ public class PlaylistRepository : IPlaylistRepository {
private readonly IDatabase database;

public PlaylistRepository(IDatabase database) {
if (database == null) {
throw new ArgumentNullException("database");
}
ArgumentNullException.ThrowIfNull(database);

this.database = database;
}
Expand Down
Loading
Loading