public string Handle(Process[] processes) {
     var sw = new StringWriter();
     var writer = new JsonTextWriter(sw);
     foreach (var process in processes) {
         writer.WriteStartArray();
         foreach (var row in process.Results) {
             writer.WriteStartArray();
             foreach (var alias in process.OutputFields().Aliases()) {
                 writer.WriteValue(row[alias]);
             }
             writer.WriteEndArray();
         }
         writer.WriteEndArray();
     }
     writer.Flush();
     return sw.ToString();
 }
예제 #2
0
 public static string LogsToJson(IEnumerable<string[]> logs) {
     var sw = new StringWriter();
     var writer = new JsonTextWriter(sw);
     writer.WriteStartArray();
     foreach (var log in logs) {
         if (log.Length <= 4)
             continue;
         writer.WriteStartObject(); //add
         writer.WritePropertyName("time");
         writer.WriteValue(log[0]);
         writer.WritePropertyName("level");
         writer.WriteValue(log[1].TrimEnd());
         writer.WritePropertyName("process");
         writer.WriteValue(log[2]);
         writer.WritePropertyName("entity");
         writer.WriteValue(log[3]);
         writer.WritePropertyName("message");
         writer.WriteValue(log[4].TrimEnd(new[] { ' ', '\r', '\n' }));
         writer.WriteEndObject(); //add
     }
     writer.WriteEndArray();
     writer.Flush();
     return sw.ToString();
 }