public static async Task StartAsync( ISendOnlyBus bus, string track, string consumerKey, string consumerSecret, string accessToken, string accessTokenSecret) { var credentials = new TwitterCredentials(consumerKey, consumerSecret, accessToken, accessTokenSecret); while (true) { try { var stream = Stream.CreateFilteredStream(credentials); stream.AddTrack(track); var sessionId = Guid.NewGuid(); stream.StreamStarted += (sender, args) => { sessionId = Guid.NewGuid(); ColorConsole.WriteLine( $"{DateTime.UtcNow.ToLocalTime()}".DarkGray(), " ", $" {track} ".DarkCyan().OnWhite(), " ", "stream started with session ID".Gray(), " ", $"{sessionId}".White()); }; stream.StreamStopped += (sender, args) => ColorConsole.WriteLine( $"{DateTime.UtcNow.ToLocalTime()} ".DarkGray(), $" {track} ".DarkCyan().OnWhite(), " stream stopped.".Red(), args.Exception == null ? string.Empty : $" {args.Exception.Message}".DarkRed()); stream.MatchingTweetReceived += (sender, e) => { var analyzeTweet = TweetMapper.Map(e.Tweet, track); Writer.Write(analyzeTweet.Tweet); bus.Send(analyzeTweet); var tweetReceived = new TweetReceived() { SessionId = sessionId, Track = track, TweetId = e.Tweet.Id }; bus.Publish(tweetReceived); }; await stream.StartStreamMatchingAnyConditionAsync(); } catch (Exception ex) { ColorConsole.WriteLine($"{DateTime.UtcNow.ToLocalTime()} ".DarkGray(), "Error listening to Twitter stream.".Red(), $" {ex.Message}".DarkRed()); Thread.Sleep(1000); } } }
private static void PublishAgreementPlacedForOnlineBrokerEvent(ISendOnlyBus bus) { const int OnlineBrokerId = 456; var agreementPlacedEvent = CreateAgreementPlacedEvent(OnlineBrokerId); bus.Publish(agreementPlacedEvent); }
private static void PublishAgreementPlacedForRemoteBrokerEvent(ISendOnlyBus bus) { const int RemoteBrokerId = 123; var agreementPlacedEvent = CreateAgreementPlacedEvent(RemoteBrokerId); bus.Publish(agreementPlacedEvent); }
public NsbProgressReporter(ISendOnlyBus bus, ICompletionState completionState, IRequestKey defaultRequestKey, Action <IProgress> setTotalCallback = null, Action <IProgress> reportProgressCallback = null) : base(completionState, defaultRequestKey, x => { setTotalCallback?.Invoke(x); using (new TransactionScope(TransactionScopeOption.Suppress)) { bus.Publish(x); } }, x => { reportProgressCallback?.Invoke(x); using (new TransactionScope(TransactionScopeOption.Suppress)) { bus.Publish(x); } }) { }
public void Publish <T>(T message) { sendOnlyBus.Publish(message); }