private void CheckContributors() { List <UserListContainer> oldList = contributors; List <UserListContainer> newList = GetContributors(); if (UserListDiff(oldList, newList, out List <UserListContainer> added, out List <UserListContainer> removed, (UseCache.Contains("contributors") ? MonitoringCache["contributors"] : null))) { // Add the new entries to the appropriate cache, if enabled. --Kris if (UseCache.Contains("contributors")) { foreach (UserListContainer ulc in added) { foreach (UserListChild child in ulc.Data.Children) { MonitoringCache["contributors"].Add(child.Id); } } } // Event handler to alert the calling app that the list has changed. --Kris LiveThreadContributorsUpdateEventArgs args = new LiveThreadContributorsUpdateEventArgs { OldContributors = oldList, NewContributors = newList, Added = added, Removed = removed }; OnContributorsUpdated(args); } }
/// <summary> /// Initializes the monitoring cache properties. /// </summary> /// <param name="useCache">Whether to cache the IDs of the monitoring results to prevent duplicate fires</param> /// <param name="type">Which monitoring sort's cache to initialize</param> internal void InitMonitoringCache(bool useCache, string type) { if (useCache) { MonitoringCache[type] = new HashSet <string>(); if (!UseCache.Contains(type)) { UseCache.Add(type); } } else if (UseCache.Contains(type)) { UseCache.Remove(type); } }
private void CheckUpdates() { List <LiveUpdate> oldList = updates; List <LiveUpdate> newList = GetUpdates(); if (Lists.ListDiff(oldList, newList, out List <LiveUpdate> added, out List <LiveUpdate> removed, (UseCache.Contains("updates") ? MonitoringCache["updates"] : null))) { // Event handler to alert the calling app that the list has changed. --Kris LiveThreadUpdatesUpdateEventArgs args = new LiveThreadUpdatesUpdateEventArgs { OldUpdates = oldList, NewUpdates = newList, Added = added, Removed = removed }; OnUpdatesUpdated(args); } }
private void MonitorPagesThread(string key, int startDelayMs = 0, int?monitoringDelayMs = null) { if (startDelayMs > 0) { Thread.Sleep(startDelayMs); } monitoringDelayMs = (monitoringDelayMs.HasValue ? monitoringDelayMs : Monitoring.Count() * MonitoringWaitDelayMS); while (!Terminate && Monitoring.Get(key).Contains(Subreddit)) { if (MonitoringExpiration.HasValue && DateTime.Now > MonitoringExpiration.Value) { MonitorModel.RemoveMonitoringKey(key, Subreddit, ref Monitoring); Threads.Remove(key); break; } while (!IsScheduled()) { if (Terminate) { break; } Thread.Sleep(15000); } if (Terminate) { break; } List <string> oldList; List <string> newList; try { oldList = pages; newList = GetPages(); string type = "pages"; if (Lists.ListDiff(oldList, newList, out List <string> added, out List <string> removed, (UseCache.Contains(type) ? MonitoringCache[type] : null))) { // Add the new entries to the appropriate cache, if enabled. --Kris if (UseCache.Contains(type)) { foreach (string page in added) { MonitoringCache[type].Add(page); } } // Event handler to alert the calling app that the list has changed. --Kris WikiPagesUpdateEventArgs args = new WikiPagesUpdateEventArgs { NewPages = newList, OldPages = oldList, Added = added, Removed = removed }; OnPagesUpdated(args); } } catch (Exception) when(!BreakOnFailure) { } Wait(monitoringDelayMs.Value); } }
private void MonitorPrivateMessagesThread(string key, string type, int startDelayMs = 0, int?monitoringDelayMs = null) { if (startDelayMs > 0) { Thread.Sleep(startDelayMs); } monitoringDelayMs = (monitoringDelayMs.HasValue ? monitoringDelayMs : Monitoring.Count() * MonitoringWaitDelayMS); while (!Terminate && Monitoring.Get(key).Contains("PrivateMessages")) { if (MonitoringExpiration.HasValue && DateTime.Now > MonitoringExpiration.Value) { MonitorModel.RemoveMonitoringKey(key, "PrivateMessages", ref Monitoring); Threads.Remove(key); break; } while (!IsScheduled()) { if (Terminate) { break; } Thread.Sleep(15000); } if (Terminate) { break; } List <Message> oldList; List <Message> newList; try { switch (type) { default: throw new RedditControllerException("Unrecognized type '" + type + "'."); case "inbox": oldList = inbox; newList = GetMessagesInbox(); break; case "unread": oldList = unread; newList = GetMessagesUnread(); break; case "sent": oldList = sent; newList = GetMessagesSent(); break; } if (Lists.ListDiff(oldList, newList, out List <Message> added, out List <Message> removed, (UseCache.Contains(type) ? MonitoringCache[type] : null))) { // Add the new entries to the appropriate cache, if enabled. --Kris if (UseCache.Contains(type)) { foreach (Message message in added) { MonitoringCache[type].Add(message.Id); } } // Event handler to alert the calling app that the list has changed. --Kris MessagesUpdateEventArgs args = new MessagesUpdateEventArgs { NewMessages = newList, OldMessages = oldList, Added = added, Removed = removed }; TriggerUpdate(args, type); } } catch (Exception) when(!BreakOnFailure) { } Wait(monitoringDelayMs.Value); } }