public static void WriteScanJson(int ResultType, string BaseId, string CompareId, bool ExportAll, string OutputPath) { List <RESULT_TYPE> ToExport = new List <RESULT_TYPE> { (RESULT_TYPE)ResultType }; Dictionary <RESULT_TYPE, int> actualExported = new Dictionary <RESULT_TYPE, int>(); JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings() { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore, Converters = new List <JsonConverter>() { new StringEnumConverter() } }); if (ExportAll) { ToExport = new List <RESULT_TYPE> { RESULT_TYPE.FILE, RESULT_TYPE.CERTIFICATE, RESULT_TYPE.PORT, RESULT_TYPE.REGISTRY, RESULT_TYPE.SERVICE, RESULT_TYPE.USER }; } foreach (RESULT_TYPE ExportType in ToExport) { Log.Information("Exporting {0}", ExportType); List <CompareResult> records = DatabaseManager.GetComparisonResults(AsaHelpers.RunIdsToCompareId(BaseId, CompareId), ExportType); actualExported.Add(ExportType, records.Count); if (records.Count > 0) { serializer.Converters.Add(new StringEnumConverter()); var o = new Dictionary <string, Object>(); o["results"] = records; o["metadata"] = AsaHelpers.GenerateMetadata(); using (StreamWriter sw = new StreamWriter(Path.Combine(OutputPath, AsaHelpers.MakeValidFileName(BaseId + "_vs_" + CompareId + "_" + ExportType.ToString() + ".json.txt")))) //lgtm [cs/path-injection] { using (JsonWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(writer, o); } } } } serializer.Converters.Add(new StringEnumConverter()); var output = new Dictionary <string, Object>(); output["results"] = actualExported; output["metadata"] = AsaHelpers.GenerateMetadata(); using (StreamWriter sw = new StreamWriter(Path.Combine(OutputPath, AsaHelpers.MakeValidFileName(BaseId + "_vs_" + CompareId + "_summary.json.txt")))) //lgtm [cs/path-injection] { using (JsonWriter writer = new JsonTextWriter(sw)) { serializer.Serialize(writer, output); } } }
public ActionResult GetResults(string BaseId, string CompareId, int ResultType, int Offset, int NumResults) { List <CompareResult> results = DatabaseManager.GetComparisonResults(AsaHelpers.RunIdsToCompareId(BaseId, CompareId), ResultType, Offset, NumResults); Dictionary <string, object> output = new Dictionary <string, object>(); output["Results"] = results; output["TotalCount"] = DatabaseManager.GetComparisonResultsCount(AsaHelpers.RunIdsToCompareId(BaseId, CompareId), ResultType); output["Offset"] = Offset; output["Requested"] = NumResults; output["Actual"] = results.Count; return(Json(JsonConvert.SerializeObject(output))); }
public ActionResult GetResults(string BaseId, string CompareId, int ResultType, int Offset, int NumResults) { var results = new List <CompareResult>(); using (var cmd = new SqliteCommand(GET_COMPARISON_RESULTS, DatabaseManager.Connection, DatabaseManager.Transaction)) { cmd.Parameters.AddWithValue("@comparison_id", AsaHelpers.RunIdsToCompareId(BaseId, CompareId)); cmd.Parameters.AddWithValue("@result_type", ResultType); cmd.Parameters.AddWithValue("@offset", Offset); cmd.Parameters.AddWithValue("@limit", NumResults); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var obj = JsonConvert.DeserializeObject <CompareResult>(reader["serialized"].ToString()); results.Add(obj); } } } Dictionary <string, object> output = new Dictionary <string, object>(); var result_count = 0; using (var cmd = new SqliteCommand(GET_RESULT_COUNT, DatabaseManager.Connection, DatabaseManager.Transaction)) { cmd.Parameters.AddWithValue("@comparison_id", AsaHelpers.RunIdsToCompareId(BaseId, CompareId)); cmd.Parameters.AddWithValue("@result_type", ResultType); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { result_count = int.Parse(reader["count(*)"].ToString(), CultureInfo.InvariantCulture); } } } output["Results"] = results; output["TotalCount"] = result_count; output["Offset"] = Offset; output["Requested"] = NumResults; output["Actual"] = results.Count; return(Json(JsonConvert.SerializeObject(output))); }