2012-01-23 08:43:54 +01:00
|
|
|
|
using System.Threading;
|
2011-07-02 10:56:58 +02:00
|
|
|
|
using System.Web.Mvc;
|
2012-01-23 08:43:54 +01:00
|
|
|
|
using System.Web.UI;
|
2010-10-08 05:35:04 +02:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2012-07-27 23:31:33 +02:00
|
|
|
|
using StackExchange.Profiling;
|
2010-10-08 05:35:04 +02:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class NotificationController : Controller
|
|
|
|
|
{
|
2011-11-21 05:43:16 +01:00
|
|
|
|
private readonly NotificationProvider _notificationProvider;
|
|
|
|
|
|
2010-10-08 05:35:04 +02:00
|
|
|
|
//
|
|
|
|
|
// GET: /Notification/
|
|
|
|
|
|
2011-04-09 01:48:47 +02:00
|
|
|
|
public NotificationController(NotificationProvider notificationProvider)
|
2010-10-08 05:35:04 +02:00
|
|
|
|
{
|
2011-11-21 05:43:16 +01:00
|
|
|
|
_notificationProvider = notificationProvider;
|
2010-10-08 05:35:04 +02:00
|
|
|
|
}
|
|
|
|
|
|
2011-07-02 10:56:58 +02:00
|
|
|
|
[HttpGet]
|
2012-01-23 08:43:54 +01:00
|
|
|
|
[OutputCache(NoStore = true, Location = OutputCacheLocation.None)]
|
2011-07-02 10:56:58 +02:00
|
|
|
|
public JsonResult Comet(string message)
|
|
|
|
|
{
|
|
|
|
|
MiniProfiler.Stop(true);
|
|
|
|
|
|
|
|
|
|
var currentMessage = GetCurrentMessage();
|
|
|
|
|
|
2011-07-02 19:41:10 +02:00
|
|
|
|
while (message == currentMessage)
|
2011-07-02 10:56:58 +02:00
|
|
|
|
{
|
|
|
|
|
Thread.Sleep(250);
|
|
|
|
|
currentMessage = GetCurrentMessage();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Json(currentMessage, JsonRequestBehavior.AllowGet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetCurrentMessage()
|
|
|
|
|
{
|
2011-11-21 05:43:16 +01:00
|
|
|
|
var notification = _notificationProvider.GetCurrent();
|
2011-07-02 10:56:58 +02:00
|
|
|
|
|
2011-11-21 05:43:16 +01:00
|
|
|
|
if (notification != null)
|
|
|
|
|
return notification.CurrentMessage;
|
2011-07-02 10:56:58 +02:00
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
2010-10-08 05:35:04 +02:00
|
|
|
|
}
|
2011-04-10 04:44:01 +02:00
|
|
|
|
}
|