2011-07-02 08:56:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Web.Mvc;
|
2011-06-14 01:23:04 +00:00
|
|
|
|
using MvcMiniProfiler;
|
2010-10-08 03:35:04 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class NotificationController : Controller
|
|
|
|
|
{
|
2011-11-21 04:43:16 +00:00
|
|
|
|
private readonly NotificationProvider _notificationProvider;
|
|
|
|
|
|
2010-10-08 03:35:04 +00:00
|
|
|
|
//
|
|
|
|
|
// GET: /Notification/
|
|
|
|
|
|
2011-04-08 23:48:47 +00:00
|
|
|
|
public NotificationController(NotificationProvider notificationProvider)
|
2010-10-08 03:35:04 +00:00
|
|
|
|
{
|
2011-11-21 04:43:16 +00:00
|
|
|
|
_notificationProvider = notificationProvider;
|
2010-10-08 03:35:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-02 08:56:58 +00:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public JsonResult Comet(string message)
|
|
|
|
|
{
|
|
|
|
|
MiniProfiler.Stop(true);
|
|
|
|
|
|
|
|
|
|
var currentMessage = GetCurrentMessage();
|
|
|
|
|
|
2011-07-02 17:41:10 +00:00
|
|
|
|
while (message == currentMessage)
|
2011-07-02 08:56:58 +00:00
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(250);
|
|
|
|
|
currentMessage = GetCurrentMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Json(currentMessage, JsonRequestBehavior.AllowGet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetCurrentMessage()
|
|
|
|
|
{
|
2011-11-21 04:43:16 +00:00
|
|
|
|
var notification = _notificationProvider.GetCurrent();
|
2011-07-02 08:56:58 +00:00
|
|
|
|
|
2011-11-21 04:43:16 +00:00
|
|
|
|
if (notification != null)
|
|
|
|
|
return notification.CurrentMessage;
|
2011-07-02 08:56:58 +00:00
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
2010-10-08 03:35:04 +00:00
|
|
|
|
}
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|