2012-02-05 06:34:36 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Web;
|
2012-11-21 16:14:57 +00:00
|
|
|
|
using NLog;
|
2012-02-05 06:34:36 +00:00
|
|
|
|
using NzbDrone.Services.Service.Repository;
|
2012-02-17 22:04:22 +00:00
|
|
|
|
using Services.PetaPoco;
|
2012-02-05 06:34:36 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Services.Service.Providers
|
|
|
|
|
{
|
|
|
|
|
public class SceneMappingProvider
|
|
|
|
|
{
|
|
|
|
|
private readonly IDatabase _database;
|
|
|
|
|
|
2012-11-21 16:14:57 +00:00
|
|
|
|
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
|
|
|
|
|
|
2012-02-05 06:34:36 +00:00
|
|
|
|
public SceneMappingProvider(IDatabase database)
|
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<SceneMapping> AllLive()
|
|
|
|
|
{
|
|
|
|
|
return _database.Fetch<SceneMapping>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IList<PendingSceneMapping> AllPending()
|
|
|
|
|
{
|
|
|
|
|
return _database.Fetch<PendingSceneMapping>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Insert(SceneMapping sceneMapping)
|
|
|
|
|
{
|
|
|
|
|
_database.Insert(sceneMapping);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Insert(PendingSceneMapping pendingSceneMapping)
|
|
|
|
|
{
|
|
|
|
|
_database.Insert(pendingSceneMapping);
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-27 01:45:07 +00:00
|
|
|
|
public void Update(PendingSceneMapping pendingSceneMapping)
|
2012-02-05 06:34:36 +00:00
|
|
|
|
{
|
2012-02-27 01:45:07 +00:00
|
|
|
|
_database.Update(pendingSceneMapping);
|
2012-02-05 06:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-27 01:45:07 +00:00
|
|
|
|
public PendingSceneMapping GetPending(int mappingId)
|
2012-02-05 06:34:36 +00:00
|
|
|
|
{
|
2012-02-27 01:45:07 +00:00
|
|
|
|
return _database.SingleOrDefault<PendingSceneMapping>("WHERE MappingId = @mappingId", new{ mappingId });
|
2012-02-05 06:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-27 01:45:07 +00:00
|
|
|
|
public void DeleteLive(int mappingId)
|
|
|
|
|
{
|
|
|
|
|
_database.Delete<SceneMapping>(mappingId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DeletePending(int mappingId)
|
|
|
|
|
{
|
|
|
|
|
_database.Delete<PendingSceneMapping>(mappingId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Promote(int mappingId)
|
2012-02-05 06:34:36 +00:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2012-02-27 01:45:07 +00:00
|
|
|
|
var pendingItem = GetPending(mappingId);
|
2012-02-05 06:34:36 +00:00
|
|
|
|
|
|
|
|
|
var mapping = new SceneMapping
|
|
|
|
|
{
|
|
|
|
|
CleanTitle = pendingItem.CleanTitle,
|
|
|
|
|
Id = pendingItem.Id,
|
|
|
|
|
Title = pendingItem.Title
|
|
|
|
|
};
|
|
|
|
|
|
2012-02-27 01:45:07 +00:00
|
|
|
|
Insert(mapping);
|
|
|
|
|
DeletePending(mappingId);
|
2012-02-05 06:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2012-11-21 16:14:57 +00:00
|
|
|
|
logger.WarnException("Unable to promote scene mapping", ex);
|
2012-02-05 06:34:36 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool PromoteAll()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var pendingItems = _database.Fetch<PendingSceneMapping>();
|
|
|
|
|
|
|
|
|
|
foreach (var pendingItem in pendingItems)
|
|
|
|
|
{
|
2012-02-27 01:45:07 +00:00
|
|
|
|
Promote(pendingItem.MappingId);
|
2012-02-05 06:34:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2012-11-21 16:14:57 +00:00
|
|
|
|
logger.WarnException("Unable to promote all scene mappings", ex);
|
2012-02-05 06:34:36 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|