public async Task <LinkReader> SaveAsync(int userId, long chatId) { try { var linkReaderId = Guid.NewGuid(); var newlinkReader = new LinkReader { ChatId = chatId, CreateDate = DateTime.Now, LinkReaderId = linkReaderId, UserId = userId }; Context.LinkReader.Add(newlinkReader); await Context.SaveChangesAsync(); return(newlinkReader); } catch (Exception exception) { Logger.LogError(exception.Message); throw; } }
private ReadingOptions GetReadingOptionsForParser() { var emReader = new PairedTagReader("em", "_"); var strongReader = new PairedTagReader("strong", "__"); var backslashReader = new BackslashReader(); var textReader = new TextReader("_\\[]"); var anyCharReader = new AnyCharReader(); var linkReader = new LinkReader(); var allowedReaders = new List <AbstractReader> { strongReader, emReader, linkReader, backslashReader, textReader, anyCharReader }; var allowedInnerReaders = new Dictionary <AbstractReader, HashSet <AbstractReader> > { [emReader] = new HashSet <AbstractReader> { backslashReader, textReader, anyCharReader }, [strongReader] = new HashSet <AbstractReader> { emReader, backslashReader, textReader, anyCharReader }, [linkReader] = new HashSet <AbstractReader> { strongReader, emReader, backslashReader, textReader, anyCharReader } }; return(new ReadingOptions(allowedReaders, allowedInnerReaders)); }
public void CanReadEmptyBuild() { var linkData = "http://www.cohplanner.com/mids/download.php?uc=609&c=250&a=500&f=HEX&dc=78DAF3AD70E159E7DE68CFC0C8EB9C93585C1CEF04244B528B587D13D333931980802B332F393FB72027B524951DC895832A880F4ACC4B4F4DD10B4A4CC94C2CC9CCCF83E854834907971614E4179520C9FB26E6651694E680390C8201F9F9397A9E796599C599499939992595226011D78A82D4A2CCDCD4BC12B03A5EB0A05B667A4649665E3A37849703E20ABA166426EB39E7E7A4000D06D9582901749D1A1047F23240C17F20020206734D7491FF7405322CE8F62B824418C122FFBDB5E0B2FFB530541A6088186288186388986088F8608804B0409D001461048B700A303030435DF2960B28CB882CFB1E43E41D86C8070C110042BB08B9"; var link = new LinkReader(new StringReader(linkData)).Read(); Assert.NotNull(link); Assert.NotNull(link.CompressionData); using var stream = new CompressionDataStream(link.CompressionData); using var binaryReader = new BinaryReader(stream); var characterReader = new CharacterReader(binaryReader); var character = characterReader.Read(); Assert.NotNull(character); Assert.NotNull(character.Archetype); Assert.Equal("Blaster", character.Archetype.DisplayName); Assert.NotNull(character.Name); Assert.Equal("incomplete", character.Name); foreach (var build in character.Builds) { Assert.NotNull(build.PowerSets); Assert.Equal(8, build.PowerSets.Count); Assert.NotNull(build.PowerSlots); Assert.Equal(39, build.PowerSlots.Count); } }
private CompressionData GetCompressionData(string linkData) { var reader = new StringReader(linkData); var linkReader = new LinkReader(reader); var link = linkReader.Read(); Assert.NotNull(link); Assert.NotNull(link.CompressionData); return(link.CompressionData); }
/// <summary> /// Inicia el crawler,obtiene los links de la pagina inicial,y a continuacion los procesa /// </summary> /// <returns></returns> public async Task StartCrawler() { var reader = new LinkReader(Request); var links = await reader.GetLinks(); var listPocos = new List <BabelPoco>(); foreach (var item in links) { var url = item; if (url.Contains(Request.Url).Equals(false)) { url = Request.OriginalUrl + url; } var htmlDocument = await Downloader.Download(url); var babelPoco = await Processor.Process(htmlDocument); listPocos.Add(babelPoco); } await Pipeline.Run(listPocos); }
public LinksController(LinkWriter linkWriter, LinkReader linkReader) { this.linkWriter = linkWriter; this.linkReader = linkReader; }
public async Task <LinkResultDTO> GetAsync(LinkReader linkReader, bool isAPIRequest, string search, string user, DateTime?startDate, DateTime?endDate, int?pageIndex, int?pageSize) { try { if (!pageIndex.HasValue) { pageIndex = 0; } if (!pageSize.HasValue) { pageSize = 10; } if (!startDate.HasValue) { startDate = DateTime.Now.AddMonths(-1); } if (!endDate.HasValue) { endDate = DateTime.Now.AddDays(1).AddMilliseconds(-1); } else { endDate = endDate.Value.AddDays(1).AddMilliseconds(-1); } var searchQuery = Context.Link.Where(p => p.ChatId == linkReader.ChatId && (string.IsNullOrEmpty(search) || p.Message.Contains(search)) && (string.IsNullOrEmpty(user) || p.Username.Contains(user)) && (p.CreateDate >= startDate.Value) && (p.CreateDate <= endDate.Value) ).OrderByDescending(p => p.CreateDate); var totalItems = await Context.Link.Where(p => p.ChatId == linkReader.ChatId).CountAsync(); var totalSearchItems = await searchQuery.CountAsync(); var searchItems = await searchQuery.Skip(pageIndex.Value *pageSize.Value).Take(pageSize.Value).ToListAsync(); var chat = await _chatBO.GetChatAsync(linkReader.ChatId); var linkResultDTO = new LinkResultDTO { ChatId = linkReader.ChatId, ChatTitle = chat.Title, CreateDate = DateTime.Now, TotalItems = totalItems, TotalSearchItems = totalSearchItems, Items = new List <LinkDTO>() }; var userDataList = new List <Tuple <int, string, string> >(); foreach (var link in searchItems) { var linkDTO = new LinkDTO { Title = link.Title, CreateDate = link.CreateDate, Uri = link.Uri, Description = link.Description, Keywords = link.Keywords, ThumbnailUri = link.ThumbnailUri, UserId = link.UserId }; if (!string.IsNullOrEmpty(link.Username)) { linkDTO.Username = link.Username; } var linkUserData = userDataList.FirstOrDefault(p => p.Item1 == link.UserId); if (linkUserData != null) { if (!string.IsNullOrWhiteSpace(linkUserData.Item2)) { linkDTO.FirstName = linkUserData.Item2; } if (!string.IsNullOrWhiteSpace(linkUserData.Item3)) { linkDTO.LastName = linkUserData.Item3; } } else { var chatMember = await _chatBO.GetChatMemberAsync(linkReader.ChatId, link.UserId); if (chatMember != null && chatMember.User != null) { if (!string.IsNullOrWhiteSpace(chatMember.User.FirstName)) { linkDTO.FirstName = chatMember.User.FirstName; } if (!string.IsNullOrWhiteSpace(chatMember.User.LastName)) { linkDTO.LastName = chatMember.User.LastName; } var userData = new Tuple <int, string, string>(link.UserId, linkDTO.FirstName, linkDTO.LastName); userDataList.Add(userData); } } linkResultDTO.Items.Add(linkDTO); } await _linkReaderLogBO.SaveLogAsync(linkReader.LinkReaderId, isAPIRequest, searchItems.Count()); return(linkResultDTO); } catch (Exception exception) { Logger.LogError(exception.Message); throw; } }
public LinkHub(LinkReader linkReader, LinkWriter linkWriter, ContextReader contextReader) { this.linkReader = linkReader; this.linkWriter = linkWriter; this.contextReader = contextReader; }