mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
Fixed up Eloquera integration, working much better now.
This commit is contained in:
parent
8c99cca207
commit
ace7910f2a
@ -18,7 +18,7 @@ public RootDirModule(RootFolderService rootFolderService)
|
||||
|
||||
Get["/"] = x => GetRootFolders();
|
||||
Post["/"] = x => AddRootFolder();
|
||||
Delete["/{id}"] = x => DeleteRootFolder((int)x.id);
|
||||
Delete["/{id}"] = x => DeleteRootFolder((long)x.id);
|
||||
}
|
||||
|
||||
private Response AddRootFolder()
|
||||
@ -32,7 +32,7 @@ private Response GetRootFolders()
|
||||
return _rootFolderService.All().AsResponse();
|
||||
}
|
||||
|
||||
private Response DeleteRootFolder(int folderId)
|
||||
private Response DeleteRootFolder(long folderId)
|
||||
{
|
||||
_rootFolderService.Remove(folderId);
|
||||
return new Response { StatusCode = HttpStatusCode.OK };
|
||||
|
@ -26,6 +26,12 @@ private Response AddSeries()
|
||||
{
|
||||
var request = Request.Body.FromJson<Core.Repository.Series>();
|
||||
|
||||
//Todo: Alert the user if this series already exists
|
||||
//Todo: We need to create the folder if the user is adding a new series
|
||||
//(we can just create the folder and it won't blow up if it already exists)
|
||||
//We also need to remove any special characters from the filename before attempting to create it
|
||||
|
||||
|
||||
_seriesProvider.AddSeries("", request.Path, request.SeriesId, request.QualityProfileId, null);
|
||||
_jobProvider.QueueJob(typeof(ImportNewSeriesJob));
|
||||
|
||||
|
@ -26,6 +26,7 @@ public void SetUp()
|
||||
|
||||
testEpisode = Builder<Episode>
|
||||
.CreateNew()
|
||||
.With(e => e.Id = 0)
|
||||
.Build();
|
||||
|
||||
|
||||
@ -35,9 +36,7 @@ public void SetUp()
|
||||
public void should_be_able_to_write_to_database()
|
||||
{
|
||||
Db.Insert(testSeries);
|
||||
|
||||
Db.AsQueryable<Series>().Should().HaveCount(1);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -66,7 +65,10 @@ public void should_store_nested_objects()
|
||||
[Test]
|
||||
public void should_update_nested_objects()
|
||||
{
|
||||
testEpisode.Series = Builder<Series>.CreateNew().Build();
|
||||
testEpisode.Series = Builder<Series>
|
||||
.CreateNew()
|
||||
.With(s => s.Id = 0)
|
||||
.Build();
|
||||
|
||||
Db.Insert(testEpisode);
|
||||
|
||||
@ -82,14 +84,14 @@ public void should_update_nested_objects()
|
||||
[Test]
|
||||
public void new_objects_should_get_id()
|
||||
{
|
||||
Db.Insert(testSeries);
|
||||
testSeries.Id = Db.InsertAndGetId(testSeries);
|
||||
testSeries.Id.Should().NotBe(0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_have_id_when_returned_from_database()
|
||||
{
|
||||
Db.Insert(testSeries);
|
||||
testSeries.Id = Db.InsertAndGetId(testSeries);
|
||||
var item = Db.AsQueryable<Series>();
|
||||
|
||||
item.Should().HaveCount(1);
|
||||
@ -100,7 +102,7 @@ public void should_have_id_when_returned_from_database()
|
||||
[Test]
|
||||
public void should_be_able_to_find_object_by_id()
|
||||
{
|
||||
Db.Insert(testSeries);
|
||||
testSeries.Id = Db.InsertAndGetId(testSeries);
|
||||
var item = Db.AsQueryable<Series>().Single(c => c.Id == testSeries.Id);
|
||||
|
||||
item.Id.Should().NotBe(0);
|
||||
|
@ -9,6 +9,6 @@ namespace NzbDrone.Core.Datastore
|
||||
public abstract class BaseRepositoryModel
|
||||
{
|
||||
[ID]
|
||||
public int Id;
|
||||
public long Id;
|
||||
}
|
||||
}
|
||||
|
@ -8,9 +8,9 @@ namespace NzbDrone.Core.Datastore
|
||||
public interface IBasicRepository<TModel>
|
||||
{
|
||||
List<TModel> All();
|
||||
TModel Get(int rootFolderId);
|
||||
TModel Get(long rootFolderId);
|
||||
TModel Add(TModel rootFolder);
|
||||
void Delete(int rootFolderId);
|
||||
void Delete(long rootFolderId);
|
||||
}
|
||||
|
||||
public abstract class BasicRepository<TModel> : IBasicRepository<TModel> where TModel : BaseRepositoryModel, new()
|
||||
@ -27,7 +27,7 @@ public List<TModel> All()
|
||||
return EloqueraDb.AsQueryable<TModel>().ToList();
|
||||
}
|
||||
|
||||
public TModel Get(int id)
|
||||
public TModel Get(long id)
|
||||
{
|
||||
return EloqueraDb.AsQueryable<TModel>().Single(c => c.Id == id);
|
||||
}
|
||||
@ -37,7 +37,7 @@ public TModel Add(TModel model)
|
||||
return EloqueraDb.Insert(model);
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
public void Delete(long id)
|
||||
{
|
||||
var itemToDelete = Get(id);
|
||||
EloqueraDb.Delete(itemToDelete);
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Eloquera.Client;
|
||||
@ -19,13 +20,18 @@ public IEnumerable<T> AsQueryable<T>()
|
||||
return _db.Query<T>();
|
||||
}
|
||||
|
||||
|
||||
public T Insert<T>(T obj)
|
||||
{
|
||||
//Todo: need to verify that this is properly setting the ID of T
|
||||
_db.Store(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
public long InsertAndGetId<T>(T obj)
|
||||
{
|
||||
return _db.Store(obj);
|
||||
}
|
||||
|
||||
public IList<T> InsertMany<T>(IEnumerable<T> objects)
|
||||
{
|
||||
return DoMany(objects, Insert);
|
||||
@ -42,7 +48,6 @@ public IList<T> UpdateMany<T>(IEnumerable<T> objects)
|
||||
return DoMany(objects, Update);
|
||||
}
|
||||
|
||||
|
||||
public void Delete<T>(T obj) where T : new()
|
||||
{
|
||||
_db.Delete(obj);
|
||||
|
@ -3,6 +3,7 @@
|
||||
using System.Linq;
|
||||
using Eloquera.Client;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Core.Repository;
|
||||
using NzbDrone.Core.RootFolders;
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
@ -39,6 +40,7 @@ public EloqueraDb Create(string dbPath = null)
|
||||
private EloqueraDb InternalCreate(string connectionString, string databaseName)
|
||||
{
|
||||
var db = new DB(connectionString);
|
||||
|
||||
try
|
||||
{
|
||||
db.OpenDatabase(databaseName);
|
||||
@ -49,6 +51,9 @@ private EloqueraDb InternalCreate(string connectionString, string databaseName)
|
||||
db.OpenDatabase(databaseName);
|
||||
}
|
||||
|
||||
//This seemse to cause Invalid Cast Exceptions... WTF
|
||||
//db.RefreshMode = ObjectRefreshMode.AlwaysReturnUpdatedValues;
|
||||
|
||||
RegisterTypeRules();
|
||||
RegisterTypes(db);
|
||||
|
||||
@ -59,13 +64,20 @@ private void RegisterTypeRules()
|
||||
{
|
||||
RootFolder rootFolder = null;
|
||||
DB.TypeRules
|
||||
//.SetIDField(() => rootFolder.Id)
|
||||
.IgnoreProperty(() => rootFolder.FreeSpace)
|
||||
.IgnoreProperty(() => rootFolder.UnmappedFolders);
|
||||
|
||||
//Series series = null;
|
||||
//DB.TypeRules
|
||||
// .SetIDField(() => series.Id);
|
||||
}
|
||||
|
||||
private void RegisterTypes(DB db)
|
||||
{
|
||||
db.RegisterType(typeof(RootFolder));
|
||||
db.RegisterType(typeof(Series));
|
||||
db.RegisterType(typeof(Episode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using Eloquera.Client;
|
||||
using NzbDrone.Core.Model;
|
||||
using PetaPoco;
|
||||
|
||||
@ -8,6 +9,9 @@ namespace NzbDrone.Core.Repository
|
||||
[PrimaryKey("EpisodeId", autoIncrement = true)]
|
||||
public class Episode
|
||||
{
|
||||
[ID]
|
||||
public long Id;
|
||||
|
||||
public int EpisodeId { get; set; }
|
||||
|
||||
public int? TvDbEpisodeId { get; set; }
|
||||
|
@ -10,7 +10,6 @@ namespace NzbDrone.Core.Repository
|
||||
[PrimaryKey("SeriesId", autoIncrement = false)]
|
||||
public class Series
|
||||
{
|
||||
|
||||
[ID]
|
||||
public long Id;
|
||||
|
||||
|
@ -11,14 +11,19 @@ public interface IRootFolderRepository : IBasicRepository<RootFolder>
|
||||
|
||||
}
|
||||
|
||||
|
||||
//This way we only need to implement none_custom methods for repos, like custom queries etc... rest is done automagically.
|
||||
public class RootFolderRepository : BasicRepository<RootFolder>, IRootFolderRepository
|
||||
{
|
||||
public RootFolderRepository(EloqueraDb eloqueraDb)
|
||||
: base(eloqueraDb)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public RootFolder Add(RootFolder rootFolder)
|
||||
{
|
||||
rootFolder.Id = EloqueraDb.InsertAndGetId(rootFolder);
|
||||
return rootFolder;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public interface IRootFolderService
|
||||
{
|
||||
List<RootFolder> All();
|
||||
RootFolder Add(RootFolder rootDir);
|
||||
void Remove(int rootDirId);
|
||||
void Remove(long rootDirId);
|
||||
List<String> GetUnmappedFolders(string path);
|
||||
Dictionary<string, ulong> FreeSpaceOnDrives();
|
||||
}
|
||||
@ -34,28 +34,36 @@ public RootFolderService(IRootFolderRepository rootFolderRepository, SeriesProvi
|
||||
|
||||
public virtual List<RootFolder> All()
|
||||
{
|
||||
return _rootFolderRepository.All();
|
||||
var rootFolders = _rootFolderRepository.All();
|
||||
|
||||
rootFolders.ForEach(folder =>
|
||||
{
|
||||
folder.FreeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(folder.Path));
|
||||
folder.UnmappedFolders = GetUnmappedFolders(folder.Path);
|
||||
});
|
||||
|
||||
return rootFolders;
|
||||
}
|
||||
|
||||
public virtual RootFolder Add(RootFolder rootDir)
|
||||
public virtual RootFolder Add(RootFolder rootFolder)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(rootDir.Path) || !Path.IsPathRooted(rootDir.Path))
|
||||
if (String.IsNullOrWhiteSpace(rootFolder.Path) || !Path.IsPathRooted(rootFolder.Path))
|
||||
throw new ArgumentException("Invalid path");
|
||||
|
||||
if (!_diskProvider.FolderExists(rootDir.Path))
|
||||
if (!_diskProvider.FolderExists(rootFolder.Path))
|
||||
throw new DirectoryNotFoundException("Can't add root directory that doesn't exist.");
|
||||
|
||||
if (All().Exists(r => DiskProvider.PathEquals(r.Path, rootDir.Path)))
|
||||
if (All().Exists(r => DiskProvider.PathEquals(r.Path, rootFolder.Path)))
|
||||
throw new InvalidOperationException("Root directory already exist.");
|
||||
|
||||
_rootFolderRepository.Add(rootDir);
|
||||
_rootFolderRepository.Add(rootFolder);
|
||||
|
||||
rootDir.FreeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(rootDir.Path));
|
||||
rootDir.UnmappedFolders = GetUnmappedFolders(rootDir.Path);
|
||||
return rootDir;
|
||||
rootFolder.FreeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(rootFolder.Path));
|
||||
rootFolder.UnmappedFolders = GetUnmappedFolders(rootFolder.Path);
|
||||
return rootFolder;
|
||||
}
|
||||
|
||||
public virtual void Remove(int rootDirId)
|
||||
public virtual void Remove(long rootDirId)
|
||||
{
|
||||
_rootFolderRepository.Delete(rootDirId);
|
||||
}
|
||||
@ -86,7 +94,6 @@ public virtual List<String> GetUnmappedFolders(string path)
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
public virtual Dictionary<string, ulong> FreeSpaceOnDrives()
|
||||
{
|
||||
var freeSpace = new Dictionary<string, ulong>();
|
||||
|
Loading…
Reference in New Issue
Block a user