Added error handling for both IBN and providers

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti 2012-08-28 08:39:23 -04:00
parent 42a2835633
commit 97bc7ec378
3 changed files with 33 additions and 15 deletions

View File

@ -121,6 +121,22 @@ namespace MediaBrowser.Controller.IO
[DllImport("kernel32")] [DllImport("kernel32")]
private static extern bool FindClose(IntPtr hFindFile); private static extern bool FindClose(IntPtr hFindFile);
private const char SpaceChar = ' ';
private static char[] InvalidFileNameChars = Path.GetInvalidFileNameChars();
/// <summary>
/// Takes a filename and removes invalid characters
/// </summary>
public static string GetValidFilename(string filename)
{
foreach (char c in InvalidFileNameChars)
{
filename = filename.Replace(c, SpaceChar);
}
return filename;
}
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]

View File

@ -15,6 +15,7 @@ using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Resolvers; using MediaBrowser.Controller.Resolvers;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Progress; using MediaBrowser.Model.Progress;
using MediaBrowser.Common.Logging;
namespace MediaBrowser.Controller namespace MediaBrowser.Controller
{ {
@ -286,7 +287,14 @@ namespace MediaBrowser.Controller
continue; continue;
} }
await provider.FetchAsync(item, args).ConfigureAwait(false); try
{
await provider.FetchAsync(item, args).ConfigureAwait(false);
}
catch (Exception ex)
{
Logger.LogException(ex);
}
} }
} }

View File

@ -204,9 +204,7 @@ namespace MediaBrowser.Controller.Library
/// </summary> /// </summary>
public Task<Person> GetPerson(string name) public Task<Person> GetPerson(string name)
{ {
string path = Path.Combine(Kernel.Instance.ApplicationPaths.PeoplePath, name); return GetImagesByNameItem<Person>(Kernel.Instance.ApplicationPaths.PeoplePath, name);
return GetImagesByNameItem<Person>(path, name);
} }
/// <summary> /// <summary>
@ -214,9 +212,7 @@ namespace MediaBrowser.Controller.Library
/// </summary> /// </summary>
public Task<Studio> GetStudio(string name) public Task<Studio> GetStudio(string name)
{ {
string path = Path.Combine(Kernel.Instance.ApplicationPaths.StudioPath, name); return GetImagesByNameItem<Studio>(Kernel.Instance.ApplicationPaths.StudioPath, name);
return GetImagesByNameItem<Studio>(path, name);
} }
/// <summary> /// <summary>
@ -224,9 +220,7 @@ namespace MediaBrowser.Controller.Library
/// </summary> /// </summary>
public Task<Genre> GetGenre(string name) public Task<Genre> GetGenre(string name)
{ {
string path = Path.Combine(Kernel.Instance.ApplicationPaths.GenrePath, name); return GetImagesByNameItem<Genre>(Kernel.Instance.ApplicationPaths.GenrePath, name);
return GetImagesByNameItem<Genre>(path, name);
} }
/// <summary> /// <summary>
@ -234,12 +228,10 @@ namespace MediaBrowser.Controller.Library
/// </summary> /// </summary>
public Task<Year> GetYear(int value) public Task<Year> GetYear(int value)
{ {
string path = Path.Combine(Kernel.Instance.ApplicationPaths.YearPath, value.ToString()); return GetImagesByNameItem<Year>(Kernel.Instance.ApplicationPaths.YearPath, value.ToString());
return GetImagesByNameItem<Year>(path, value.ToString());
} }
private ConcurrentDictionary<string, object> ImagesByNameItemCache = new ConcurrentDictionary<string, object>(); private ConcurrentDictionary<string, object> ImagesByNameItemCache = new ConcurrentDictionary<string, object>(StringComparer.OrdinalIgnoreCase);
/// <summary> /// <summary>
/// Generically retrieves an IBN item /// Generically retrieves an IBN item
@ -247,7 +239,9 @@ namespace MediaBrowser.Controller.Library
private Task<T> GetImagesByNameItem<T>(string path, string name) private Task<T> GetImagesByNameItem<T>(string path, string name)
where T : BaseEntity, new() where T : BaseEntity, new()
{ {
string key = path.ToLower(); name = FileData.GetValidFilename(name);
string key = Path.Combine(path, name);
// Look for it in the cache, if it's not there, create it // Look for it in the cache, if it's not there, create it
if (!ImagesByNameItemCache.ContainsKey(key)) if (!ImagesByNameItemCache.ContainsKey(key))