parent
47fbab02c5
commit
feba96e8e0
@ -0,0 +1,11 @@
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace NzbDrone.Core.Applications
|
||||
{
|
||||
public class AppIndexerMap : ModelBase
|
||||
{
|
||||
public int IndexerId { get; set; }
|
||||
public int AppId { get; set; }
|
||||
public int RemoteIndexerId { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
|
||||
namespace NzbDrone.Core.Applications
|
||||
{
|
||||
public interface IAppIndexerMapRepository : IBasicRepository<AppIndexerMap>
|
||||
{
|
||||
List<AppIndexerMap> GetMappingsForApp(int appId);
|
||||
void DeleteAllForApp(int appId);
|
||||
}
|
||||
|
||||
public class TagRepository : BasicRepository<AppIndexerMap>, IAppIndexerMapRepository
|
||||
{
|
||||
public TagRepository(IMainDatabase database, IEventAggregator eventAggregator)
|
||||
: base(database, eventAggregator)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteAllForApp(int appId)
|
||||
{
|
||||
Delete(x => x.AppId == appId);
|
||||
}
|
||||
|
||||
public List<AppIndexerMap> GetMappingsForApp(int appId)
|
||||
{
|
||||
return Query(x => x.AppId == appId);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
|
||||
namespace NzbDrone.Core.Applications
|
||||
{
|
||||
public interface IAppIndexerMapService
|
||||
{
|
||||
List<AppIndexerMap> GetMappingsForApp(int appId);
|
||||
AppIndexerMap Insert(AppIndexerMap appIndexerMap);
|
||||
void DeleteAllForApp(int appId);
|
||||
}
|
||||
|
||||
public class AppIndexerMapService : IAppIndexerMapService
|
||||
{
|
||||
private readonly IAppIndexerMapRepository _appIndexerMapRepository;
|
||||
|
||||
public AppIndexerMapService(IAppIndexerMapRepository appIndexerMapRepository)
|
||||
{
|
||||
_appIndexerMapRepository = appIndexerMapRepository;
|
||||
}
|
||||
|
||||
public void DeleteAllForApp(int appId)
|
||||
{
|
||||
_appIndexerMapRepository.DeleteAllForApp(appId);
|
||||
}
|
||||
|
||||
public List<AppIndexerMap> GetMappingsForApp(int appId)
|
||||
{
|
||||
return _appIndexerMapRepository.GetMappingsForApp(appId);
|
||||
}
|
||||
|
||||
public AppIndexerMap Insert(AppIndexerMap appIndexerMap)
|
||||
{
|
||||
return _appIndexerMapRepository.Insert(appIndexerMap);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +1,65 @@
|
||||
using NLog;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.ThingiProvider.Events;
|
||||
|
||||
namespace NzbDrone.Core.Applications
|
||||
{
|
||||
public class ApplicationService
|
||||
public class ApplicationService : IHandle<ProviderAddedEvent<IIndexer>>, IHandle<ProviderDeletedEvent<IIndexer>>, IHandle<ProviderAddedEvent<IApplication>>, IHandle<ProviderUpdatedEvent<IIndexer>>
|
||||
{
|
||||
private readonly IApplicationsFactory _applicationsFactory;
|
||||
private readonly IApplicationFactory _applicationsFactory;
|
||||
private readonly Logger _logger;
|
||||
|
||||
public ApplicationService(IApplicationsFactory applicationsFactory, Logger logger)
|
||||
public ApplicationService(IApplicationFactory applicationsFactory, Logger logger)
|
||||
{
|
||||
_applicationsFactory = applicationsFactory;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
// Sync Indexers on App Add if Sync Enabled
|
||||
public void Handle(ProviderAddedEvent<IApplication> message)
|
||||
{
|
||||
var appDefinition = (ApplicationDefinition)message.Definition;
|
||||
|
||||
if (message.Definition.Enable)
|
||||
{
|
||||
var app = _applicationsFactory.GetInstance(appDefinition);
|
||||
|
||||
app.SyncIndexers();
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(ProviderAddedEvent<IIndexer> message)
|
||||
{
|
||||
var enabledApps = _applicationsFactory.GetAvailableProviders();
|
||||
|
||||
// TODO: Only apps with Sync enabled
|
||||
foreach (var app in enabledApps)
|
||||
{
|
||||
app.AddIndexer((IndexerDefinition)message.Definition);
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(ProviderDeletedEvent<IIndexer> message)
|
||||
{
|
||||
var enabledApps = _applicationsFactory.GetAvailableProviders();
|
||||
|
||||
// TODO: Only remove indexers when Sync is Full
|
||||
foreach (var app in enabledApps)
|
||||
{
|
||||
app.RemoveIndexer(message.ProviderId);
|
||||
}
|
||||
}
|
||||
|
||||
public void Handle(ProviderUpdatedEvent<IIndexer> message)
|
||||
{
|
||||
var enabledApps = _applicationsFactory.GetAvailableProviders();
|
||||
|
||||
// TODO: Only upate indexers when Sync is Full
|
||||
foreach (var app in enabledApps)
|
||||
{
|
||||
app.UpdateIndexer((IndexerDefinition)message.Definition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Applications
|
||||
{
|
||||
public interface IApplication : IProvider
|
||||
{
|
||||
void SyncIndexers();
|
||||
void AddIndexer(IndexerDefinition indexer);
|
||||
void UpdateIndexer(IndexerDefinition indexer);
|
||||
void RemoveIndexer(int indexerId);
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
using NzbDrone.Core.ThingiProvider;
|
||||
|
||||
namespace NzbDrone.Core.Applications
|
||||
{
|
||||
public interface IApplications : IProvider
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NzbDrone.Core.Applications.Radarr
|
||||
{
|
||||
public class RadarrField
|
||||
{
|
||||
public int Order { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Label { get; set; }
|
||||
public string Unit { get; set; }
|
||||
public string HelpText { get; set; }
|
||||
public string HelpLink { get; set; }
|
||||
public object Value { get; set; }
|
||||
public string Type { get; set; }
|
||||
public bool Advanced { get; set; }
|
||||
public string Section { get; set; }
|
||||
public string Hidden { get; set; }
|
||||
|
||||
public RadarrField Clone()
|
||||
{
|
||||
return (RadarrField)MemberwiseClone();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NzbDrone.Core.Applications.Radarr
|
||||
{
|
||||
public class RadarrIndexer
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public bool EnableRss { get; set; }
|
||||
public bool EnableAutomaticSearch { get; set; }
|
||||
public bool EnableInteractiveSearch { get; set; }
|
||||
public int Priority { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string ImplementationName { get; set; }
|
||||
public string Implementation { get; set; }
|
||||
public string ConfigContract { get; set; }
|
||||
public string InfoLink { get; set; }
|
||||
public HashSet<int> Tags { get; set; }
|
||||
public List<RadarrField> Fields { get; set; }
|
||||
}
|
||||
}
|
Loading…
Reference in new issue