2013-04-10 03:47:04 +03:00
|
|
|
using System.Collections.Generic;
|
2013-02-27 06:19:22 +03:00
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Core.Lifecycle;
|
2013-09-11 09:33:47 +03:00
|
|
|
using NzbDrone.Core.Messaging;
|
2013-02-27 06:19:22 +03:00
|
|
|
|
|
|
|
namespace NzbDrone.Core.Qualities
|
|
|
|
{
|
|
|
|
public interface IQualitySizeService
|
|
|
|
{
|
|
|
|
void Update(QualitySize qualitySize);
|
|
|
|
void UpdateAll(List<QualitySize> qualitySizes);
|
|
|
|
List<QualitySize> All();
|
|
|
|
QualitySize Get(int qualityId);
|
|
|
|
}
|
|
|
|
|
2013-04-10 03:47:04 +03:00
|
|
|
public class QualitySizeService : IQualitySizeService, IHandle<ApplicationStartedEvent>
|
2013-02-27 06:19:22 +03:00
|
|
|
{
|
|
|
|
private readonly IQualitySizeRepository _qualitySizeRepository;
|
|
|
|
private readonly Logger _logger;
|
|
|
|
|
|
|
|
public QualitySizeService(IQualitySizeRepository qualitySizeRepository, Logger logger)
|
|
|
|
{
|
|
|
|
_qualitySizeRepository = qualitySizeRepository;
|
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void Update(QualitySize qualitySize)
|
|
|
|
{
|
|
|
|
_qualitySizeRepository.Update(qualitySize);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void UpdateAll(List<QualitySize> qualitySizes)
|
|
|
|
{
|
|
|
|
_qualitySizeRepository.UpdateMany(qualitySizes);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual List<QualitySize> All()
|
|
|
|
{
|
|
|
|
return _qualitySizeRepository.All().ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual QualitySize Get(int qualityId)
|
|
|
|
{
|
|
|
|
return _qualitySizeRepository.GetByQualityId(qualityId);
|
|
|
|
}
|
|
|
|
|
2013-04-10 03:47:04 +03:00
|
|
|
public void Handle(ApplicationStartedEvent message)
|
2013-02-27 06:19:22 +03:00
|
|
|
{
|
2013-02-27 11:21:36 +03:00
|
|
|
var existing = All();
|
2013-02-27 06:19:22 +03:00
|
|
|
|
|
|
|
_logger.Debug("Setting up default quality sizes");
|
|
|
|
|
2013-05-31 04:43:13 +03:00
|
|
|
foreach (var quality in Quality.All())
|
2013-02-27 06:19:22 +03:00
|
|
|
{
|
2013-04-10 03:47:04 +03:00
|
|
|
if (!existing.Any(s => s.QualityId == quality.Id))
|
2013-02-27 11:21:36 +03:00
|
|
|
{
|
2013-02-27 06:19:22 +03:00
|
|
|
_qualitySizeRepository.Insert(new QualitySize
|
2013-04-10 03:47:04 +03:00
|
|
|
{
|
|
|
|
QualityId = quality.Id,
|
|
|
|
Name = quality.Name,
|
|
|
|
MinSize = 0,
|
|
|
|
MaxSize = 100
|
|
|
|
});
|
2013-02-27 11:21:36 +03:00
|
|
|
}
|
2013-02-27 06:19:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|