Skip to content

Commit

Permalink
Fix a bunch of possible errors
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Mar 19, 2024
1 parent d1807ea commit fbe0353
Show file tree
Hide file tree
Showing 25 changed files with 54 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Shoko.Server/Scheduling/Delegates/SQLiteDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ public virtual async Task<Dictionary<Type, int>> SelectJobTypeCounts(ConnectionA
}
}

await using var rs = await cmd.ExecuteReaderAsync(System.Data.CommandBehavior.SequentialAccess, cancellationToken).ConfigureAwait(false);
await using var rs = await cmd.ExecuteReaderAsync(cancellationToken);

var results = new List<(IJobDetail, bool)>();
while (await rs.ReadAsync(cancellationToken).ConfigureAwait(false))
Expand All @@ -435,7 +435,7 @@ public virtual async Task<Dictionary<Type, int>> SelectJobTypeCounts(ConnectionA
var jobType = loadHelper.LoadType(rs.GetString(ColumnJobClass)!)!;
var isDurable = GetBooleanFromDbValue(rs[ColumnIsDurable]);
var requestsRecovery = GetBooleanFromDbValue(rs[ColumnRequestsRecovery]);
var map = await ReadMapFromReader(rs, 6).ConfigureAwait(false);
var map = await ReadMapFromReader(rs, 6);
var jobDataMap = map != null ? new JobDataMap(map) : null;
var blocked = GetBooleanFromDbValue(rs[Blocked]);

Expand Down
4 changes: 2 additions & 2 deletions Shoko.Server/Scheduling/Delegates/SqlServerDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ public virtual async Task<Dictionary<Type, int>> SelectJobTypeCounts(ConnectionA
}
}

await using var rs = await cmd.ExecuteReaderAsync(System.Data.CommandBehavior.SequentialAccess, cancellationToken).ConfigureAwait(false);
await using var rs = await cmd.ExecuteReaderAsync(cancellationToken);

var results = new List<(IJobDetail, bool)>();
while (await rs.ReadAsync(cancellationToken).ConfigureAwait(false))
Expand All @@ -434,7 +434,7 @@ public virtual async Task<Dictionary<Type, int>> SelectJobTypeCounts(ConnectionA
var jobType = loadHelper.LoadType(rs.GetString(ColumnJobClass)!)!;
var isDurable = GetBooleanFromDbValue(rs[ColumnIsDurable]);
var requestsRecovery = GetBooleanFromDbValue(rs[ColumnRequestsRecovery]);
var map = await ReadMapFromReader(rs, 6).ConfigureAwait(false);
var map = await ReadMapFromReader(rs, 6);
var jobDataMap = map != null ? new JobDataMap(map) : null;
var blocked = GetBooleanFromDbValue(rs[Blocked]);

Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/AniDB/AddFileToMyListJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void PostInit()
public override Dictionary<string, object> Details => new()
{
{
"File Path", Utils.GetDistinctPath(_videoLocal.GetBestVideoLocalPlace()?.FullServerPath)
"File Path", Utils.GetDistinctPath(_videoLocal?.GetBestVideoLocalPlace()?.FullServerPath) ?? Hash
}
};

Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/AniDB/GetAniDBAnimeJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class GetAniDBAnimeJob : BaseJob<SVR_AniDB_Anime>
public override void PostInit()
{
// We have the title helper. May as well use it to provide better info for the user
_animeName = RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID)?.PreferredTitle ?? _titleHelper.SearchAnimeID(AnimeID)?.PreferredTitle;
_animeName = RepoFactory.AniDB_Anime?.GetByAnimeID(AnimeID)?.PreferredTitle ?? _titleHelper.SearchAnimeID(AnimeID)?.PreferredTitle;
}

