diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-04-26 23:42:05 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2014-04-26 23:42:05 -0400 |
| commit | fadda8ef5663beea338f65ef9c69cd96ec1c5858 (patch) | |
| tree | 911b8d1d86af4452ab93487a2243f0d3197fc7a3 /MediaBrowser.Server.Implementations/News | |
| parent | bdffaf22c99a114d33a7485f9a9c5766e0fbbcaa (diff) | |
add new notification features
Diffstat (limited to 'MediaBrowser.Server.Implementations/News')
| -rw-r--r-- | MediaBrowser.Server.Implementations/News/NewsEntryPoint.cs | 39 | ||||
| -rw-r--r-- | MediaBrowser.Server.Implementations/News/NewsService.cs | 2 |
2 files changed, 39 insertions, 2 deletions
diff --git a/MediaBrowser.Server.Implementations/News/NewsEntryPoint.cs b/MediaBrowser.Server.Implementations/News/NewsEntryPoint.cs index bb6ae5a90b..9a4783cba2 100644 --- a/MediaBrowser.Server.Implementations/News/NewsEntryPoint.cs +++ b/MediaBrowser.Server.Implementations/News/NewsEntryPoint.cs @@ -2,9 +2,12 @@ using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Notifications; using MediaBrowser.Controller.Plugins; using MediaBrowser.Model.Logging; using MediaBrowser.Model.News; +using MediaBrowser.Model.Notifications; using MediaBrowser.Model.Serialization; using System; using System.Collections.Generic; @@ -25,15 +28,20 @@ namespace MediaBrowser.Server.Implementations.News private readonly ILogger _logger; private readonly IJsonSerializer _json; + private readonly INotificationManager _notifications; + private readonly IUserManager _userManager; + private readonly TimeSpan _frequency = TimeSpan.FromHours(24); - public NewsEntryPoint(IHttpClient httpClient, IApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IJsonSerializer json) + public NewsEntryPoint(IHttpClient httpClient, IApplicationPaths appPaths, IFileSystem fileSystem, ILogger logger, IJsonSerializer json, INotificationManager notifications, IUserManager userManager) { _httpClient = httpClient; _appPaths = appPaths; _fileSystem = fileSystem; _logger = logger; _json = json; + _notifications = notifications; + _userManager = userManager; } public void Run() @@ -61,6 +69,13 @@ namespace MediaBrowser.Server.Implementations.News private async Task DownloadNews(string path) { + DateTime? lastUpdate = null; + + if (File.Exists(path)) + { + lastUpdate = _fileSystem.GetLastWriteTimeUtc(path); + } + var requestOptions = new HttpRequestOptions { Url = "http://mediabrowser3.com/community/index.php?/blog/rss/1-media-browser-developers-blog", @@ -75,9 +90,31 @@ namespace MediaBrowser.Server.Implementations.News var news = ParseRssItems(doc).ToList(); _json.SerializeToFile(news, path); + + await CreateNotifications(news, lastUpdate, CancellationToken.None).ConfigureAwait(false); } } + private Task CreateNotifications(List<NewsItem> items, DateTime? lastUpdate, CancellationToken cancellationToken) + { + if (lastUpdate.HasValue) + { + items = items.Where(i => i.Date.ToUniversalTime() > lastUpdate.Value) + .ToList(); + } + + var tasks = items.Select(i => _notifications.SendNotification(new NotificationRequest + { + Date = i.Date, + Name = i.Title, + Description = i.Link, + UserIds = _userManager.Users.Select(u => u.Id.ToString("N")).ToList() + + }, cancellationToken)); + + return Task.WhenAll(tasks); + } + private IEnumerable<NewsItem> ParseRssItems(XmlDocument xmlDoc) { var nodes = xmlDoc.SelectNodes("rss/channel/item"); diff --git a/MediaBrowser.Server.Implementations/News/NewsService.cs b/MediaBrowser.Server.Implementations/News/NewsService.cs index 34da857dd9..9eeadfab7b 100644 --- a/MediaBrowser.Server.Implementations/News/NewsService.cs +++ b/MediaBrowser.Server.Implementations/News/NewsService.cs @@ -2,10 +2,10 @@ using MediaBrowser.Controller.News; using MediaBrowser.Model.News; using MediaBrowser.Model.Querying; +using MediaBrowser.Model.Serialization; using System.Collections.Generic; using System.IO; using System.Linq; -using MediaBrowser.Model.Serialization; namespace MediaBrowser.Server.Implementations.News { |
