/// <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; } } }
public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState) { var requestHeader = correlationState as MiniProfilerRequestHeader; MiniProfiler.Stop(); var miniProfiler = MiniProfiler.Current; if (miniProfiler != null && requestHeader != null) { if (requestHeader.ExcludeTrivialMethods) { miniProfiler.Root.RemoveTrivialTimings(); } var header = new MiniProfilerResultsHeader { ProfilerResults = miniProfiler }; if (reply.Headers.MessageVersion != MessageVersion.None) { var untypedHeader = new MessageHeader <MiniProfilerResultsHeader>(header) .GetUntypedHeader(MiniProfilerResultsHeader.HeaderName, MiniProfilerResultsHeader.HeaderNamespace); reply.Headers.Add(untypedHeader); } else if (_http || reply.Properties.ContainsKey(HttpResponseMessageProperty.Name)) { _http = true; HttpResponseMessageProperty property = (HttpResponseMessageProperty)reply.Properties[HttpResponseMessageProperty.Name]; string text = header.ToHeaderText(); property.Headers.Add(MiniProfilerResultsHeader.HeaderName, text); } else { throw new InvalidOperationException("MVC Mini Profiler does not support EnvelopeNone unless HTTP is the transport mechanism"); } } //try //{ // var arrayOfIds = Settings.Storage.GetUnviewedIds(current.User).ToJson(); // // allow profiling of ajax requests // response.AppendHeader("X-MiniProfiler-Ids", arrayOfIds); //} //catch { } // headers blew up }
/// <summary> /// Write the header to a byte stream. /// </summary> /// <param name="header">The header.</param> /// <returns>The serialized data.</returns> private static byte[] Write(MiniProfilerResultsHeader header) { var serializer = new DataContractSerializer(typeof(MiniProfilerResultsHeader), HeaderName, HeaderNamespace); using (var stream = new MemoryStream()) { using (var writer = new XmlTextWriter(stream, Encoding.Unicode)) { writer.WriteStartElement(HeaderName, HeaderNamespace); serializer.WriteObjectContent(writer, header); writer.WriteEndElement(); writer.Flush(); byte[] buffer = stream.GetBuffer(); Array.Resize(ref buffer, (int)stream.Length); return buffer; } } }
public void BeforeSendReply(ref System.ServiceModel.Channels.Message reply, object correlationState) { var requestHeader = correlationState as MiniProfilerRequestHeader; MiniProfiler.Stop(); var miniProfiler = MiniProfiler.Current; if (miniProfiler != null && requestHeader != null) { if (requestHeader.ExcludeTrivialMethods) { miniProfiler.Root.RemoveTrivialTimings(); } var header = new MiniProfilerResultsHeader { ProfilerResults = miniProfiler }; if (reply.Headers.MessageVersion != MessageVersion.None) { var untypedHeader = new MessageHeader<MiniProfilerResultsHeader>(header) .GetUntypedHeader(MiniProfilerResultsHeader.HeaderName, MiniProfilerResultsHeader.HeaderNamespace); reply.Headers.Add(untypedHeader); } else if (_http || reply.Properties.ContainsKey(HttpResponseMessageProperty.Name)) { _http = true; HttpResponseMessageProperty property = (HttpResponseMessageProperty)reply.Properties[HttpResponseMessageProperty.Name]; string text = header.ToHeaderText(); property.Headers.Add(MiniProfilerResultsHeader.HeaderName, text); } else throw new InvalidOperationException("MVC Mini Profiler does not support EnvelopeNone unless HTTP is the transport mechanism"); } //try //{ // var arrayOfIds = Settings.Storage.GetUnviewedIds(current.User).ToJson(); // // allow profiling of ajax requests // response.AppendHeader("X-MiniProfiler-Ids", arrayOfIds); //} //catch { } // headers blew up }
/// <summary> /// Write the header to a byte stream. /// </summary> /// <param name="header">The header.</param> /// <returns>The serialized data.</returns> private static byte[] Write(MiniProfilerResultsHeader header) { var serializer = new DataContractSerializer(typeof(MiniProfilerResultsHeader), HeaderName, HeaderNamespace); using (var stream = new MemoryStream()) { using (var writer = new XmlTextWriter(stream, Encoding.Unicode)) { writer.WriteStartElement(HeaderName, HeaderNamespace); serializer.WriteObjectContent(writer, header); writer.WriteEndElement(); writer.Flush(); byte[] buffer = stream.GetBuffer(); Array.Resize(ref buffer, (int)stream.Length); return(buffer); } } }
/// <summary> /// before the reply is sent. /// </summary> /// <param name="reply">The reply.</param> /// <param name="correlationState">The correlation state.</param> public void BeforeSendReply(ref Message reply, object correlationState) { var requestHeader = correlationState as MiniProfilerRequestHeader; MiniProfiler.Stop(); var miniProfiler = MiniProfiler.Current; if (miniProfiler != null && requestHeader != null) { if (requestHeader.ExcludeTrivialMethods) { miniProfiler.Root.RemoveTrivialTimings(); } var header = new MiniProfilerResultsHeader { ProfilerResults = miniProfiler }; // ReSharper disable PossibleUnintendedReferenceComparison if (reply.Headers.MessageVersion != MessageVersion.None) // ReSharper restore PossibleUnintendedReferenceComparison { var untypedHeader = new MessageHeader <MiniProfilerResultsHeader>(header) .GetUntypedHeader(MiniProfilerResultsHeader.HeaderName, MiniProfilerResultsHeader.HeaderNamespace); reply.Headers.Add(untypedHeader); } else if (_http || reply.Properties.ContainsKey(HttpResponseMessageProperty.Name)) { _http = true; var property = (HttpResponseMessageProperty)reply.Properties[HttpResponseMessageProperty.Name]; string text = header.ToHeaderText(); property.Headers.Add(MiniProfilerResultsHeader.HeaderName, text); } else { throw new InvalidOperationException("MVC Mini Profiler does not support EnvelopeNone unless HTTP is the transport mechanism"); } } }
/// <summary> /// before the reply is sent. /// </summary> /// <param name="reply">The reply.</param> /// <param name="correlationState">The correlation state.</param> public void BeforeSendReply(ref Message reply, object correlationState) { var requestHeader = correlationState as MiniProfilerRequestHeader; MiniProfiler.Stop(); var miniProfiler = MiniProfiler.Current; if (miniProfiler != null && requestHeader != null) { if (requestHeader.ExcludeTrivialMethods) { miniProfiler.Root.RemoveTrivialTimings(); } var header = new MiniProfilerResultsHeader { ProfilerResults = miniProfiler }; // ReSharper disable PossibleUnintendedReferenceComparison if (reply.Headers.MessageVersion != MessageVersion.None) // ReSharper restore PossibleUnintendedReferenceComparison { var untypedHeader = new MessageHeader<MiniProfilerResultsHeader>(header) .GetUntypedHeader(MiniProfilerResultsHeader.HeaderName, MiniProfilerResultsHeader.HeaderNamespace); reply.Headers.Add(untypedHeader); } else if (_http || reply.Properties.ContainsKey(HttpResponseMessageProperty.Name)) { _http = true; var property = (HttpResponseMessageProperty)reply.Properties[HttpResponseMessageProperty.Name]; string text = header.ToHeaderText(); property.Headers.Add(MiniProfilerResultsHeader.HeaderName, text); } else throw new InvalidOperationException("MVC Mini Profiler does not support EnvelopeNone unless HTTP is the transport mechanism"); } }