private async Task <string> RetrieveHtmlContent() { string content = String.Empty; #if LOCAL_TEST content = await Task.Run(() => File.ReadAllText(@"..\..\..\IHK.ResultsNotifier.Tests\html_content_sample\IHK_Results_Page.html")); return(content); #endif try { content = await networkClient.GetExamResultsDocument(); } catch (HttpRequestException ex) { RequestDataFallback("Lost connection or could not reach the server. Please check your connection.", ex, "INFO", MessageBoxIcon.Exclamation); } catch (AuthenticationException ex) { // Probably User's session expired. Running another attemp to authenticate the user and retrieve results. try { await networkClient.AuthenticateUser(user); if (networkClient.IsAuthenticated) { return(await networkClient.GetExamResultsDocument()); } } catch { /*ignored*/ } RequestDataFallback("User authentication lost. Please try to relog.", ex, "INFO", MessageBoxIcon.Exclamation); } catch (Exception ex) { RequestDataFallback("Unknown error has occurred (4).", ex, "ERROR", MessageBoxIcon.Error); } return(content); }
private async Task AuthenticateUserValidation(User user) { try { if (networkClient == null || networkClient.IsDisposed) { networkClient = new NetworkClient(); await networkClient.AuthenticateUser(user); } else { await networkClient.ValidateAuthentication(); } } catch (HttpRequestException ex) { AuthenticationFallback(ex); } catch (Exception ex) { AuthenticationFallback(ex); } }