sonarr-repo-only/NzbDrone.Core/Providers/SignalRProvider.cs

50 lines
1.7 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NLog;
using NzbDrone.Common.Eventing;
using NzbDrone.Core.Download;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Model;
2012-12-19 01:40:47 +00:00
using NzbDrone.Core.Providers.Hubs;
using SignalR;
using SignalR.Hubs;
namespace NzbDrone.Core.Providers
{
public class SignalRProvider : IHandle<EpisodeGrabbedEvent>
{
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
2012-10-13 21:15:21 +00:00
public virtual void UpdateEpisodeStatus(int episodeId, EpisodeStatusType episodeStatus, QualityModel quality)
{
try
{
logger.Trace("Sending Status update to client. EpisodeId: {0}, Status: {1}", episodeId, episodeStatus);
2012-12-19 01:40:47 +00:00
var context = GlobalHost.ConnectionManager.GetHubContext<EpisodeHub>();
context.Clients.updatedStatus(new
{
EpisodeId = episodeId,
EpisodeStatus = episodeStatus.ToString(),
Quality = (quality == null ? String.Empty : quality.Quality.ToString())
});
}
catch (Exception ex)
{
2012-11-21 16:14:57 +00:00
logger.TraceException("Error", ex);
throw;
}
}
public void Handle(EpisodeGrabbedEvent message)
{
foreach (var episode in message.ParseResult.Episodes)
{
UpdateEpisodeStatus(episode.OID, EpisodeStatusType.Downloading, message.ParseResult.Quality);
}
}
}
}