Exemplo n.º 1
0
 public void Write(CodeStatDataCollection codeStatDataCollection)
 {
     if (_type == CodeStatWriterType.JSON)
     {
         WriteToJson(codeStatDataCollection);
     }
     else
     {
         throw new ArgumentException("Unsupported type");
     }
 }
Exemplo n.º 2
0
        private void WriteToJson(CodeStatDataCollection codeStatDataCollection)
        {
            using (var w = new StreamWriter(_outputFileName))
            {
                var jwriter = new JsonTextWriter(w)
                {
                    Formatting = Formatting.Indented
                };

                jwriter.WriteStartObject();
                foreach (var source in codeStatDataCollection.GroupBy(arg => arg.Entry.ScriptFileName))
                {
                    jwriter.WritePropertyName(source.Key, true);
                    jwriter.WriteStartObject();

                    jwriter.WritePropertyName("#path");
                    jwriter.WriteValue(source.Key);
                    foreach (var method in source.GroupBy(arg => arg.Entry.SubName))
                    {
                        jwriter.WritePropertyName(method.Key, true);
                        jwriter.WriteStartObject();

                        foreach (var entry in method.OrderBy(kv => kv.Entry.LineNumber))
                        {
                            jwriter.WritePropertyName(entry.Entry.LineNumber.ToString());
                            jwriter.WriteStartObject();

                            jwriter.WritePropertyName("count");
                            jwriter.WriteValue(entry.ExecutionCount);

                            jwriter.WritePropertyName("time");
                            jwriter.WriteValue(entry.TimeElapsed);

                            jwriter.WriteEndObject();
                        }

                        jwriter.WriteEndObject();
                    }

                    jwriter.WriteEndObject();
                }

                jwriter.WriteEndObject();
                jwriter.Flush();
            }
        }