Exemplo n.º 1
0
        /// <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);
        }
        /// <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;
        }
        /// <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()
            });
        }