/// <summary> /// Processes this instance. /// </summary> public void Process() { UriHandlerStartedEventArgs startedEventArgs = new UriHandlerStartedEventArgs(Element); OnStarted(startedEventArgs); if (startedEventArgs.Cancel) return; string hash = null; string content = null; Uri redirect = null; Stopwatch stopwatch = new Stopwatch(); // send a found event on a redirect location in the header if (Uri.TryCreate(_response.Headers[HttpResponseHeader.Location], UriKind.RelativeOrAbsolute, out redirect)) OnUriFound(new UriFoundEventArgs(_element.BaseUri, redirect)); stopwatch.Start(); using (Stream responseStream = _response.GetResponseStream()) { using (StreamReader reader = new StreamReader(responseStream)) { content = reader.ReadToEnd(); hash = content.ToHashString("SHA1"); // remove all line breaks for data matching string matchData = content.Replace('\n', ' '); MatchCollection uriMatches = UriExpression.Matches(matchData); foreach (Match match in uriMatches) { if (match.Success) { Uri uri; if (Uri.TryCreate(match.Groups["url"].Value, UriKind.RelativeOrAbsolute, out uri)) OnUriFound(new UriFoundEventArgs(_element.RequestedUri, uri)); } } } responseStream.Close(); } stopwatch.Stop(); OnFinished(new UriProcessingFinishedEventArgs(Element, _response, _related.ToArray(), hash, content, stopwatch.Elapsed)); }
/// <summary> /// Raises the <see cref="E:Started"/> event. /// </summary> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected virtual void OnStarted(UriHandlerStartedEventArgs e) { if (Started != null) Started(this, e); }
/// <summary> /// Handles the Started event of the handler control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void handler_Started(object sender, UriHandlerStartedEventArgs e) { lock (_sync) { bool isProcessed = IsProcessed(e.Element); e.Cancel = isProcessed; if (!isProcessed) _processing.Add(e.Element, DateTime.Now); } }