Moved source code under src folder - massive change

This commit is contained in:
Mark McDowall
2013-10-02 18:01:32 -07:00
parent 2fc8123d6b
commit 5bf0e197ec
1499 changed files with 1054 additions and 1444 deletions
@@ -0,0 +1,19 @@
using Newtonsoft.Json;
using NzbDrone.Core.Datastore;
namespace NzbDrone.Core.DataAugmentation.Scene
{
public class SceneMapping : ModelBase
{
[JsonProperty("title")]
public string ParseTerm { get; set; }
[JsonProperty("searchTitle")]
public string SearchTerm { get; set; }
public int TvdbId { get; set; }
[JsonProperty("season")]
public int SeasonNumber { get; set; }
}
}
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using NzbDrone.Common;
using NzbDrone.Common.Serializer;
namespace NzbDrone.Core.DataAugmentation.Scene
{
public interface ISceneMappingProxy
{
List<SceneMapping> Fetch();
}
public class SceneMappingProxy : ISceneMappingProxy
{
private readonly IHttpProvider _httpProvider;
public SceneMappingProxy(IHttpProvider httpProvider)
{
_httpProvider = httpProvider;
}
public List<SceneMapping> Fetch()
{
var mappingsJson = _httpProvider.DownloadString(Services.RootUrl + "/v1/SceneMapping");
return Json.Deserialize<List<SceneMapping>>(mappingsJson);
}
}
}
@@ -0,0 +1,20 @@
using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events;
namespace NzbDrone.Core.DataAugmentation.Scene
{
public interface ISceneMappingRepository : IBasicRepository<SceneMapping>
{
}
public class SceneMappingRepository : BasicRepository<SceneMapping>, ISceneMappingRepository
{
public SceneMappingRepository(IDatabase database, IEventAggregator eventAggregator)
: base(database, eventAggregator)
{
}
}
}
@@ -0,0 +1,114 @@
using System;
using System.Linq;
using NLog;
using NzbDrone.Common.Cache;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Commands;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Parser;
namespace NzbDrone.Core.DataAugmentation.Scene
{
public interface ISceneMappingService
{
string GetSceneName(int tvdbId);
Nullable<int> GetTvDbId(string cleanName);
}
public class SceneMappingService : ISceneMappingService,
IHandleAsync<ApplicationStartedEvent>,
IExecute<UpdateSceneMappingCommand>
{
private readonly ISceneMappingRepository _repository;
private readonly ISceneMappingProxy _sceneMappingProxy;
private readonly Logger _logger;
private readonly ICached<SceneMapping> _getSceneNameCache;
private readonly ICached<SceneMapping> _gettvdbIdCache;
public SceneMappingService(ISceneMappingRepository repository, ISceneMappingProxy sceneMappingProxy, ICacheManger cacheManger, Logger logger)
{
_repository = repository;
_sceneMappingProxy = sceneMappingProxy;
_getSceneNameCache = cacheManger.GetCache<SceneMapping>(GetType(), "scene_name");
_gettvdbIdCache = cacheManger.GetCache<SceneMapping>(GetType(), "tvdb_id");
_logger = logger;
}
public string GetSceneName(int tvdbId)
{
var mapping = _getSceneNameCache.Find(tvdbId.ToString());
if (mapping == null) return null;
return mapping.SearchTerm;
}
public Nullable<Int32> GetTvDbId(string cleanName)
{
var mapping = _gettvdbIdCache.Find(cleanName.CleanSeriesTitle());
if (mapping == null)
return null;
return mapping.TvdbId;
}
private void UpdateMappings()
{
_logger.Info("Updating Scene mapping");
try
{
var mappings = _sceneMappingProxy.Fetch();
if (mappings.Any())
{
_repository.Purge();
foreach (var sceneMapping in mappings)
{
sceneMapping.ParseTerm = sceneMapping.ParseTerm.CleanSeriesTitle();
}
_repository.InsertMany(mappings);
}
else
{
_logger.Warn("Received empty list of mapping. will not update.");
}
}
catch (Exception ex)
{
_logger.ErrorException("Failed to Update Scene Mappings:", ex);
}
RefreshCache();
}
private void RefreshCache()
{
var mappings = _repository.All();
_gettvdbIdCache.Clear();
_getSceneNameCache.Clear();
foreach (var sceneMapping in mappings)
{
_getSceneNameCache.Set(sceneMapping.TvdbId.ToString(), sceneMapping);
_gettvdbIdCache.Set(sceneMapping.ParseTerm.CleanSeriesTitle(), sceneMapping);
}
}
public void HandleAsync(ApplicationStartedEvent message)
{
UpdateMappings();
}
public void Execute(UpdateSceneMappingCommand message)
{
UpdateMappings();
}
}
}
@@ -0,0 +1,9 @@
using NzbDrone.Core.Messaging.Commands;
namespace NzbDrone.Core.DataAugmentation.Scene
{
public class UpdateSceneMappingCommand : Command
{
}
}