Exemplo n.º 1
0
        protected override async Task <bool> ImplementExecute()
        {
            try
            {
                var lastIdCommand = new ReadMaxIdCommand(
                    _twitterRepository);

                var lastId = await lastIdCommand.Execute();

                var mentionTask = _twitterRepository
                                  .GetMentions(lastId)
                                  .ContinueWith(async(Task <SearchResponse> searchResultTask) => {
                    if (searchResultTask.IsCompletedSuccessfully)
                    {
                        var results = searchResultTask.Result;

                        if (results != null)
                        {
                            var currentMaxFileId = results.search_metadata.max_id_str;

                            var writeMaxIdCommand = new WriteMaxIdCommand(
                                currentMaxFileId,
                                _twitterRepository);

                            await writeMaxIdCommand.Execute();

                            var handleMentionsTask = new HandleMentionsCommand(
                                results.statuses,
                                _twitterRepository,
                                _hashtagResponseFactory);

                            Task.Factory.StartNew(async() => {
                                await handleMentionsTask.Execute();
                            });
                        }
                    }

                    await Task.Delay(DelayMilliseconds);

                    var command = new RunMentionWatchCommand(
                        _twitterRepository,
                        _hashtagResponseFactory);

                    await command.Execute();
                });
            }
            catch (Exception)
            {
                //log somehow
                return(false);
            }

            return(true);
        }