예제 #1
0
        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));
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
 public void InitializeFixture()
 {
     m_actual = HarConvert.Deserialize(Resources.Sample);
 }
        public Har GetHarContent()
        {
            var harString = GetHarContentString();

            return(HarConvert.Deserialize(harString));
        }
예제 #7
0
 public void Deserialize_Null_Exception()
 {
     Assert.Catch <ArgumentNullException>(() => HarConvert.Deserialize(null));
 }