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