/// <summary> /// before the send request. /// </summary> /// <param name="request">The request.</param> /// <param name="channel">The channel.</param> /// <returns>the mini profiler start</returns> public object BeforeSendRequest(ref Message request, IClientChannel channel) { var miniProfiler = MiniProfiler.Current; if (miniProfiler == null) { return(null); } miniProfiler.Step($"WCF call to {channel.RemoteAddress.Uri}"); var header = new MiniProfilerRequestHeader { User = miniProfiler.User, ParentProfilerId = miniProfiler.Id }; // ReSharper disable PossibleUnintendedReferenceComparison if (request.Headers.MessageVersion != MessageVersion.None) // ReSharper restore PossibleUnintendedReferenceComparison { var untypedHeader = new MessageHeader <MiniProfilerRequestHeader>(header) .GetUntypedHeader(MiniProfilerRequestHeader.HeaderName, MiniProfilerRequestHeader.HeaderNamespace); request.Headers.Add(untypedHeader); } else if (_http || WebOperationContext.Current != null || channel.Via.Scheme == "http" || channel.Via.Scheme == "https") { _http = true; object property; if (!request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out property)) { property = new HttpRequestMessageProperty(); request.Properties.Add(HttpRequestMessageProperty.Name, property); } ((HttpRequestMessageProperty)property).Headers.Add(MiniProfilerRequestHeader.HeaderName, header.ToHeaderText()); } else { throw new InvalidOperationException("MVC Mini Profiler does not support EnvelopeNone unless HTTP is the transport mechanism"); } return(new MiniProfilerState { Timing = miniProfiler.Head, // Can't use MiniProfiler.DurationMilliseconds as it is set only when the profiler is stopped StartTime = miniProfiler.GetElapsedMilliseconds() }); }
/// <summary> /// parse the header text, and return the resulting profiler. /// </summary> /// <param name="text">The text.</param> /// <returns>the mini request header</returns> public static MiniProfilerRequestHeader FromHeaderText(string text) { var parts = text.Split('&'); var header = new MiniProfilerRequestHeader { ParentProfilerId = Guid.Parse(parts[0]), User = parts[1], ExcludeTrivialMethods = parts[2] == "y" }; if (parts.Length > 3) header.TrivialDurationThresholdMilliseconds = decimal.Parse(parts[3]); return header; }
/// <summary> /// parse the header text, and return the resulting profiler. /// </summary> /// <param name="text">The text.</param> /// <returns>the mini request header</returns> public static MiniProfilerRequestHeader FromHeaderText(string text) { var parts = text.Split('&'); var header = new MiniProfilerRequestHeader { ParentProfilerId = Guid.Parse(parts[0]), User = parts[1], ExcludeTrivialMethods = parts[2] == "y" }; if (parts.Length > 3) { header.TrivialDurationThresholdMilliseconds = decimal.Parse(parts[3]); } return(header); }
/// <summary> /// before the send request. /// </summary> /// <param name="request">The request.</param> /// <param name="channel">The channel.</param> /// <returns>the mini profiler start</returns> public object BeforeSendRequest(ref Message request, IClientChannel channel) { // If we currently are running inside a MiniProfiler context, then add a request onto this request var miniProfiler = GetCurrentProfiler(); if (miniProfiler != null) { var header = new MiniProfilerRequestHeader { User = miniProfiler.User, ParentProfilerId = miniProfiler.Id }; // ReSharper disable PossibleUnintendedReferenceComparison if (request.Headers.MessageVersion != MessageVersion.None) // ReSharper restore PossibleUnintendedReferenceComparison { var untypedHeader = new MessageHeader <MiniProfilerRequestHeader>(header) .GetUntypedHeader(MiniProfilerRequestHeader.HeaderName, MiniProfilerRequestHeader.HeaderNamespace); request.Headers.Add(untypedHeader); } else if (_http || WebOperationContext.Current != null || channel.Via.Scheme == "http" | channel.Via.Scheme == "https") { _http = true; HttpRequestMessageProperty property = null; if (!request.Properties.ContainsKey(HttpRequestMessageProperty.Name)) { request.Properties.Add(HttpRequestMessageProperty.Name, new HttpRequestMessageProperty()); } property = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name]; property.Headers.Add(MiniProfilerRequestHeader.HeaderName, header.ToHeaderText()); } else { throw new InvalidOperationException("MVC Mini Profiler does not support EnvelopeNone unless HTTP is the transport mechanism"); } return(new MiniProfilerStart { StartTime = miniProfiler.DurationMilliseconds }); } return(null); }
public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext) { // ReSharper disable PossibleUnintendedReferenceComparison if (request.Headers.MessageVersion != MessageVersion.None) // ReSharper restore PossibleUnintendedReferenceComparison { // Check to see if we have a request as part of this message var headerIndex = request.Headers.FindHeader(MiniProfilerRequestHeader.HeaderName, MiniProfilerRequestHeader.HeaderNamespace); if (headerIndex >= 0) { var requestHeader = request.Headers.GetHeader <MiniProfilerRequestHeader>(headerIndex); if (requestHeader != null) { MiniProfiler.Settings.ProfilerProvider = new WcfRequestProfilerProvider(); MiniProfiler.Start(); return(requestHeader); } } } else if (_http || WebOperationContext.Current != null || channel.Via.Scheme == "http" | channel.Via.Scheme == "https") { _http = true; if (request.Properties.ContainsKey(HttpRequestMessageProperty.Name)) { var property = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name]; var text = property.Headers[MiniProfilerRequestHeader.HeaderName]; if (!string.IsNullOrEmpty(text)) { var header = MiniProfilerRequestHeader.FromHeaderText(text); MiniProfiler.Settings.ProfilerProvider = new WcfRequestProfilerProvider(); MiniProfiler.Start(); return(header); } } } else { throw new InvalidOperationException("MVC Mini Profiler does not support EnvelopeNone unless HTTP is the transport mechanism"); } return(null); }
/// <summary> /// before the send request. /// </summary> /// <param name="request">The request.</param> /// <param name="channel">The channel.</param> /// <returns>the mini profiler start</returns> public object BeforeSendRequest(ref Message request, IClientChannel channel) { // If we currently are running inside a MiniProfiler context, then add a request onto this request var miniProfiler = GetCurrentProfiler(); if (miniProfiler != null) { var header = new MiniProfilerRequestHeader { User = miniProfiler.User, ParentProfilerId = miniProfiler.Id }; // ReSharper disable PossibleUnintendedReferenceComparison if (request.Headers.MessageVersion != MessageVersion.None) // ReSharper restore PossibleUnintendedReferenceComparison { var untypedHeader = new MessageHeader<MiniProfilerRequestHeader>(header) .GetUntypedHeader(MiniProfilerRequestHeader.HeaderName, MiniProfilerRequestHeader.HeaderNamespace); request.Headers.Add(untypedHeader); } else if (_http || WebOperationContext.Current != null || channel.Via.Scheme == "http" | channel.Via.Scheme == "https") { _http = true; if (!request.Properties.ContainsKey(HttpRequestMessageProperty.Name)) { request.Properties.Add(HttpRequestMessageProperty.Name, new HttpRequestMessageProperty()); } HttpRequestMessageProperty property = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name]; property.Headers.Add(MiniProfilerRequestHeader.HeaderName, header.ToHeaderText()); } else throw new InvalidOperationException("MVC Mini Profiler does not support EnvelopeNone unless HTTP is the transport mechanism"); return new MiniProfilerStart { StartTime = miniProfiler.DurationMilliseconds }; } return null; }