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