Esempio n. 1
0
        protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var corrId      = string.Format("{0}{1}", DateTime.Now.Ticks, Thread.CurrentThread.ManagedThreadId);
            var requestInfo = string.Format("{0} {1}", request.Method, request.RequestUri);

            //var requestMessage = request.Content.ReadAsByteArrayAsync();

            HttpLoggingEventArgs lge = new HttpLoggingEventArgs()
            {
                Method        = request.Method.Method,
                Uri           = request.RequestUri.PathAndQuery,
                CorrelationID = corrId,
                Direction     = "In"
            };

            FireEvent(lge);

            var response = base.SendAsync(request, cancellationToken);
            var result   = response.Result;

            lge.Direction = "Out";
            if (!result.IsSuccessStatusCode)
            {
                lge.Result = result.ReasonPhrase;
            }
            else
            {
                lge.Result = "OK";
            }

            FireEvent(lge);

            return(response);
        }
Esempio n. 2
0
        void Instance_OnHttpLog(object sender, Code.MessageHandler.HttpLoggingEventArgs e)
        {
            this.BeginInvoke((Action)(() =>
            {
                if (e.Direction == "In")
                {
                    trvHttp.Nodes.Add("-> " + DateTime.Now.ToString() + " " + e.Method + " " + e.Uri).Name = e.CorrelationID;
                    return;
                }

                if (e.Direction == "Out")
                {
                    var nd = trvHttp.Nodes.Find(e.CorrelationID, false);
                    var ind = nd.First();
                    if (e.Result == "OK")
                    {
                        ind.Text = ind.Text.Replace("->", "<>") + " - Ok";
                    }
                    else
                    {
                        ind.Text = ind.Text.Replace("->", "XX") + " - " + e.Result;
                    }
                }
            }));
        }
Esempio n. 3
0
 public void FireEvent(HttpLoggingEventArgs args)
 {
     Task.Factory.StartNew(() =>
     {
         if (OnHttpLog != null)
         {
             OnHttpLog(this, args);
         }
     });
 }