/// <summary> /// Traps the response and triggers the event for the current thread /// </summary> /// <param name="tvReqInfo"></param> /// <param name="httpRespInfo"></param> /// <returns>True of False if the request was trapped or not</returns> public bool TrapResponse(TVRequestInfo tvReqInfo, HttpResponseInfo httpRespInfo) { if (_trapResponses) { //trigger the event, if (_responseTrapped != null) { string rawResponse = httpRespInfo.ToString(); if (MatchesTrapDefs(httpRespInfo)) { ManualResetEvent reqLock = new ManualResetEvent(false); _trapOn.BeginInvoke(this, new EventArgs(), null, null); _responseTrapped.BeginInvoke(new RequestTrapEventEventArgs(tvReqInfo, httpRespInfo, reqLock), null, null); //wait for the event to finish reqLock.WaitOne(); _trapOff.BeginInvoke(this, new EventArgs(), null, null); //the request was trapped return true return(true); } } } return(false); }
/// <summary> /// Updates patterns to be tracked with values from response info /// </summary> /// <param name="respInfo"></param> public void UpdatePatternValues(HttpResponseInfo respInfo) { if (respInfo != null) { UpdatePatternValues(respInfo.ToString()); } }
/// <summary> /// Checks if the response matches the traps /// </summary> /// <param name="info"></param> /// <returns></returns> private bool MatchesTrapDefs(HttpResponseInfo info) { string rawResponse = info.ToString(); foreach (HttpTrapDef def in _trapDefs) { if (def.Location == HttpTrapLocation.Response && def.IsMatch(rawResponse)) { return(true); } } return(false); }