Example #1
0
        /// <summary>
        /// after the reply is received.
        /// </summary>
        /// <param name="reply">The reply.</param>
        /// <param name="correlationState">The correlation state.</param>
        public void AfterReceiveReply(ref Message reply, object correlationState)
        {
            var profilerStart = correlationState as MiniProfilerStart;

            // Check to see if there are any results here
            var profiler = GetCurrentProfiler();

            if (profiler != null)
            {
                // Check to see if we have a request as part of this message
                MiniProfilerResultsHeader resultsHeader = null;
                // ReSharper disable PossibleUnintendedReferenceComparison
                if (reply.Headers.MessageVersion != MessageVersion.None)
                // ReSharper restore PossibleUnintendedReferenceComparison
                {
                    var headerIndex = reply.Headers.FindHeader(MiniProfilerResultsHeader.HeaderName, MiniProfilerResultsHeader.HeaderNamespace);
                    if (headerIndex >= 0)
                    {
                        resultsHeader = reply.Headers.GetHeader <MiniProfilerResultsHeader>(headerIndex);
                    }
                }
                else if (_http || reply.Properties.ContainsKey(HttpResponseMessageProperty.Name))
                {
                    _http = true;

                    var property = (HttpResponseMessageProperty)reply.Properties[HttpResponseMessageProperty.Name];

                    var text = property.Headers[MiniProfilerResultsHeader.HeaderName];
                    if (!string.IsNullOrEmpty(text))
                    {
                        resultsHeader = MiniProfilerResultsHeader.FromHeaderText(text);
                    }
                }
                else
                {
                    throw new InvalidOperationException("MVC Mini Profiler does not support EnvelopeNone unless HTTP is the transport mechanism");
                }

                if (resultsHeader != null && resultsHeader.ProfilerResults != null)
                {
                    // Update timings of profiler results
                    if (profilerStart != null)
                    {
                        resultsHeader.ProfilerResults.Root.UpdateStartMillisecondTimingsToAbsolute(profilerStart.StartTime);
                    }

                    profiler.AddProfilerResults(resultsHeader.ProfilerResults);
                    //// if (resultsHeader.ProfilerResults.HasSqlTimings)
                    //// profiler.HasSqlTimings = true;
                }
            }
        }