private OnGoingStudy StartStudy(TwitterStudy study) { var reportData = new TwitterSpyStudyData(study); Trace.WriteLine(string.Format("Study {0} started", study.Id)); foreach (var topic in study.Topics) { _stream.AddTrack(topic, reportData.ProcessTweet); } var onGoingStudy = new OnGoingStudy { Data = reportData }; // the object is stored so that the timer isn't garbage collected var timer = new Timer(o => { var data = (TwitterSpyStudyData)o; // // Remove the study from the ongoing list // lock (_onGoingStudies) { _onGoingStudies.Remove(onGoingStudy); } CheckIfStreamNeedsToBeStopped(); // // Remove topics // foreach (var topic in data.Study.Topics) { _stream.RemoveTrack(topic); } var report = data.GetReport(); // // send report to the client via queue // _reportQueue.AddMessage(new CloudQueueMessage(JsonConvert.SerializeObject(report))); }, reportData, study.Duration, TimeSpan.FromTicks(-1)); onGoingStudy.Timer = timer; return(onGoingStudy); }
void HandleTracks(bool add, params string[] tracks) { StopTweetStream(); foreach (var track in tracks) { if (add) { _filteredStream.AddTrack(track); } else { _filteredStream.RemoveTrack(track); } } }
public void RemoveTrack(string hashtag) { if (filteredStream.TracksCount > 0) { filteredStream.StopStream(); Dictionary <string, Action <ITweet> > tracks = filteredStream.Tracks; ReCreateFilteredStream(); tracks.Keys.ForEach(s => filteredStream.AddTrack(s)); } filteredStream.RemoveTrack(hashtag); if (filteredStream.TracksCount > 0) { filteredStream.StartStreamMatchingAnyConditionAsync(); } Debug.WriteLine("REMOVED HASHTAG - " + hashtag); }