public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var st = new Stopwatch();

            st.Start();

#if DEBUG
            SerializationStatistics stats = null;
#endif

            AppChangesResponse response = (AppChangesResponse)value;
            writer.WriteStartObject();
            writer.WritePropertyName("MDT");
            serializer.Serialize(writer, response.MDT);
            writer.WritePropertyName("NV");
            serializer.Serialize(writer, response.NV);
            writer.Flush();
            writer.WritePropertyName("MD");
            writer.WriteStartArray();
            for (int i = 0; i < response.MD.Count; i++)
            {
#if DEBUG
                if (CollectStats)
                {
                    var stringWriter = new StringWriter();
                    var obj          = response.MD[i];
                    st.Reset();
                    st.Start();
                    serializer.Serialize(stringWriter, response.MD[i]);
                    var result = stringWriter.ToString();
                    writer.WriteRawValue(result);
                    st.Stop();
                    stats = stats ?? new SerializationStatistics();
                    stats.Register(response.MD[i], result, st.ElapsedMilliseconds);
                }
                else
                {
#endif
                serializer.Serialize(writer, response.MD[i]);
#if DEBUG
            }
#endif
                writer.Flush();
            }
            writer.WriteEndArray();

            writer.WritePropertyName("VD");
            serializer.Serialize(writer, response.VD);
            writer.WritePropertyName("RM");
            serializer.Serialize(writer, response.RM);
            if (response.SW != null)
            {
                writer.WritePropertyName("SW");
                serializer.Serialize(writer, response.SW);
            }
            writer.WriteEndObject();
            writer.Flush();
#if DEBUG
            if (CollectStats && stats != null)
            {
                stats.DumpStats();
            }
#endif
            st.Stop();
            System.Diagnostics.Trace.TraceInformation(">>>>>>>>>>>>>>>>> REQUEST RESPONSE Serialization time " + st.ElapsedMilliseconds);
        }
Exemplo n.º 2
0
 public ActionResult TurnOff()
 {
     Nocache();
     AppChangesResponse.TurnOffStatistics();
     return(Json("{Stats: false}", JsonRequestBehavior.AllowGet));
 }