public override string TypeName => "Get AniDB Anime Data";
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/AniDB/GetAniDBFileJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override void PostInit()
public override Dictionary<string, object> Details => new()
{
{
"Filename", _vlocal.FileName
"Filename", _vlocal?.FileName ?? VideoLocalID.ToString()
}
};

Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/AniDB/GetAniDBImagesJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class GetAniDBImagesJob : BaseJob

public override void PostInit()
{
_anime = RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID);
_anime = RepoFactory.AniDB_Anime?.GetByAnimeID(AnimeID);
_title = _anime?.PreferredTitle ?? _titleHelper.SearchAnimeID(AnimeID)?.PreferredTitle;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class GetAniDBReleaseGroupStatusJob : BaseJob

public override void PostInit()
{
_anime = RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID);
_anime = RepoFactory.AniDB_Anime?.GetByAnimeID(AnimeID);
_animeName = _anime?.PreferredTitle ?? _titleHelper.SearchAnimeID(AnimeID)?.PreferredTitle;
}

Expand Down
11 changes: 8 additions & 3 deletions Shoko.Server/Scheduling/Jobs/AniDB/UpdateMyListFileStatusJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,21 @@ public class UpdateMyListFileStatusJob : BaseJob

public override void PostInit()
{
FullFileName = RepoFactory.FileNameHash.GetByHash(Hash).FirstOrDefault()?.FileName;
FullFileName = RepoFactory.FileNameHash?.GetByHash(Hash).FirstOrDefault()?.FileName;
}

public override string Title => "Updating AniDB MyList Status for File";
public override Dictionary<string, object> Details => new()
public override Dictionary<string, object> Details => FullFileName != null ? new()
{
{
"Filename", FullFileName
}
};
} : new()
{
{
"Hash", Hash
}
} ;

public override Task Process()
{
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/AniDB/VoteAniDBAnimeJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class VoteAniDBAnimeJob : BaseJob

public override void PostInit()
{
_animeName = RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID)?.PreferredTitle ?? _titleHelper.SearchAnimeID(AnimeID)?.PreferredTitle ?? AnimeID.ToString();
_animeName = RepoFactory.AniDB_Anime?.GetByAnimeID(AnimeID)?.PreferredTitle ?? _titleHelper.SearchAnimeID(AnimeID)?.PreferredTitle ?? AnimeID.ToString();
}

public override string TypeName => "Rate Anime";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class DeleteImportFolderJob : BaseJob
public override Dictionary<string, object> Details => new()
{
{
"Import Folder", RepoFactory.ImportFolder.GetByID(ImportFolderID)?.ImportFolderName ?? ImportFolderID.ToString()
"Import Folder", RepoFactory.ImportFolder?.GetByID(ImportFolderID)?.ImportFolderName ?? ImportFolderID.ToString()
}
};

Expand Down
24 changes: 11 additions & 13 deletions Shoko.Server/Scheduling/Jobs/Shoko/ManualLinkJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,18 @@ public class ManualLinkJob : BaseJob

public override string TypeName => "Manually Link File";
public override string Title => "Manually Linking Episode";
public override Dictionary<string, object> Details
{
get
public override Dictionary<string, object> Details => _episode != null ?
new()
{
var result = new Dictionary<string, object>
{
{ "File Path", Utils.GetDistinctPath(_vlocal.GetBestVideoLocalPlace()?.FullServerPath) },
{ "Anime", RepoFactory.AniDB_Anime.GetByAnimeID(_episode.AniDB_Episode.AnimeID).AnimeID },
{ "Episode Type", _episode.AniDB_Episode.EpisodeType.ToString() },
{ "Episode Number", _episode.AniDB_Episode.EpisodeNumber }
};
return result;
}
}
{ "File Path", Utils.GetDistinctPath(_vlocal.GetBestVideoLocalPlace()?.FullServerPath) },
{ "Anime", RepoFactory.AniDB_Anime.GetByAnimeID(_episode.AniDB_Episode.AnimeID)?.PreferredTitle },
{ "Episode Type", _episode.AniDB_Episode.EpisodeType.ToString() },
{ "Episode Number", _episode.AniDB_Episode.EpisodeNumber }
} : new()
{
{ "VideoLocalID", VideoLocalID },
{ "EpisodeID", EpisodeID },
};

