public async Task <string> GetCardSetJson(CardSetFile file) { if (file == null || string.IsNullOrEmpty(file.cdn_root) || string.IsNullOrEmpty(file.url)) { ArgumentNullException ex = new ArgumentNullException("file"); _logger.LogError(ex, "CardSetFile cannot be null or empty."); throw ex; } if (file.cdn_root.Contains(@"\/")) { FormatException ex = new FormatException("Invalid url format, escape characters are still in the string."); _logger.LogError(ex, "Exception thrown in HttpClientService.GetCardSetJson method."); throw ex; } string result = null; HttpResponseMessage response = await _client.GetAsync(file.cdn_root + file.url); if (response.IsSuccessStatusCode) { result = await response.Content.ReadAsStringAsync(); } return(result); }
public async Task <CardSetFile> GetCardSetFile(string setId) { if (string.IsNullOrEmpty(setId)) { ArgumentNullException ex = new ArgumentNullException("setId"); _logger.LogError(ex, "Exception thrown in CardSetManager.GetCardSetFile method."); throw ex; } int setIdInt; bool parseSucceeded = Int32.TryParse(setId, out setIdInt); if (!parseSucceeded) { FormatException ex = new FormatException("setId was not an integer."); _logger.LogError(ex, "Exception thrown in CardSetManager.GetCardSetFile method."); throw ex; } string fileLocation = await _httpService.GetRawJsonFileLocation(setId); return(_jsonParser.ParseRawJsonFileLocation(fileLocation)); }
public CardSet ParseRawJsonFile(string rawJson) { if (string.IsNullOrEmpty(rawJson)) { throw new ArgumentNullException("rawJson"); } JsonValue json = null; try { json = JsonValue.Parse(rawJson); } catch (ArgumentException ex) { _logger.LogError(ex, "Exception thrown in JsonParsingManager.ParseRawJsonFile method."); throw new FormatException("rawJson was not in JSON format.", ex); } CardSetRootObject jsonObject = JsonConvert.DeserializeObject <CardSetRootObject>(rawJson); return(jsonObject.card_set); }
public string GetLocalFileContents(string fileName) { if (string.IsNullOrEmpty(fileName)) { Exception ex = new ArgumentNullException("fileName"); _logger.LogError(ex, "Exception in FileDataService.GetLocalFileContents method."); throw ex; } if (fileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0) { Exception ex = new FormatException("There were invalid characters in the file name. Please try again."); _logger.LogError(ex, "Exception in FileDataService.GetLocalFileContents method."); throw ex; } string workingPath = Directory.GetCurrentDirectory() + "\\" + fileName; string contents = null; try { using (StreamReader reader = new StreamReader(workingPath)) { contents = reader.ReadToEnd(); } } catch (Exception ex) { _logger.LogError(ex, "Exception in FileDataService.GetLocalFileContents method."); throw ex; } return(contents); }
public AverageDurationResponse Get() { try { return(new AverageDurationResponse { AverageDurationMilliseconds = ComputeAverageDuration() }); } catch (Exception exception) { _logger.LogError(exception, "Failed to compute average duration"); throw; } }
private (int, int) CountTotalAndErrorRecords() { try { var oldestTimestamp = DateTime.Now.AddHours(-1.0); var allCalls = _dbContext.CallOutcomes.Count(c => c.EndTimestamp >= oldestTimestamp); var errorCalls = _dbContext.CallOutcomes.Count(c => c.EndTimestamp >= oldestTimestamp && c.IsError); return(allCalls, errorCalls); } catch (Exception exception) { _logger.LogError(exception, "Failed to retrieve record counts for error rate computation"); throw; } }