private void MonitorCommentsThread(MonitoringSnapshot monitoring, string key, string type, string subKey, int startDelayMs = 0) { if (startDelayMs > 0) { Thread.Sleep(startDelayMs); } while (!Terminate && Monitoring.Get(key).Contains(subKey)) { List <Comment> oldList; List <Comment> newList; switch (type) { default: throw new RedditControllerException("Unrecognized type '" + type + "'."); case "confidence": oldList = confidence; newList = GetConfidence(); break; case "top": oldList = top; newList = GetTop(); break; case "new": oldList = newComments; newList = GetNew(); break; case "controversial": oldList = controversial; newList = GetControversial(); break; case "old": oldList = old; newList = GetOld(); break; case "random": oldList = random; newList = GetRandom(); break; case "qa": oldList = qa; newList = GetQA(); break; case "live": oldList = live; newList = GetLive(); break; } if (Lists.ListDiff(oldList, newList, out List <Comment> added, out List <Comment> removed)) { // Event handler to alert the calling app that the list has changed. --Kris CommentsUpdateEventArgs args = new CommentsUpdateEventArgs { NewComments = newList, OldComments = oldList, Added = added, Removed = removed }; TriggerUpdate(args, type); } Thread.Sleep(Monitoring.Count() * MonitoringWaitDelayMS); } }
private void MonitorCommentsThread(MonitoringSnapshot monitoring, string key, string type, string subKey, 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(subKey)) { if (MonitoringExpiration.HasValue && DateTime.Now > MonitoringExpiration.Value) { MonitorModel.RemoveMonitoringKey(key, subKey, ref Monitoring); Threads.Remove(key); break; } while (!IsScheduled()) { if (Terminate) { break; } Thread.Sleep(15000); } if (Terminate) { break; } List <Comment> oldList; List <Comment> newList; try { switch (type) { default: throw new RedditControllerException("Unrecognized type '" + type + "'."); case "confidence": oldList = confidence; newList = GetConfidence(); break; case "top": oldList = top; newList = GetTop(); break; case "new": oldList = newComments; newList = GetNew(); break; case "controversial": oldList = controversial; newList = GetControversial(); break; case "old": oldList = old; newList = GetOld(); break; case "random": oldList = random; newList = GetRandom(); break; case "qa": oldList = qa; newList = GetQA(); break; case "live": oldList = live; newList = GetLive(); break; } if (Lists.ListDiff(oldList, newList, out List <Comment> added, out List <Comment> removed)) { // Event handler to alert the calling app that the list has changed. --Kris CommentsUpdateEventArgs args = new CommentsUpdateEventArgs { NewComments = newList, OldComments = oldList, Added = added, Removed = removed }; TriggerUpdate(args, type); } } catch (Exception) when(!BreakOnFailure) { } Wait(monitoringDelayMs.Value); } }
private void MonitorPostsThread(MonitoringSnapshot monitoring, string key, string type, string subKey, int startDelayMs = 0) { if (startDelayMs > 0) { Thread.Sleep(startDelayMs); } while (!Terminate && Monitoring.Get(key).Contains(subKey)) { List <Post> oldList; List <Post> newList; switch (type) { default: throw new RedditControllerException("Unrecognized type '" + type + "'."); case "best": oldList = best; newList = GetBest(); break; case "hot": oldList = hot; newList = GetHot(); break; case "new": oldList = newPosts; newList = GetNew(); break; case "rising": oldList = rising; newList = GetRising(); break; case "top": oldList = top; newList = GetTop(); break; case "controversial": oldList = controversial; newList = GetControversial(); break; case "modqueue": oldList = modQueue; newList = GetModQueue(); break; case "modqueuereports": oldList = modQueueReports; newList = GetModQueueReports(); break; case "modqueuespam": oldList = modQueueSpam; newList = GetModQueueSpam(); break; case "modqueueunmoderated": oldList = modQueueUnmoderated; newList = GetModQueueUnmoderated(); break; case "modqueueedited": oldList = modQueueEdited; newList = GetModQueueEdited(); break; } if (Lists.ListDiff(oldList, newList, out List <Post> added, out List <Post> removed)) { // Event handler to alert the calling app that the list has changed. --Kris PostsUpdateEventArgs args = new PostsUpdateEventArgs { NewPosts = newList, OldPosts = oldList, Added = added, Removed = removed }; TriggerUpdate(args, type); } Thread.Sleep(Monitoring.Count() * MonitoringWaitDelayMS); } }