#93: Working on build errors, removed DotnetZip dependency, and added new Ionic.Zlip.Netstandard dependency

This commit is contained in:
kdeng00
2024-07-26 19:35:12 -04:00
parent 983b434823
commit 6898776f5b
14 changed files with 104 additions and 91 deletions
+3 -3
View File
@@ -19,7 +19,7 @@ public class AlbumManager : BaseManager
{
_config = config;
_connectionString = _config.GetConnectionString("DefaultConnection");
_albumContext = new AlbumContext(_connectionString);
_albumContext = new AlbumContext(_connectionString!);
}
#endregion
@@ -89,7 +89,7 @@ public class AlbumManager : BaseManager
oldAlbumTitle.Equals(newAlbumTitle) && oldAlbumArtist.Equals(newAlbumArtist)))
{
_logger.Info("No change to the song's album");
return albumRecord;
return albumRecord!;
}
info = "Change to the song's album";
@@ -137,7 +137,7 @@ public class AlbumManager : BaseManager
private int SongsInAlbum(Album album)
{
var sngContext = new SongContext(_connectionString);
var sngContext = new SongContext(_connectionString!);
var songs = sngContext.Songs.Where(sng => sng.AlbumId == album.Id).ToList();
return songs.Count;
+2 -2
View File
@@ -7,7 +7,7 @@ public class BaseManager
{
#region Fields
protected static Logger _logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
protected IConfiguration _config;
protected string _connectionString;
protected IConfiguration? _config;
protected string? _connectionString;
#endregion
}
+1 -1
View File
@@ -78,7 +78,7 @@ public class CoverArtManager : BaseManager
var coverArt = new CoverArt
{
SongTitle = song.Title
SongTitle = song.Title!
};
var segment = coverArt.GenerateFilename(0);
+8 -8
View File
@@ -187,9 +187,9 @@ public class DirectoryManager : BaseManager
private class DirEnt
{
public string Pre { get; set;}
public string Path { get; set; }
public string Post { get; set; }
public string? Pre { get; set;}
public string? Path { get; set; }
public string? Post { get; set; }
}
private void GenerateDirectories(List<DirEnt> dirs)
@@ -197,7 +197,7 @@ public class DirectoryManager : BaseManager
foreach (var di in dirs)
{
_logger.Info(di.Pre);
Directory.CreateDirectory(di.Path);
Directory.CreateDirectory(di.Path!);
_logger.Info(di.Post);
}
}
@@ -207,10 +207,10 @@ public class DirectoryManager : BaseManager
switch (dirTypes)
{
case DirectoryType.Music:
_rootSongDirectory = _config.GetValue<string>("RootMusicPath");
_rootSongDirectory = _config!.GetValue<string>("RootMusicPath")!;
break;
case DirectoryType.CoverArt:
_rootSongDirectory = _config.GetValue<string>("CoverArtPath");
_rootSongDirectory = _config!.GetValue<string>("CoverArtPath")!;
break;
}
}
@@ -227,7 +227,7 @@ public class DirectoryManager : BaseManager
private string AlbumDirectory(Song song)
{
var directory = ArtistDirectory(song);
var segment = SerializeValue(song.AlbumTitle);
var segment = SerializeValue(song.AlbumTitle!);
directory += $@"{segment}/";
Console.WriteLine($"Album directory {directory}");
@@ -240,7 +240,7 @@ public class DirectoryManager : BaseManager
private string ArtistDirectory(Song song)
{
var directory = _rootSongDirectory;
var segment = SerializeValue(song.Artist);
var segment = SerializeValue(song.Artist!);
directory += $@"{segment}/";
Console.WriteLine($"Artist directory {directory}");
+6 -6
View File
@@ -19,7 +19,7 @@ public class GenreManager : BaseManager
{
_config = config;
_connectionString = _config.GetConnectionString("DefaultConnection");
_genreContext = new GenreContext(_connectionString);
_genreContext = new GenreContext(_connectionString!);
}
#endregion
@@ -93,10 +93,10 @@ public class GenreManager : BaseManager
var existingGenreRecord = _genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(oldGenreRecord.GenreName));
_genreContext.Update(existingGenreRecord);
_genreContext.Update(existingGenreRecord!);
_genreContext.SaveChanges();
return existingGenreRecord;
return existingGenreRecord!;
}
}
@@ -110,16 +110,16 @@ public class GenreManager : BaseManager
var genre = _genreContext.Genres.FirstOrDefault(gnr => gnr.GenreName.Equals(song.Genre));
if (SongsInGenre(genre) <= 1)
if (SongsInGenre(genre!) <= 1)
{
_genreContext.Remove(genre);
_genreContext.Remove(genre!);
_genreContext.SaveChanges();
}
}
private int SongsInGenre(Genre genre)
{
var sngContext = new SongContext(_connectionString);
var sngContext = new SongContext(_connectionString!);
var songs = sngContext.Songs.Where(sng => sng.GenreId == genre.Id).ToList();
return songs.Count;
+29 -30
View File
@@ -9,11 +9,11 @@ namespace Icarus.Controllers.Managers;
public class SongManager : BaseManager
{
#region Fields
private string _tempDirectoryRoot;
private string _archiveDirectoryRoot;
private string _compressedSongFilename;
private string _message;
private SongContext _songContext;
private string? _tempDirectoryRoot;
private string? _archiveDirectoryRoot;
private string? _compressedSongFilename;
private string? _message;
private SongContext? _songContext;
#endregion
@@ -234,10 +234,10 @@ public class SongManager : BaseManager
}
}
var coverMgr = new CoverArtManager(_config);
var coverMgr = new CoverArtManager(_config!);
var coverArt = coverMgr.SaveCoverArt(coverArtData, song);
DirectoryManager dirMgr = new DirectoryManager(_config, song);
DirectoryManager dirMgr = new DirectoryManager(_config!, song);
dirMgr.CreateDirectory();
song.SongDirectory = dirMgr.SongDirectory;
@@ -262,13 +262,13 @@ public class SongManager : BaseManager
// Save cover art to the database
// Save song to the database
var coverMgr = new CoverArtManager(_config);
var coverMgr = new CoverArtManager(_config!);
var coverArt = coverMgr.SaveCoverArt(coverArtData, song);
var meta = new Utilities.MetadataRetriever();
meta.UpdateMetadata(song, song);
DirectoryManager dirMgr = new DirectoryManager(_config, song);
DirectoryManager dirMgr = new DirectoryManager(_config!, song);
dirMgr.CreateDirectory();
var tempPath = song.SongPath();
@@ -350,7 +350,7 @@ public class SongManager : BaseManager
public async Task<Song> SaveSongTemp(IFormFile songFile)
{
_logger.Info("Assigning song filename");
var song = new Song { SongDirectory = this._tempDirectoryRoot };
var song = new Song { SongDirectory = this._tempDirectoryRoot! };
var filename = await song.GenerateFilenameAsync(false) + "-" + songFile.FileName;
song.Filename = filename;
var songPath = song.SongPath();
@@ -371,7 +371,6 @@ public class SongManager : BaseManager
// song.SongDirectory = _tempDirectoryRoot;
song.DateCreated = DateTime.Now;
// song.Filename = filename;
return song;
}
@@ -385,9 +384,9 @@ public class SongManager : BaseManager
var currentGenre = currentSong.Genre;
var currentYear = currentSong.Year;
if (!currentTitle.Equals(songUpdates.Title) || !currentArtist.Equals(songUpdates.Artist) ||
!currentAlbum.Equals(songUpdates.AlbumTitle) ||
!currentGenre.Equals(songUpdates.Genre) || currentYear != songUpdates.Year)
if (!currentTitle!.Equals(songUpdates.Title) || !currentArtist!.Equals(songUpdates.Artist) ||
!currentAlbum!.Equals(songUpdates.AlbumTitle) ||
!currentGenre!.Equals(songUpdates.Genre) || currentYear != songUpdates.Year)
return true;
return false;
@@ -395,7 +394,7 @@ public class SongManager : BaseManager
private void DeleteEmptyDirectories(ref Song oldSong, ref Song updatedSong)
{
DirectoryManager mgr = new DirectoryManager(_config);
DirectoryManager mgr = new DirectoryManager(_config!);
_logger.Info("Checking to see if there are any directories to delete");
mgr.DeleteEmptyDirectories(oldSong);
@@ -405,8 +404,8 @@ public class SongManager : BaseManager
{
try
{
_connectionString = _config.GetConnectionString("DefaultConnection");
_songContext = new SongContext(_connectionString);
_connectionString = _config!.GetConnectionString("DefaultConnection");
_songContext = new SongContext(_connectionString!);
}
catch (Exception ex)
{
@@ -420,10 +419,10 @@ public class SongManager : BaseManager
{
_logger.Info("Starting process to save the song to the database");
var albumMgr = new AlbumManager(_config);
var artistMgr = new ArtistManager(_config);
var genreMgr = new GenreManager(_config);
var coverMgr = new CoverArtManager(_config);
var albumMgr = new AlbumManager(_config!);
var artistMgr = new ArtistManager(_config!);
var genreMgr = new GenreManager(_config!);
var coverMgr = new CoverArtManager(_config!);
albumMgr.SaveAlbumToDatabase(ref song);
artistMgr.SaveArtistToDatabase(ref song);
genreMgr.SaveGenreToDatabase(ref song);
@@ -431,10 +430,10 @@ public class SongManager : BaseManager
var info = "Saving Song to DB";
_logger.Info(info);
_songContext.Add(song);
_songContext.SaveChanges();
_songContext!.Add(song);
_songContext!.SaveChanges();
coverMgr.SaveCoverArtToDatabase(ref song, ref cover);
coverMgr.SaveCoverArtToDatabase(ref song, ref cover!);
}
@@ -479,7 +478,7 @@ public class SongManager : BaseManager
{
var updatedSongRecord = oldSongRecord;
var songContext = new SongContext(_connectionString);
var songContext = new SongContext(_connectionString!);
if (!SongRecordChanged(oldSongRecord, newSongRecord))
{
@@ -519,17 +518,17 @@ public class SongManager : BaseManager
newSongRecord = updatedSongRecord;
result.Message = "Successfully updated song";
result.SongTitle = updatedSongRecord.Title;
result.SongTitle = updatedSongRecord.Title!;
}
private void DeleteSongFromDatabase(Song song)
{
_logger.Info("Starting process to delete records related to the song from the database");
var albumMgr = new AlbumManager(_config);
var artistMgr = new ArtistManager(_config);
var genreMgr = new GenreManager(_config);
var sngContext = new SongContext(_connectionString);
var albumMgr = new AlbumManager(_config!);
var artistMgr = new ArtistManager(_config!);
var genreMgr = new GenreManager(_config!);
var sngContext = new SongContext(_connectionString!);
sngContext.Songs.Remove(song);
sngContext.SaveChanges();
artistMgr.DeleteArtistFromDatabase(song);
+18 -18
View File
@@ -11,12 +11,12 @@ public class MetadataRetriever
private static NLog.Logger _logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
private List<string> _supportedAudioFileTypes = new List<string> {"wav", "flac"};
private List<string> _supportedImageFileTypes = new List<string> {"jpeg", "jpg", "png"};
private Song _updatedSong;
private string _message;
private string _title;
private string _artist;
private string _album;
private string _genre;
private Song? _updatedSong;
private string? _message;
private string? _title;
private string? _artist;
private string? _album;
private string? _genre;
private int _year;
private int _duration;
#endregion
@@ -197,7 +197,7 @@ public class MetadataRetriever
_logger.Error(msg, "An error occurred in MetadataRetriever");
}
return null;
return [];
}
@@ -263,43 +263,43 @@ public class MetadataRetriever
switch (key.ToLower())
{
case "title":
_updatedSong.Title = title;
_updatedSong!.Title = title;
fileTag.Tag.Title = title;
break;
case "artists":
_updatedSong.Artist = artist;
_updatedSong!.Artist = artist;
fileTag.Tag.Performers = new []{artist};
break;
case "album":
_updatedSong.AlbumTitle = album;
_updatedSong!.AlbumTitle = album;
fileTag.Tag.Album = album;
break;
case "genre":
_updatedSong.Genre = genre;
_updatedSong!.Genre = genre;
fileTag.Tag.Genres = new []{genre};
break;
case "year":
_updatedSong.Year = year;
fileTag.Tag.Year = (uint)year;
_updatedSong!.Year = year;
fileTag.Tag.Year = (uint)year!;
break;
case "albumartist":
_updatedSong.AlbumArtist = albumArtist;
_updatedSong!.AlbumArtist = albumArtist;
fileTag.Tag.AlbumArtists = new []{albumArtist};
break;
case "track":
_updatedSong.Track = track;
_updatedSong!.Track = track;
fileTag.Tag.Track = (uint)(track);
break;
case "trackcount":
_updatedSong.TrackCount = trackCount;
_updatedSong!.TrackCount = trackCount;
fileTag.Tag.TrackCount = (uint)(trackCount);
break;
case "disc":
_updatedSong.Disc = disc;
_updatedSong!.Disc = disc;
fileTag.Tag.Disc = (uint)(disc);
break;
case "disccount":
_updatedSong.DiscCount = discCount;
_updatedSong!.DiscCount = discCount;
fileTag.Tag.DiscCount = (uint)(discCount);
break;
}
+14 -1
View File
@@ -1,4 +1,4 @@
using Ionic.Zip;
// using Ionic.Zip;
using Icarus.Models;
@@ -63,11 +63,24 @@ public class SongCompression
try
{
using (var fi = new FileStream(songDetails.SongPath(), FileMode.Open))
{
using (var z = new Ionic.Zlib.ZlibStream(fi, Ionic.Zlib.CompressionMode.Compress))
{
using (var tr = new FileStream(tmpZipFilePath, FileMode.CreateNew))
{
z.CopyTo(tr);
}
}
}
/*
var f = new Ionic.Zlib.ZlibStream();
using (ZipFile zip = new ZipFile())
{
zip.AddFile(songDetails.SongPath());
zip.Save(tmpZipFilePath);
}
*/
Console.WriteLine("Successfully compressed");
}
+4 -4
View File
@@ -12,8 +12,8 @@ namespace Icarus.Controllers.V1;
public class ArtistController : BaseController
{
#region Fields
private readonly ILogger<ArtistController> _logger;
private string _connectionString;
private readonly ILogger<ArtistController>? _logger;
private string? _connectionString;
#endregion
@@ -35,7 +35,7 @@ public class ArtistController : BaseController
[HttpGet]
public IActionResult GetArtists()
{
var artistContext = new ArtistContext(_connectionString);
var artistContext = new ArtistContext(_connectionString!);
var artists = artistContext.Artists.ToList();
@@ -50,7 +50,7 @@ public class ArtistController : BaseController
{
Artist artist = new Artist { Id = id };
var artistContext = new ArtistContext(_connectionString);
var artistContext = new ArtistContext(_connectionString!);
if (artistContext.DoesRecordExist(artist))
{
+1 -1
View File
@@ -82,7 +82,7 @@ public class CoverArtController : BaseController
var songMetaData = songContext.RetrieveRecord(new Song { Id = id});
var c = covMgr.GetCoverArt(songMetaData);
var filename = DirectoryManager.GenerateDownloadFilename(10, Constants.FileExtensions.JPG_EXTENSION, songMetaData.Title, randomizeFilename);
var filename = DirectoryManager.GenerateDownloadFilename(10, Constants.FileExtensions.JPG_EXTENSION, songMetaData.Title!, randomizeFilename);
var data = await c.GetData();
+8 -8
View File
@@ -17,8 +17,8 @@ namespace Icarus.Controllers.V1;
public class LoginController : ControllerBase
{
#region Fields
private string _connectionString;
private IConfiguration _config;
private string? _connectionString;
private IConfiguration? _config;
private ILogger<LoginController> _logger;
#endregion
@@ -41,7 +41,7 @@ public class LoginController : ControllerBase
[HttpPost]
public IActionResult Login([FromBody] User user)
{
var context = new UserContext(_connectionString);
var context = new UserContext(_connectionString!);
_logger.LogInformation("Starting process of validating credentials");
@@ -57,10 +57,10 @@ public class LoginController : ControllerBase
{
if (context.Users.FirstOrDefault(usr => usr.Username.Equals(user.Username)) != null)
{
user = context.Users.FirstOrDefault(usr => usr.Username.Equals(user.Username));
user = context.Users.FirstOrDefault(usr => usr.Username.Equals(user.Username))!;
var validatePass = new PasswordEncryption();
var validated = validatePass.VerifyPassword(user, password);
var validated = validatePass.VerifyPassword(user!, password);
if (!validated)
{
loginRes.Message = message;
@@ -71,9 +71,9 @@ public class LoginController : ControllerBase
_logger.LogInformation("Successfully validated user credentials");
TokenManager tk = new TokenManager(_config);
TokenManager tk = new TokenManager(_config!);
loginRes = tk.LoginSymmetric(user);
loginRes = tk.LoginSymmetric(user!);
return Ok(loginRes);
}
@@ -87,7 +87,7 @@ public class LoginController : ControllerBase
catch (Exception ex)
{
_logger.LogError("An error occurred: {0}", ex.Message);
_logger.LogError("Inner Exception: {0}", ex.InnerException.Message);
_logger.LogError("Inner Exception: {0}", ex.InnerException!.Message);
}
return NotFound(loginRes);
+2 -1
View File
@@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<Version>0.1.10</Version>
</PropertyGroup>
@@ -10,9 +11,9 @@
<ItemGroup>
<PackageReference Include="BCrypt.Net-Next" Version="4.0.2" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.4.0" />
<PackageReference Include="DotNetZip" Version="1.15.0" />
<PackageReference Include="EntityFramework" Version="6.4.4" />
<PackageReference Include="File.TypeChecker" Version="4.1.1" />
<PackageReference Include="Iconic.Zlib.Netstandard" Version="1.0.0" />
<PackageReference Include="ID3" Version="0.6.0" />
<PackageReference Include="JWT" Version="10.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
+7 -7
View File
@@ -10,24 +10,24 @@ public class Song
[JsonProperty("id")]
public int Id { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
public string? Title { get; set; }
[JsonProperty("album")]
[Column("Album")]
public string AlbumTitle { get; set; }
public string? AlbumTitle { get; set; }
[JsonProperty("artist")]
public string Artist { get; set; }
public string? Artist { get; set; }
[JsonProperty("album_artist")]
public string AlbumArtist { get; set; }
public string? AlbumArtist { get; set; }
[JsonProperty("year")]
public int? Year { get; set; }
[JsonProperty("genre")]
public string Genre { get; set; }
public string? Genre { get; set; }
[JsonProperty("duration")]
public int Duration { get; set; }
[JsonProperty("filename")]
public string Filename { get; set; }
public string? Filename { get; set; }
[JsonIgnore]
public string SongDirectory { get; set; }
public string? SongDirectory { get; set; }
[JsonProperty("audio_type")]
public string? AudioType { get; set; }
[JsonProperty("track")]
+1 -1
View File
@@ -16,8 +16,8 @@ One can interface with Icarus the music server either by:
* [MySql](https://www.nuget.org/packages/MySql.Data/)
* OpenSSL
* BCrypt.Net-Next
* DotNetZip
* ID3
* Iconic.Zlib.Netstandard
* JWT
* Microsoft.AspNetCore.Authentication.JwtBearer
* Microsoft.AspNetCore.Mvc.NewtonsoftJson