Beispiel #1
0
        public void Start()
        {
            timer = new Timer(state =>
            {
                try
                {
                    var tweets = twitterService.GetMentions(settings.SinceId);
                    if (tweets != null)
                    {
                        foreach (var tweet in tweets.OrderBy(x => x.CreatedDate))
                        {
                            settings.UpdateSinceId(tweet.Id);

                            var expression = tweetMatcher.Match(tweet.Text);
                            var response   = sandboxService.Send(expression);

                            // Ignore
                            if (response.HasErrors())
                            {
                                continue;
                            }

                            if (response.HasUnspecifiedBehavior())
                            {
                                HandleUnspecifiedBehavior(response, tweet);
                                continue;
                            }

                            var message = GetMessage(response);
                            if (string.IsNullOrWhiteSpace(message))
                            {
                                continue;
                            }

                            Send(tweet, message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debugger.Launch();
                    Debugger.Break();
                    Console.WriteLine(ex);
                }
            }, null, settings.DueTime, settings.Timeout);
        }