public IEnumerable <SemanticCard> Producer(string url) { if (string.IsNullOrWhiteSpace(url)) { throw new ArgumentException(nameof(url)); } var nextPageUrl = url; do { _semanticSearchResults.Load(nextPageUrl); foreach (var row in _semanticSearchResults.TableRows) { var semanticCard = new SemanticCard { Title = _semanticCardSearchResults.Name(row), CorrelationId = Guid.NewGuid(), Url = _semanticCardSearchResults.Url(row, _semanticSearchResults.CurrentWebPageUri) }; if (!string.IsNullOrWhiteSpace(semanticCard.Title) && !string.IsNullOrWhiteSpace(semanticCard.Url)) { yield return(semanticCard); } } if (_semanticSearchResults.HasNextPage) { nextPageUrl = _semanticSearchResults.NextPageLink(); } } while (_semanticSearchResults.HasNextPage); }
public override void ContinueGesture(object sender, GestureEventArgs e) { base.ContinueGesture(sender, e); SemanticCard card = (SemanticCard)e.Senders[0]; card.Rotate(10);//for debug }
public async Task <SemanticSearchTaskResult> ProcessItem(SemanticCard semanticCard) { var response = new SemanticSearchTaskResult { Card = semanticCard }; var yugiohCard = _cardWebPage.GetYugiohCard(new Uri(new Uri(_config.WikiaDomainUrl), semanticCard.Url)); if (yugiohCard != null) { response.YugiohCard = yugiohCard; const string flip = "Flip"; if (!yugiohCard.Types.ToLower().Contains(flip.ToLower())) { yugiohCard.Types = $"{yugiohCard.Types} / {flip}"; } var card = await _yugiohCardService.AddOrUpdate(yugiohCard); if (card != null) { response.IsSuccessfullyProcessed = true; } } return(response); }
public Task Publish(SemanticCard semanticCard) { var messageBodyBytes = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(semanticCard)); var factory = new ConnectionFactory() { HostName = _rabbitMqConfig.Value.Host, Port = _rabbitMqConfig.Value.Port, UserName = _rabbitMqConfig.Value.Username, Password = _rabbitMqConfig.Value.Password }; using (var connection = factory.CreateConnection()) using (var channel = connection.CreateModel()) { var props = channel.CreateBasicProperties(); props.ContentType = _rabbitMqConfig.Value.ContentType; props.DeliveryMode = _rabbitMqConfig.Value.Exchanges[RabbitMqExchangeConstants.YugiohHeadersArticle].PersistentMode; props.Headers = _rabbitMqConfig.Value.Exchanges[RabbitMqExchangeConstants.YugiohHeadersArticle].Headers.ToDictionary(k => k.Key, k => (object)k.Value); channel.BasicPublish ( RabbitMqExchangeConstants.YugiohHeadersArticle, string.Empty, props, messageBodyBytes ); } return(Task.CompletedTask); }
/// <summary> /// Add a card to the card layer /// </summary> /// <param name="card"></param> internal async Task AddCard(Card card) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { this.Children.Add(card); SemanticCard sCard = card as SemanticCard; }); }
public override void TerminateGesture(object sender, GestureEventArgs e) { base.TerminateGesture(sender, e); SemanticCard card = (SemanticCard)e.Senders[0]; SortingBox box = (SortingBox)e.Senders[1]; box.AddCard(card); System.Diagnostics.Debug.WriteLine("Card Sorted: " + card.Document.GetTitle()); }
public async Task Given_A_SemanticCard_If_Process_Executed_Successful_IsSuccessful_Should_Be_True() { // Arrange var semanticCard = new SemanticCard(); // Act var result = await _sut.Process(semanticCard); // Assert result.IsSuccessful.Should().BeTrue(); }
public async Task Given_A_SemanticCard_Should_Invoke_Publish_Once() { // Arrange var semanticCard = new SemanticCard(); // Act await _sut.Process(semanticCard); // Assert await _articleHeaderExchange.Received(1).Publish(Arg.Is(semanticCard)); }
public async Task <SemanticCardPublishResult> Process(SemanticCard semanticCard) { var response = new SemanticCardPublishResult { Card = semanticCard }; _logger.LogInformation("Publishing semantic card '{CardName}' to queue", semanticCard.Title); await _articleHeaderExchange.Publish(semanticCard); response.IsSuccessful = true; return(response); }
public async Task Given_A_Category_And_A_SemanticCard_Should_Execute_Process() { // Arrange var category = "Flip"; var semanticCard = new SemanticCard { Name = "Red-Eyes Black Dragon" }; _semanticCardProcessor.Process(Arg.Any <string>(), Arg.Any <SemanticCard>()).Returns(new SemanticSearchTaskResult()); // Act await _sut.Process(category, semanticCard); // Assert await _semanticCardProcessor.Received(1).Process(Arg.Any <string>(), Arg.Any <SemanticCard>()); }
public List <SemanticCard> CardsByUrl(string url) { HtmlNode nextLink; var semanticCardList = new List <SemanticCard>(); do { var doc = _htmlWebPage.Load(url); var tableRows = doc.DocumentNode.SelectNodes("//table[@class='sortable wikitable smwtable']/tbody/tr") ?? doc.DocumentNode.SelectNodes("//table[@class='sortable wikitable smwtable card-list']/tbody/tr"); foreach (var row in tableRows) { var semanticCard = new SemanticCard { Name = row.SelectSingleNode("td[position() = 1]")?.InnerText.Trim(), Url = row.SelectSingleNode("td[position() = 1]/a")?.Attributes["href"]?.Value, }; if (!string.IsNullOrWhiteSpace(semanticCard.Name)) { semanticCardList.Add(semanticCard); } } nextLink = doc.DocumentNode.SelectSingleNode("//a[contains(text(), 'Next')]"); if (nextLink != null) { var hrefLink = $"{_config.WikiaDomainUrl}{nextLink.Attributes["href"].Value}"; hrefLink = WebUtility.HtmlDecode(hrefLink); url = hrefLink; } } while (nextLink != null); return(semanticCardList); }
public Task <SemanticSearchTaskResult> Process(string category, SemanticCard semanticCard) { var handler = _semanticCardHandler.Handler(category); return(handler.ProcessItem(semanticCard)); }
public Task <SemanticSearchTaskResult> Process(string category, SemanticCard semanticCard) { _logger.Info("{1} | ' {0} '", semanticCard.Name, category); return(_semanticCardProcessor.Process(category, semanticCard)); }