private void btnProcessFile_Click(object sender, EventArgs e) { string result = ""; HarFile harfile; try { using (StreamReader sr = new StreamReader(txtFilePath.Text)) { result = sr.ReadToEnd(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Problem accessing file"); return; } try { harfile = JsonConvert.DeserializeObject<HarFile>(result); } catch (Exception ex2) { MessageBox.Show(ex2.Message, "Problem processing file"); return; } // process the file and build collections of Stat objects. Each stat is a summary of data for a unique item (URL/file type) List<HarFile.Stat> urlStats = new List<HarFile.Stat>(); List<HarFile.Stat> typeStats = new List<HarFile.Stat>(); List<HarFile.Error> errors = new List<HarFile.Error>(); foreach (HarFile.Entry entry in harfile.log.entries) { string url = entry.request.url; string type; //remove URL parameters if (url.Contains("?")) url = url.Substring(0, url.IndexOf("?")); if (url.LastIndexOf('/') > url.LastIndexOf('.')) { type = url.Substring(url.LastIndexOf('/') + 1).ToLower(); } else type = url.Substring(url.LastIndexOf('.') + 1).ToLower(); urlStats = processStat(urlStats, entry, url); typeStats = processStat(typeStats,entry,type); // find errors, create error object, add to list if (entry.response.status > 399) { HarFile.Error errorResp = new HarFile.Error(); errorResp.timestamp = entry.startedDateTime.ToString(); errorResp.time = entry.time; errorResp.url = url; errorResp.queryString = entry.request.queryString; errorResp.status = entry.response.status; errorResp.responseHeaders = entry.response.headers; errorResp.errorText = entry.response.content.text; errors.Add(errorResp); } } urlStats = calcAverages(urlStats, "url"); typeStats = calcAverages(typeStats, "type"); //display stats dgvStats.DataSource = null; source.DataSource = urlStats; dgvStats.DataSource = source; dgvStats.Refresh(); dgvType.DataSource = null; source2.DataSource = typeStats; dgvType.DataSource = source2; dgvType.Refresh(); dgvErrors.DataSource = null; source3.DataSource = errors; dgvErrors.DataSource = source3; dgvErrors.Refresh(); dgvOutliers.DataSource = null; source4.DataSource = outliers; dgvOutliers.DataSource = source4; dgvOutliers.Refresh(); }
private void btnProcessFile_Click(object sender, EventArgs e) { string result = ""; HarFile harfile; try { using (StreamReader sr = new StreamReader(txtFilePath.Text)) { result = sr.ReadToEnd(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Problem accessing file"); return; } try { harfile = JsonConvert.DeserializeObject <HarFile>(result); } catch (Exception ex2) { MessageBox.Show(ex2.Message, "Problem processing file"); return; } // process the file and build collections of Stat objects. Each stat is a summary of data for a unique item (URL/file type) List <HarFile.Stat> urlStats = new List <HarFile.Stat>(); List <HarFile.Stat> typeStats = new List <HarFile.Stat>(); List <HarFile.Error> errors = new List <HarFile.Error>(); foreach (HarFile.Entry entry in harfile.log.entries) { string url = entry.request.url; string type; //remove URL parameters if (url.Contains("?")) { url = url.Substring(0, url.IndexOf("?")); } if (url.LastIndexOf('/') > url.LastIndexOf('.')) { type = url.Substring(url.LastIndexOf('/') + 1).ToLower(); } else { type = url.Substring(url.LastIndexOf('.') + 1).ToLower(); } urlStats = processStat(urlStats, entry, url); typeStats = processStat(typeStats, entry, type); // find errors, create error object, add to list if (entry.response.status > 399) { HarFile.Error errorResp = new HarFile.Error(); errorResp.timestamp = entry.startedDateTime.ToString(); errorResp.time = entry.time; errorResp.url = url; errorResp.queryString = entry.request.queryString; errorResp.status = entry.response.status; errorResp.responseHeaders = entry.response.headers; errorResp.errorText = entry.response.content.text; errors.Add(errorResp); } } urlStats = calcAverages(urlStats, "url"); typeStats = calcAverages(typeStats, "type"); //display stats dgvStats.DataSource = null; source.DataSource = urlStats; dgvStats.DataSource = source; dgvStats.Refresh(); dgvType.DataSource = null; source2.DataSource = typeStats; dgvType.DataSource = source2; dgvType.Refresh(); dgvErrors.DataSource = null; source3.DataSource = errors; dgvErrors.DataSource = source3; dgvErrors.Refresh(); dgvOutliers.DataSource = null; source4.DataSource = outliers; dgvOutliers.DataSource = source4; dgvOutliers.Refresh(); }