public async Task <IEnumerable <string> > GetRequestUrlsByFilter(long id, string filter) { if (string.IsNullOrEmpty(filter)) { throw new ArgumentNullException(nameof(filter)); } try { var harFile = await this._harFileRepository.GetByIdAsync(id); if (harFile == null) { throw new Exception($"HarFile {id} not found."); } var harModel = HarConvert.Deserialize(harFile.HarContentString); var urlsFound = harModel.Log.Entries.Select(e => e.Request.Url.AbsoluteUri).Where(u => u.Contains(filter)); return(urlsFound); } catch (Exception ex) { throw new Exception("Unhandled Service Exception", ex); } }
public async Task <IActionResult> Post([FromBody] JObject harFileData) { if (harFileData != null) { var harData = HarConvert.Deserialize(harFileData.ToString()); // validating manually var valid = this.ValidateHarFile(harData); if (valid) { var firstPage = harData.Log.Pages.First(); var harFile = new HarFile(); harFile.URL = firstPage.Title; harFile.StartedDateTime = firstPage.StartedDateTime; harFile.HarContentString = JsonConvert.SerializeObject(harFileData); await this._harFilesService.SaveAsync(harFile); } else { return(BadRequest("The HAR file data is invalid.")); } } return(CreatedAtAction(nameof(Post), null)); }
public async Task <double> GetAverageBodySize(long id) { try { var harFile = await this._harFileRepository.GetByIdAsync(id); if (harFile == null) { throw new Exception($"HarFile {id} not found."); } var harModel = HarConvert.Deserialize(harFile.HarContentString); var avgBodySize = harModel.Log.Entries.Average(e => e.Response.BodySize); return(avgBodySize); } catch (Exception ex) { throw new Exception("Unhandled Service Exception", ex); } }
public async Task <IEnumerable <Entry> > GetBlockedEntries(long id) { try { var harFile = await this._harFileRepository.GetByIdAsync(id); if (harFile == null) { throw new Exception($"HarFile {id} not found."); } var harModel = HarConvert.Deserialize(harFile.HarContentString); var blockedEntires = harModel.Log.Entries.OrderByDescending(e => e.Timings.Blocked); return(blockedEntires); } catch (Exception ex) { throw new Exception("Unhandled Service Exception", ex); } }
public void InitializeFixture() { m_actual = HarConvert.Deserialize(Resources.Sample); }
public Har GetHarContent() { var harString = GetHarContentString(); return(HarConvert.Deserialize(harString)); }
public void Deserialize_Null_Exception() { Assert.Catch <ArgumentNullException>(() => HarConvert.Deserialize(null)); }