Пример #1
0
        protected override async Task Execute(CancellationToken token)
        {
            log.LogInformation("Starting twitter monitoring...");

            var keywords = string.IsNullOrEmpty(config.Keywords) ? new string[] { } : config.Keywords.Split(',');
            var follow   = string.IsNullOrEmpty(config.People) ? new string[] { } : config.People.Split(',');

            if (follow.Length == 0 &&
                keywords.Length == 0)
            {
                throw new NotSupportedException("Invalid selection");
            }

            var subscribtion = monitoring.MessagesReceiving
                               .ObserveOn(TaskPoolScheduler.Default)
                               .Subscribe(item => persistency.Save(item));
            await monitoring.Start(keywords, follow).ConfigureAwait(false);

            subscribtion.Dispose();
        }
        private void Start()
        {
            logger.LogInformation("Starting stream...");
            var auth = authentication.Authenticate();

            Auth.SetUserCredentials(auth.ConsumerKey, auth.ConsumerSecret, auth.AccessToken, auth.AccessTokenSecret);
            stream.LanguageFilters = Trackers.Languages;
            subscription           = stream.MessagesReceiving
                                     .ObserveOn(TaskPoolScheduler.Default)
                                     .Where(item => !duplicateDetectors.HasReceived(item.Text))
                                     .Select(Save)
                                     .Merge()
                                     .Subscribe(
                item => { logger.LogDebug("Processed message: {0} ({1})", item.Text, item.Language); },
                e => logger.LogError(e, "Stream error"),
                () => logger.LogInformation("Completed!"));
            var keywords = Trackers.Trackers.Where(item => item.IsKeyword).Select(item => item.Keyword).ToArray();
            var users    = Trackers.Trackers.Where(item => !item.IsKeyword).Select(item => item.Keyword).ToArray();

            Task.Factory.StartNew(async() => await stream.Start(keywords, users).ConfigureAwait(false), TaskCreationOptions.LongRunning);
        }