public void AddDocumentResult(DocumentResult result) { switch (result.Type) { case DocType.HtmlPage: Pages.Add(result); break; case DocType.Asset: Assets.Add(result); break; } TimeSpan totalTime = AvgDownloadTime + result.DownloadTime; double totalMiliSec = totalTime.TotalMilliseconds; AvgDownloadTime = TimeSpan.FromMilliseconds(totalMiliSec / (Pages.Count + Assets.Count)); }
/// <summary> /// Entry point for scanning process /// </summary> /// <param name="website"> URI of website to scan </param> /// <returns> Summary of scanning process </returns> public ScanResult Scan() { ScanResult result = new ScanResult(_baseUri); _uriQueue.Enqueue(_baseUri); _scanned.Add(_baseUri); int counter = 0; while (_uriQueue.Count > 0 && counter++ < PAGES_LIMIT) { DocumentResult docResult = processDocument(_uriQueue.Dequeue()); _scanned.Add(docResult.Uri); result.AddDocumentResult(docResult); } return(result); }
private DocumentResult processDocument(Uri uri) { OnMeasuringStarted(uri); sw.Start(); HttpResponseMessage response; try { response = _client.GetAsync(uri).Result; } catch (Exception e) { return(new DocumentResult() { Exception = e }); } sw.Stop(); DocumentResult result = new DocumentResult() { Uri = uri, ScannedAt = DateTime.Now, StatusCode = response.StatusCode, Size = response.Content.ReadAsByteArrayAsync().Result.Length, DownloadTime = sw.Elapsed }; string contentType = response.Content?.Headers.ContentType?.MediaType; // Detect type of response if (Utilities.IsHtmlMimeType(contentType)) { result.Type = DocType.HtmlPage; parseResponse(response); } else { result.Type = DocType.Asset; } OnMeasuringEnded(result); sw.Reset(); return(result); }
private void OnMeasuringEnded(DocumentResult result) { MeasuringEnded?.Invoke(this, result); }