@@ -117,7 +117,7 @@ private static async Task<bool> GetProps( string accName, string league )
117117 {
118118 return false ;
119119 }
120- if ( Properties . Settings . Default . SessionId == "" )
120+ if ( string . IsNullOrEmpty ( Properties . Settings . Default . SessionId ) )
121121 {
122122 _ = MessageBox . Show ( "Missing Settings!" + Environment . NewLine + "Please set PoE Session Id." ) ;
123123 return false ;
@@ -146,53 +146,44 @@ private static async Task<bool> GetProps( string accName, string league )
146146 {
147147 // add user agent
148148 client . DefaultRequestHeaders . Add ( "User-Agent" , $ "EnhancePoEApp/v{ Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version } " ) ;
149- using ( var res = await client . GetAsync ( propsUri ) )
149+ using var res = await client . GetAsync ( propsUri ) ;
150+ if ( res . IsSuccessStatusCode )
150151 {
151- if ( res . IsSuccessStatusCode )
152- {
153- using ( var content = res . Content )
154- {
155- string resContent = await content . ReadAsStringAsync ( ) ;
156- PropsList = JsonSerializer . Deserialize < StashTabPropsList > ( resContent ) ;
152+ using var content = res . Content ;
153+ string resContent = await content . ReadAsStringAsync ( ) ;
154+ PropsList = JsonSerializer . Deserialize < StashTabPropsList > ( resContent ) ;
157155
158- Trace . WriteLine ( res . Headers , "res headers" ) ;
156+ Trace . WriteLine ( res . Headers , "res headers" ) ;
159157
160- // get new rate limit values
161- string rateLimit = res . Headers . GetValues ( "X-Rate-Limit-Account" ) . FirstOrDefault ( ) ;
162- string rateLimitState = res . Headers . GetValues ( "X-Rate-Limit-Account-State" ) . FirstOrDefault ( ) ;
163- string responseTime = res . Headers . GetValues ( "Date" ) . FirstOrDefault ( ) ;
164- RateLimit . DeserializeRateLimits ( rateLimit , rateLimitState ) ;
165- RateLimit . DeserializeResponseSeconds ( responseTime ) ;
166- }
167- }
168- else
169- {
170- if ( res . StatusCode == HttpStatusCode . Forbidden )
171- {
172- _ = MessageBox . Show ( "Connection forbidden. Please check your Accountname and POE Session ID. You may have to refresh your POE Session ID sometimes." , "Error fetching data" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
173- }
174- else
175- {
176- _ = MessageBox . Show ( res . ReasonPhrase , "Error fetching data" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
177- }
178- FetchError = true ;
179- return false ;
180- }
158+ // get new rate limit values
159+ string rateLimit = res . Headers . GetValues ( "X-Rate-Limit-Account" ) . FirstOrDefault ( ) ;
160+ string rateLimitState = res . Headers . GetValues ( "X-Rate-Limit-Account-State" ) . FirstOrDefault ( ) ;
161+ string responseTime = res . Headers . GetValues ( "Date" ) . FirstOrDefault ( ) ;
162+ RateLimit . DeserializeRateLimits ( rateLimit , rateLimitState ) ;
163+ RateLimit . DeserializeResponseSeconds ( responseTime ) ;
164+ }
165+ else
166+ {
167+ _ = MessageBox . Show ( res . StatusCode == HttpStatusCode . Forbidden ?
168+ "Connection forbidden. Please check your Accountname and POE Session ID. You may have to refresh your POE Session ID sometimes." :
169+ res . ReasonPhrase , "Error fetching data" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
170+ FetchError = true ;
171+ return false ;
181172 }
182173 }
183174
184175 IsFetching = false ;
185176 return true ;
186177 }
187178
188- public async static Task < bool > GetItems ( )
179+ public static async Task < bool > GetItems ( )
189180 {
190181 if ( IsFetching )
191182 {
192183 Trace . WriteLine ( "already fetching" ) ;
193184 return false ;
194185 }
195- if ( Properties . Settings . Default . SessionId == "" )
186+ if ( string . IsNullOrEmpty ( Properties . Settings . Default . SessionId ) )
196187 {
197188 _ = MessageBox . Show ( "Missing Settings!" + Environment . NewLine + "Please set PoE Session Id." ) ;
198189 return false ;
@@ -228,35 +219,31 @@ public async static Task<bool> GetItems()
228219 if ( ! usedUris . Contains ( i . StashTabUri ) )
229220 {
230221 cookieContainer . Add ( i . StashTabUri , new Cookie ( "POESESSID" , sessionId ) ) ;
231- using ( var res = await client . GetAsync ( i . StashTabUri ) )
222+ using var res = await client . GetAsync ( i . StashTabUri ) ;
223+ usedUris . Add ( i . StashTabUri ) ;
224+ if ( res . IsSuccessStatusCode )
232225 {
233- usedUris . Add ( i . StashTabUri ) ;
234- if ( res . IsSuccessStatusCode )
235- {
236- using ( var content = res . Content )
237- {
238- // get new rate limit values
239- string rateLimit = res . Headers . GetValues ( "X-Rate-Limit-Account" ) . FirstOrDefault ( ) ;
240- string rateLimitState = res . Headers . GetValues ( "X-Rate-Limit-Account-State" ) . FirstOrDefault ( ) ;
241- string responseTime = res . Headers . GetValues ( "Date" ) . FirstOrDefault ( ) ;
242- RateLimit . DeserializeRateLimits ( rateLimit , rateLimitState ) ;
243- RateLimit . DeserializeResponseSeconds ( responseTime ) ;
226+ using var content = res . Content ;
227+ // get new rate limit values
228+ string rateLimit = res . Headers . GetValues ( "X-Rate-Limit-Account" ) . FirstOrDefault ( ) ;
229+ string rateLimitState = res . Headers . GetValues ( "X-Rate-Limit-Account-State" ) . FirstOrDefault ( ) ;
230+ string responseTime = res . Headers . GetValues ( "Date" ) . FirstOrDefault ( ) ;
231+ RateLimit . DeserializeRateLimits ( rateLimit , rateLimitState ) ;
232+ RateLimit . DeserializeResponseSeconds ( responseTime ) ;
244233
245- // deserialize response
246- string resContent = await content . ReadAsStringAsync ( ) ;
247- var deserializedContent = JsonSerializer . Deserialize < ItemList > ( resContent ) ;
248- i . ItemList = deserializedContent . items ;
249- i . Quad = deserializedContent . quadLayout ;
234+ // deserialize response
235+ string resContent = await content . ReadAsStringAsync ( ) ;
236+ var deserializedContent = JsonSerializer . Deserialize < ItemList > ( resContent ) ;
237+ i . ItemList = deserializedContent . items ;
238+ i . Quad = deserializedContent . quadLayout ;
250239
251- i . CleanItemList ( ) ;
252- }
253- }
254- else
255- {
256- FetchError = true ;
257- _ = MessageBox . Show ( res . ReasonPhrase , "Error fetching data" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
258- return false ;
259- }
240+ i . CleanItemList ( ) ;
241+ }
242+ else
243+ {
244+ FetchError = true ;
245+ _ = MessageBox . Show ( res . ReasonPhrase , "Error fetching data" , MessageBoxButton . OK , MessageBoxImage . Error ) ;
246+ return false ;
260247 }
261248 }
262249 }
0 commit comments