1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +02:00
Sonarr/NzbDrone.Core/Providers/ReferenceDataProvider.cs

71 lines
2.0 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using NLog;
using Newtonsoft.Json;
2012-02-11 03:48:20 +03:00
using NzbDrone.Common;
2013-02-24 09:48:52 +03:00
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using PetaPoco;
namespace NzbDrone.Core.Providers
{
public class ReferenceDataProvider
{
private readonly IDatabase _database;
private readonly HttpProvider _httpProvider;
2013-02-24 09:48:52 +03:00
private readonly IConfigService _configService;
2012-02-04 08:28:50 +03:00
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
2013-02-24 09:48:52 +03:00
public ReferenceDataProvider(IDatabase database, HttpProvider httpProvider, IConfigService configService)
{
_database = database;
_httpProvider = httpProvider;
2013-02-24 09:48:52 +03:00
_configService = configService;
}
public virtual void UpdateDailySeries()
{
//Update all series in DB
//DailySeries.csv
var seriesIds = GetDailySeriesIds();
if (seriesIds.Any())
{
var dailySeriesString = String.Join(", ", seriesIds);
var sql = String.Format("UPDATE Series SET IsDaily = 1 WHERE SeriesId in ({0})", dailySeriesString);
_database.Execute(sql);
}
}
public virtual bool IsSeriesDaily(int seriesId)
{
return GetDailySeriesIds().Contains(seriesId);
}
public List<int> GetDailySeriesIds()
{
try
{
2013-02-24 09:48:52 +03:00
var dailySeriesIds = _httpProvider.DownloadString(_configService.ServiceRootUrl + "/DailySeries/AllIds");
var seriesIds = JsonConvert.DeserializeObject<List<int>>(dailySeriesIds);
return seriesIds;
}
2012-02-04 08:28:50 +03:00
catch (Exception ex)
{
Logger.WarnException("Failed to get Daily Series", ex);
return new List<int>();
}
2012-02-04 08:28:50 +03:00
}
}
}