1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Threading . Tasks ;
4
+ using wikia . Api ;
5
+ using wikia . Models . Article . AlphabeticalList ;
6
+ using wikia . Models . Article . Simple ;
7
+ using ygo_scheduled_tasks . domain . ETL . ArticleList . Processor . Model ;
8
+ using ygo_scheduled_tasks . domain . ETL . Tips . Model ;
9
+ using ygo_scheduled_tasks . domain . Services ;
10
+
11
+ namespace ygo_scheduled_tasks . domain . ETL . ArticleList . Processor . Item
12
+ {
13
+ public class CardTriviaItemProcessor : IArticleItemProcessor
14
+ {
15
+ private readonly IWikiArticle _wikiArticle ;
16
+ private readonly ICardService _cardService ;
17
+ private readonly ICardTriviaService _cardTriviaService ;
18
+
19
+ public CardTriviaItemProcessor
20
+ (
21
+ IWikiArticle wikiArticle ,
22
+ ICardService cardService ,
23
+ ICardTriviaService cardTriviaService
24
+ )
25
+ {
26
+ _wikiArticle = wikiArticle ;
27
+ _cardService = cardService ;
28
+ _cardTriviaService = cardTriviaService ;
29
+ }
30
+
31
+ public async Task < ArticleTaskResult > ProcessItem ( UnexpandedArticle item )
32
+ {
33
+ var response = new ArticleTaskResult { Article = item } ;
34
+
35
+ var card = await _cardService . CardByName ( item . Title ) ;
36
+
37
+ if ( card != null )
38
+ {
39
+ var triviaSections = new List < CardTriviaSection > ( ) ;
40
+
41
+ var articleCardTrivia = await _wikiArticle . Simple ( item . Id ) ;
42
+
43
+ foreach ( var cardTriviaSection in articleCardTrivia . Sections )
44
+ {
45
+ if ( cardTriviaSection . Title . Equals ( "References" , StringComparison . OrdinalIgnoreCase ) )
46
+ continue ;
47
+
48
+ var rulingSection = new CardTriviaSection
49
+ {
50
+ Name = cardTriviaSection . Title ,
51
+ Trivia = GetSectionContentList ( cardTriviaSection )
52
+ } ;
53
+
54
+ triviaSections . Add ( rulingSection ) ;
55
+ }
56
+
57
+ await _cardTriviaService . Update ( card . Id , triviaSections ) ;
58
+ }
59
+
60
+ return response ;
61
+ }
62
+
63
+ private List < string > GetSectionContentList ( Section cardTipSection )
64
+ {
65
+ var content = new List < string > ( ) ;
66
+
67
+ foreach ( var c in cardTipSection . Content )
68
+ {
69
+ GetContentList ( c . Elements , content ) ;
70
+ }
71
+
72
+ return content ;
73
+ }
74
+
75
+ public void GetContentList ( IEnumerable < ListElement > elementList , List < string > contentlist )
76
+ {
77
+ if ( elementList != null )
78
+ {
79
+ foreach ( var e in elementList )
80
+ {
81
+ if ( e != null )
82
+ {
83
+ if ( ! string . IsNullOrEmpty ( e . Text ) )
84
+ contentlist . Add ( e . Text ) ;
85
+
86
+ GetContentList ( e . Elements , contentlist ) ;
87
+ }
88
+ }
89
+ }
90
+ }
91
+
92
+ public bool Handles ( string category )
93
+ {
94
+ return category == ArticleCategory . CardTrivia ;
95
+ }
96
+ }
97
+ }
0 commit comments