ReadThreadInfoAsync() public method

public ReadThreadInfoAsync ( ) : Task
return Task
Esempio n. 1
0
        public async Task TakeAsync(int pageSize)
        {
            var collection = new ThreadCollection(_community, _forum);

            for (int i = 1; i < pageSize + 1; i++)
            {
                var threads = await collection.NavigateToPageAsync(i);

                foreach (var url in threads)
                {
                    var threadId = ExtractUuid(url);

                    if (_storage.FirstOrDefault(m => m.Id.Equals(threadId)) != null)
                    {
                        continue;
                    }

                    var parser = new ThreadParser(Guid.Parse(threadId));

                    try
                    {

                        var info = await parser.ReadThreadInfoAsync();

                        _storage.Add(info);

                        Log(threadId);
                    }
                    catch (Exception ex)
                    {
                        Log(ex.Message);
                    }

                }
            }
        }
        private async Task<bool> RegisterNewThreadAsync(string identifier)
        {
            // register a new thread item
            try
            {
                var parser = new ThreadParser(Guid.Parse(identifier));

                var info = await parser.ReadThreadInfoAsync();

                if(info == null)
                {
                    return false;
                }

                // query the database by the identifer / create a new item if not exist
                var model = new ThreadModel
                {
                    Id = info.Id,
                    Title = info.Title,
                    AuthorId = info.AuthorId,
                    CreateOn = info.CreateOn,
                    ForumId = info.ForumId
                };

                var tags = Utils.DetectTagsFromTitle(info.Title);

                foreach (var name in tags)
                {
                    var tag = _tagRepository.CreateTagIfNotExists(name);

                    model.Tags.Add(tag);
                }

                _threadRepository.Create(model);

                return true;
            }catch(Exception e)
            {
                return false;
            }
        }