public async Task <DcfDto> GetDcf(string stock) { DcfDto result = null; try { _logger.WriteInformation("Getting DCF List"); using (var httpClient = new HttpClient()) { using (var request = new HttpRequestMessage(new HttpMethod("GET"), _dcfUrl + stock)) { request.Headers.TryAddWithoutValidation("Upgrade-Insecure-Requests", "1"); _logger.WriteInformation($"Getting {stock} DCF"); var response = await httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { var jsonString = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <DcfDto>(jsonString); } } } } catch (Exception ex) { _logger.WriteError("Error calling DCF API", ex); } _logger.WriteInformation("Received DCF"); return(result); }
public async Task SaveStocks(List <Stock> stocks) { try { foreach (var stock in stocks) { var existingStock = _context.Stocks.FirstOrDefault(x => x.Symbol == stock.Symbol); if (existingStock == null) { ValidateStockDcf(stock); await AddStock(stock); } else { ValidateStockDcf(stock); await UpdateStock(stock, existingStock); } } await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.WriteError("Error saving DCF list to DB", ex); } _logger.WriteInformation("Saved data to DB"); }
public async Task <List <Server> > GetServerList() { { List <Server> result = null; var httpClient = new RestClient(_apiUrl); var request = await GetServerListRequest(); _logger.WriteInformation("Getting Server List"); try { IRestResponse <List <Server> > response = await httpClient.ExecuteTaskAsync <List <Server> >(request); if (response.IsSuccessful) { result = response.Data; } } catch (Exception ex) { _logger.WriteError("Error calling Server List APi", ex); } _logger.WriteInformation("Received Server List"); return(result); } }
public async Task <SymbolsList> GetStockList() { SymbolsList result = null; try { _logger.WriteInformation("Getting Stock List"); using (var httpClient = new HttpClient()) { using (var request = new HttpRequestMessage(new HttpMethod("GET"), _apiUrl)) { request.Headers.TryAddWithoutValidation("Upgrade-Insecure-Requests", "1"); var response = await httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { var jsonString = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <SymbolsList>(jsonString); } } } } catch (Exception ex) { _logger.WriteError("Error calling Stock list APi", ex); } _logger.WriteInformation("Received Stock List"); return(result); }
public void AddDcf(DcfDto dto) { try { //_context.Dcfs.Add(dto); } catch (Exception ex) { ex.Data.Add(dto.Id, dto); _logger.WriteError("Error saving DCF list to DB", ex); } }
protected override void OnStartup(StartupEventArgs e) { _logger = new ConsoleLogger(); try { Current.DispatcherUnhandledException += GlobalExceptionHandler; AppDomain.CurrentDomain.UnhandledException += AppDomainExceptionhandler; } catch (Exception ex) { _logger.WriteError(ex.Message, ex); MessageBox.Show("Application Failed", "Windows party application", MessageBoxButton.OK, MessageBoxImage.Exclamation); Environment.Exit(9); } base.OnStartup(e); }
public async Task <List <CompanyRatingDto> > GetCompanyRatingList(List <Stock> stocks) { List <CompanyRatingDto> result = new List <CompanyRatingDto>(); try { _logger.WriteInformation("Getting Company Rating List"); using (var httpClient = new HttpClient()) { var stockListString = _symbolService.GetStockListString(stocks, 3); foreach (var stockListItem in stockListString) { using (var request = new HttpRequestMessage(new HttpMethod("GET"), _companyRatingUrl + stockListItem)) { request.Headers.TryAddWithoutValidation("Upgrade-Insecure-Requests", "1"); _logger.WriteInformation($"Getting DCF Items {stockListString.IndexOf(stockListItem)} / {stockListString.Count} : {stockListItem}"); var response = await httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { var jsonString = await response.Content.ReadAsStringAsync(); var responseResults = JsonConvert.DeserializeObject <CompanyRatingListDto>(jsonString); foreach (var responseResult in responseResults.CompaniesRating) { result.Add(responseResult); } } else { throw new Exception($"Failed http call + {stockListItem}"); } } } } } catch (Exception ex) { _logger.WriteError("Error calling Company Rating API", ex); } _logger.WriteInformation("Received Company Rating"); return(result); }
private void ExcecutePrepare() { Task.Run(async() => { try { ToggleVisibility(true); Stocks = await _stockListFacade.GetStockList(); Stocks = await _dCFfacade.GetDcfListWithBulkOrder(Stocks.ToList()); Stocks = await _companyRatingFacade.GetStocksWithRatings(Stocks); SortedStocks = Stocks; await _stockRepoFacade.SaveStocks(Stocks); } catch (Exception ex) { _logger.WriteError("error on main VM preprare call", ex); } finally { ToggleVisibility(false); } }); }
public async Task <ApiTokenResponse> GetToken() { ApiTokenResponse result = null; var httpClient = new RestClient(_apiUrl); var request = GetTokenRequest(); _logger.WriteInformation("Getting Token"); try { IRestResponse <ApiTokenResponse> response = await httpClient.ExecuteTaskAsync <ApiTokenResponse>(request); if (response.IsSuccessful) { result = response.Data; } } catch (Exception ex) { _logger.WriteError("Error calling Token APi", ex); } _logger.WriteInformation("Received Token"); return(result); }
private void HandleUnhandledException(Exception exception) { _logger.WriteError(exception.GetBaseException().Message, exception); MessageBox.Show(TechErrorMessage, "Error", MessageBoxButton.OK, MessageBoxImage.Error); }