protected override void AddRequest(RequestInfoBase info) { if (info.Exception != null) { var now = DateTime.UtcNow; _tracker.Log(info.Exception); if (_lastExceptionTime > DateTime.MinValue) { var timeDiff = now - _lastExceptionTime; _tracker.Log("TimeFromLastException CIAPI", timeDiff.TotalSeconds); } _lastExceptionTime = now; } else { var now = DateTime.UtcNow; _tracker.LogLatency(info.Uri.ToString(), info.Watch.Elapsed.TotalSeconds); if (_lastSuccessTime > DateTime.MinValue) { var timeDiff = now - _lastSuccessTime; _tracker.Log("TimeFromLastSuccess CIAPI", timeDiff.TotalSeconds); } _lastSuccessTime = now; } }
protected override void AddRequest(RequestInfoBase info) { if (Paused) { return; } lock (Requests) { Requests.Add(info.Copy()); } }
private static void AddResult(Stopwatch watch, RequestInfoBase request, string funcName) { var latency = request.Completed.Subtract(request.Issued).TotalSeconds; var res = new LatencyResult { Name = funcName, Internal = latency, //Internal2 = request.Timer.Elapsed.TotalSeconds, External = watch.Elapsed.TotalSeconds, RequestInfo = request }; Latencies.Add(res); }
protected override void AddRequest(RequestInfoBase info) { if (Paused) { return; } lock (_lockTarget) { var json = Client.Serializer.SerializeObject(info); Write(json + "\n,\n"); } }
public virtual void OnRequestCompleted(RequestInfoBase info) { var e = new RequestCompletedEventArgs(info); EventHandler<RequestCompletedEventArgs> handler = RequestCompleted; if (handler != null) { try { handler(this, e); } catch { Log.Error("Error in request completion handler\r\n" + e.Info); } } }
public virtual void OnRequestCompleted(RequestInfoBase info) { if (_disposed) { throw new ObjectDisposedException(GetType().FullName); } var e = new RequestCompletedEventArgs(info); EventHandler<RequestCompletedEventArgs> handler = RequestCompleted; if (handler != null) { try { handler(this, e); } catch { Log.Error("Error in request completion handler\r\n" + e.Info); } } }
internal static WebRequest CreateRequest(RequestInfoBase info, IRequestFactory requestFactory) { WebRequest Request = requestFactory.Create(info.Uri.AbsoluteUri); Request.Method = info.Method.ToString(); if ((info.Method == RequestMethod.POST || info.Method == RequestMethod.PUT)) { Request.ContentType = info.RequestContentType.ToHeaderValue(); } if (Request is HttpWebRequest) { var request = ((HttpWebRequest)Request); switch (info.ResponseContentType) { case ContentType.JSON: request.Accept = "text/plain, text/json, application/json"; break; case ContentType.FORM: request.Accept = "text/plain, text/json, application/json, text/xml, application/xml"; break; case ContentType.XML: request.Accept = "text/xml, application/xml"; break; case ContentType.TEXT: request.Accept = "text/plain"; break; } request.UserAgent = info.UserAgent; var headers = info.Headers; if (headers != null) { foreach (var header in headers) { request.Headers[header.Key] = header.Value.ToString(); } } } if ((info.Method == RequestMethod.POST || info.Method == RequestMethod.PUT)) { if (string.IsNullOrEmpty(info.RequestBody)) { #if !WINDOWS_PHONE Request.ContentLength = 0; #endif } else { // set request stream var gate = new AutoResetEvent(false); byte[] bodyValue = Encoding.UTF8.GetBytes(info.RequestBody); Exception exception = null; Request.BeginGetRequestStream(ac => { try { using ( Stream requestStream = Request.EndGetRequestStream(ac)) { requestStream.Write(bodyValue, 0, bodyValue.Length); requestStream.Flush(); } } catch (Exception ex) { exception = ex; } finally { gate.Set(); } }, null); gate.WaitOne(); // #FIXME: logic to catch stalls conflicts with throttle //if (!gate.WaitOne(10000)) //{ // throw new Exception("timed out setting request body"); //} if (exception != null) { throw exception; } } } return Request; }
public RequestInfoBase Copy() { RequestInfoBase result = new RequestInfoBase() { AllowedRetries = this.AllowedRetries, AttemptedRetries = this.AttemptedRetries, CacheDuration = this.CacheDuration, CacheExpiration = this.CacheExpiration, Completed = this.Completed, Id = this.Id, Index = this.Index, Issued = this.Issued, Method = this.Method, RequestBody = this.RequestBody, RequestContentType = this.RequestContentType, ResponseContentType = this.ResponseContentType, ResponseText = this.ResponseText, State = this.State, Target = this.Target, Timeout = this.Timeout, Uri = this.Uri, UriTemplate = this.UriTemplate, UserAgent = this.UserAgent }; if (Parameters != null) { result.Parameters = new Dictionary<string, object>(this.Parameters); } if (Exception != null) { result.Exception = ReliableHttpException.Create(this.Exception); } var headers = Headers; if (headers != null) { result._headers = headers; } return result; }
public RequestCompletedEventArgs(RequestInfoBase info) { Info = info; }
protected abstract void AddRequest(RequestInfoBase info);