public override void PostInit()
{
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/Shoko/MediaInfoJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override void PostInit()
}

public override string Title => "Reading MediaInfo for File";
public override Dictionary<string, object> Details => new() { { "File Path", _fileName } };
public override Dictionary<string, object> Details => new() { { "File Path", _fileName ?? VideoLocalID.ToString() } };

public override Task Process()
{
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/Shoko/ProcessFileJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override void PostInit()
}

public override string Title => "Get XRefs for File";
public override Dictionary<string, object> Details => new() { { "File Path", _fileName } };
public override Dictionary<string, object> Details => new() { { "File Path", _fileName ?? VideoLocalID.ToString() } };

public override async Task Process()
{
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/Shoko/RenameMoveFileJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override void PostInit()
_fileName = Utils.GetDistinctPath(_vlocal?.GetBestVideoLocalPlace()?.FullServerPath);
}
public override string Title => "Renaming/Moving File";
public override Dictionary<string, object> Details => new() { { "File Path", _fileName } };
public override Dictionary<string, object> Details => new() { { "File Path", _fileName ?? VideoLocalID.ToString() } };


public override Task Process()
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/Shoko/ScanFolderJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class ScanFolderJob : BaseJob
public int ImportFolderID { get; set; }
public override string TypeName => "Scan Folder";
public override string Title => "Scanning Import Folder";
public override Dictionary<string, object> Details => new() { { "Import Folder", RepoFactory.ImportFolder.GetByID(ImportFolderID)?.ImportFolderName ?? ImportFolderID.ToString() } };
public override Dictionary<string, object> Details => new() { { "Import Folder", RepoFactory.ImportFolder?.GetByID(ImportFolderID)?.ImportFolderName ?? ImportFolderID.ToString() } };

public override async Task Process()
{
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/TMDB/SearchTMDBSeriesJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SearchTMDBSeriesJob : BaseJob

public override void PostInit()
{
_animeTitle = RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID)?.PreferredTitle ?? AnimeID.ToString();
_animeTitle = RepoFactory.AniDB_Anime?.GetByAnimeID(AnimeID)?.PreferredTitle ?? AnimeID.ToString();
}

public override string TypeName => "Search TMDB Series";
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/Trakt/SearchTraktSeriesJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class SearchTraktSeriesJob : BaseJob

public override string TypeName => "Get Trakt Series";
public override string Title => "Searching for Trakt Series";
public override Dictionary<string, object> Details => new() { { "Anime", RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID)?.PreferredTitle ?? AnimeID.ToString() } };
public override Dictionary<string, object> Details => new() { { "Anime", RepoFactory.AniDB_Anime?.GetByAnimeID(AnimeID)?.PreferredTitle ?? AnimeID.ToString() } };

