@@ -50,7 +50,13 @@ public async Task Parse(string url)
50
50
{
51
51
continue ;
52
52
}
53
- var response = await m_httpClient . GetAsync ( competitionUrl ) ;
53
+ var httpRequestMessage = new HttpRequestMessage ( HttpMethod . Get , competitionUrl ) ;
54
+ httpRequestMessage . Headers . UserAgent . Add ( new System . Net . Http . Headers . ProductInfoHeaderValue ( @"ArcticPuzzler" , "1.0.0.0" ) ) ;
55
+ var response = await m_httpClient . SendAsync ( httpRequestMessage ) ;
56
+ if ( ! response . IsSuccessStatusCode )
57
+ {
58
+ m_logger . LogInformation ( $ "Could not get pdf for { competitionUrl } with response code { response . StatusCode } ") ;
59
+ }
54
60
using ( var stream = await response . Content . ReadAsStreamAsync ( ) )
55
61
{
56
62
var competition = new Competition ( ) ;
@@ -69,7 +75,6 @@ public async Task Parse(string url)
69
75
catch ( Exception ex )
70
76
{
71
77
m_logger . LogInformation ( ex , $ "Error parsing { competitionUrl } ") ;
72
-
73
78
}
74
79
}
75
80
}
@@ -89,10 +94,7 @@ public async Task<CompetitionGroup> ParsePdf(Stream stream)
89
94
90
95
var firstLine = textLines . First ( ) ;
91
96
competitionRound . RoundName = firstLine . Replace ( "Results" , "" ) . TrimEnd ( ) ;
92
- string puzzleName = textLines . Last ( ) ;
93
- string puzzleBrand = textLines [ textLines . Length - 2 ] ;
94
- puzzleBrand = WashPuzzleBrandName ( puzzleBrand ) ;
95
- BrandName puzzleBrandEnum = puzzleBrand . GetEnumFromString < BrandName > ( ) ;
97
+
96
98
97
99
var topRow = rows . First ( ) . ToArray ( ) ;
98
100
var timeHeader = Array . FindIndex ( topRow , t => t . GetText ( ) . ToLower ( ) . Contains ( "time" ) ) ;
@@ -122,17 +124,24 @@ public async Task<CompetitionGroup> ParsePdf(Stream stream)
122
124
await AddResultForIndividual ( competitionRound , rows , timeHeader , nameHeader , countryHeader ) ;
123
125
break ;
124
126
}
125
-
126
- competitionGroup . Rounds . ForEach ( t =>
127
- {
128
- t . Participants . ForEach ( k => k . Results . ForEach ( m => { m . Puzzle . BrandName = puzzleBrandEnum ; m . Puzzle . Name = puzzleName ; } ) ) ;
129
- t . Puzzles . Add ( new Puzzle { BrandName = puzzleBrandEnum , Name = puzzleName } ) ;
130
- } ) ;
131
-
132
-
127
+ try
128
+ {
129
+ string puzzleName = textLines . Last ( ) ;
130
+ string puzzleBrand = textLines [ textLines . Length - 2 ] ;
131
+ puzzleBrand = WashPuzzleBrandName ( puzzleBrand ) ;
132
+ BrandName puzzleBrandEnum = puzzleBrand . GetEnumFromString < BrandName > ( ) ;
133
+ competitionGroup . Rounds . ForEach ( t =>
134
+ {
135
+ t . Participants . ForEach ( k => k . Results . ForEach ( m => { m . Puzzle . BrandName = puzzleBrandEnum ; m . Puzzle . Name = puzzleName ; } ) ) ;
136
+ t . Puzzles . Add ( new Puzzle { BrandName = puzzleBrandEnum , Name = puzzleName } ) ;
137
+ } ) ;
138
+ }
139
+ catch ( Exception ex )
140
+ {
141
+ m_logger . LogInformation ( ex , $ "Error parsing puzzle brandname/puzzle name ") ;
142
+ }
133
143
}
134
144
}
135
-
136
145
competitionGroup . Rounds . Add ( competitionRound ) ;
137
146
138
147
return competitionGroup ;
0 commit comments