Exemplo n.º 1
0
        public async void Start(string[] args)
        {
            List <Question> questions = new List <Question>();

            while (true)
            {
                try
                {
                    questions.AddRange(await _stackoverflowParse.ParseList());
                    var resultQuestions = await _repository.AddQuestions(questions);

                    foreach (var q in resultQuestions)
                    {
                        q.Tags = questions.Single(x => x.Url == q.Url).Tags;
                    }

                    var tags = await _repository.UpdateTagsAndStatus(resultQuestions);

                    if (resultQuestions.Any())
                    {
                        await _pushAllProvider.Send();
                    }
                }
                catch (Exception ex)
                {
                    _errorProvider.SendError(ex);
                }
                finally
                {
                    questions.Clear();
                    Thread.Sleep(60 * 1000);
                }
            }
        }
        public async void Start(string[] args)
        {
            List <Question> questions = new List <Question>();

            while (true)
            {
                try
                {
                    questions.AddRange(await _tosterParse.ParseList());
                    var resultQuestions = await _repository.AddQuestions(questions);

                    await _tosterParse.ParseTags(resultQuestions);

                    var tags = await _repository.UpdateTagsAndStatus(resultQuestions);

                    if (tags.Any())
                    {
                        Dictionary <string, string> tagUrls = new Dictionary <string, string>();

                        foreach (var pair in resultQuestions.Where(x => x.TagUrls != null).SelectMany(x => x.TagUrls))
                        {
                            if (!tagUrls.ContainsKey(pair.Key))
                            {
                                tagUrls[pair.Key] = pair.Value;
                            }
                        }

                        foreach (var tag in tags)
                        {
                            tag.Url = tagUrls[tag.Name];
                        }

                        await _tosterParse.ParseTagImage(tags);

                        await _repository.UpdateTagImage(tags);
                    }

                    if (resultQuestions.Any())
                    {
                        await _pushAllProvider.Send();
                    }
                }
                catch (Exception ex)
                {
                    _errorProvider.SendError(ex);
                }
                finally
                {
                    questions.Clear();
                    Thread.Sleep(60 * 1000);
                }
            }
        }