public override Task Process()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@ public override Dictionary<string, object> Details
{
get
{
var episode = RepoFactory.AnimeEpisode.GetByID(AnimeEpisodeID).AniDB_Episode;
return new()
var episode = RepoFactory.AnimeEpisode?.GetByID(AnimeEpisodeID)?.AniDB_Episode;
return episode == null ? new()
{
{ "Anime", RepoFactory.AniDB_Anime.GetByAnimeID(episode.AnimeID) },
{ "EpisodeID", AnimeEpisodeID }
} : new()
{
{ "Anime", RepoFactory.AniDB_Anime.GetByAnimeID(episode.AnimeID)?.PreferredTitle },
{ "Episode Type", ((EpisodeType)episode.EpisodeType).ToString() },
{ "Episode Number", episode.EpisodeNumber }
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SyncTraktCollectionSeriesJob : BaseJob

public override void PostInit()
{
_seriesName = RepoFactory.AnimeSeries.GetByID(AnimeSeriesID)?.GetSeriesName() ?? AnimeSeriesID.ToString();
_seriesName = RepoFactory.AnimeSeries?.GetByID(AnimeSeriesID)?.GetSeriesName() ?? AnimeSeriesID.ToString();
}

public override string Title => "Syncing Series to Trakt Collection";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ public override Dictionary<string, object> Details
{
get
{
var episode = RepoFactory.AnimeEpisode.GetByID(AnimeEpisodeID).AniDB_Episode;
return new()
var episode = RepoFactory.AnimeEpisode?.GetByID(AnimeEpisodeID)?.AniDB_Episode;
return episode == null ? new()
{
{ "EpisodeID", AnimeEpisodeID }
} : new()
{
{ "Anime", RepoFactory.AniDB_Anime.GetByAnimeID(episode.AnimeID) },
{ "Episode Type", ((EpisodeType)episode.EpisodeType).ToString() },
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/TvDB/DownloadTvDBImageJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class DownloadTvDBImageJob : BaseJob, IImageDownloadJob

public override void PostInit()
{
Anime = RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID)?.PreferredTitle ?? AnimeID.ToString();
Anime = RepoFactory.AniDB_Anime?.GetByAnimeID(AnimeID)?.PreferredTitle ?? AnimeID.ToString();
}

public override string TypeName => "Download TvDB Image";
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/TvDB/GetTvDBImagesJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class GetTvDBImagesJob : BaseJob
public override Dictionary<string, object> Details => new()
{
{
"Series", RepoFactory.TvDB_Series.GetByTvDBID(TvDBSeriesID)?.SeriesName ?? TvDBSeriesID.ToString()
"Series", RepoFactory.TvDB_Series?.GetByTvDBID(TvDBSeriesID)?.SeriesName ?? TvDBSeriesID.ToString()
}
};

Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/TvDB/GetTvDBSeriesJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class GetTvDBSeriesJob : BaseJob<TvDB_Series>
public override Dictionary<string, object> Details => new()
{
{
"Series", RepoFactory.TvDB_Series.GetByTvDBID(TvDBSeriesID)?.SeriesName ?? TvDBSeriesID.ToString()
"Series", RepoFactory.TvDB_Series?.GetByTvDBID(TvDBSeriesID)?.SeriesName ?? TvDBSeriesID.ToString()
}
};

Expand Down
4 changes: 2 additions & 2 deletions Shoko.Server/Scheduling/Jobs/TvDB/LinkTvDBSeriesJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public class LinkTvDBSeriesJob : BaseJob
public override string Title => "Linking TvDB Series";
public override Dictionary<string, object> Details => new()
{
{ "Anime", RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID)?.PreferredTitle ?? AnimeID.ToString() },
{ "TvDB Series", RepoFactory.TvDB_Series.GetByTvDBID(TvDBID)?.SeriesName ?? TvDBID.ToString() }
{ "Anime", RepoFactory.AniDB_Anime?.GetByAnimeID(AnimeID)?.PreferredTitle ?? AnimeID.ToString() },
{ "TvDB Series", RepoFactory.TvDB_Series?.GetByTvDBID(TvDBID)?.SeriesName ?? TvDBID.ToString() }
};

public override async Task Process()
Expand Down
2 changes: 1 addition & 1 deletion Shoko.Server/Scheduling/Jobs/TvDB/SearchTvDBSeriesJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class SearchTvDBSeriesJob : BaseJob

public override void PostInit()
{
_title = RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID)?.PreferredTitle ?? AnimeID.ToString();
_title = RepoFactory.AniDB_Anime?.GetByAnimeID(AnimeID)?.PreferredTitle ?? AnimeID.ToString();
}

public override string Title => "Searching for TvDB Series";
Expand Down

0 comments on commit fbe0353

Please sign in to comment.