Skip to content
Permalink
Browse files

Make the Search More Fail Safe

  • Loading branch information
da3dsoul committed Nov 9, 2019
1 parent e193c49 commit 1e38174b0dd1109b80738a7e102f7f042e94417d
Showing with 30 additions and 37 deletions.
  1. +30 −37 Shoko.Desktop/UserControls/UnrecognisedVideos.xaml.cs
@@ -10,10 +10,12 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using Nancy.Rest.Client.Exceptions;
using NLog;
using Shoko.Commons.Extensions;
using Shoko.Commons.Utils;
@@ -1051,9 +1053,9 @@ private void SearchAnime(CancellationTokenSource token, object argument)
}
catch (Exception e)
{
EnableSeriesControls();
runningTask = null;
logger.Error(e);
EnableSeriesControls();
}
}

@@ -1075,19 +1077,7 @@ private void SearchAnime(CancellationToken token, object argument, List<VM_Anime

if (vidLocals == null || vidLocals.Count == 0)
{
Series.Clear();
foreach (VM_AnimeSeries_User anime in VM_ShokoServer.Instance.ShokoServices
.GetAllSeries(VM_ShokoServer.Instance.CurrentUser.JMMUserID).CastList<VM_AnimeSeries_User>())
{
if (token.IsCancellationRequested)
{
Series.Clear();
tempAnime.Clear();
return;
}
tempAnime.Add(anime);
Series.Add(anime);
}
DisplayAllSeries(token, tempAnime);
}
else
{
@@ -1111,37 +1101,40 @@ private void SearchAnime(CancellationToken token, object argument, List<VM_Anime
{
return;
}
foreach (VM_AnimeSeries_User anime in VM_ShokoServer.Instance.ShokoServices
.SearchSeriesWithFilename(VM_ShokoServer.Instance.CurrentUser.JMMUserID,
searchString).CastList<VM_AnimeSeries_User>())

try
{
var searchResults = VM_ShokoServer.Instance.ShokoServices
.SearchSeriesWithFilename(VM_ShokoServer.Instance.CurrentUser.JMMUserID,
searchString).CastList<VM_AnimeSeries_User>();
if (token.IsCancellationRequested) return;
tempAnime.AddRange(searchResults);
}
catch (Exception e)
{
if (token.IsCancellationRequested)
return;
tempAnime.Add(anime);
logger.Error($"An error occurred while searching for a series in the Unrecognized Utility: {e}");
DisplayAllSeries(token, tempAnime);
}
}

if (tempAnime.Count > 0) return;
if (token.IsCancellationRequested)
{
return;
}

if (Series.Count == 0)
Series.AddRange(VM_ShokoServer.Instance.ShokoServices
.GetAllSeries(VM_ShokoServer.Instance.CurrentUser.JMMUserID).CastList<VM_AnimeSeries_User>());

if (token.IsCancellationRequested) return;

foreach (VM_AnimeSeries_User anime in Series)
{
if (token.IsCancellationRequested)
{
return;
}
tempAnime.Add(anime);
}
DisplayAllSeries(token, tempAnime);
}

private void DisplayAllSeries(CancellationToken token, List<VM_AnimeSeries_User> tempAnime)
{
lock(Series) Series.Clear();
var series = VM_ShokoServer.Instance.ShokoServices
.GetAllSeries(VM_ShokoServer.Instance.CurrentUser.JMMUserID).CastList<VM_AnimeSeries_User>();
if (token.IsCancellationRequested) return;

lock(Series) Series.AddRange(series);
if (token.IsCancellationRequested) return;
tempAnime.AddRange(series);
}

private bool SeriesSearchFilter(object obj)
{
VM_AnimeSeries_User servm = obj as VM_AnimeSeries_User;

0 comments on commit 1e38174

Please sign in to comment.
You can’t perform that action at this time.