Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
fix: json validation
Browse files Browse the repository at this point in the history
See merge request Linaro/WindowsPerf/wpa-plugin!20

=== ChangeLog ===

* fix: json validation
  • Loading branch information
Alaaeddine-chakroun committed May 9, 2024
1 parent edd38a7 commit df8361c
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions WPAPlugin/WperfProcessingSourceWithSourceParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


using Microsoft.Performance.SDK.Processing;
using NJsonSchema;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Performance.SDK.Processing;
using NJsonSchema;
using WPAPlugin.Schemas;

namespace WPAPlugin
Expand Down Expand Up @@ -64,7 +64,7 @@ public override ProcessingSourceInfo GetAboutInfo()
new ContactInfo
{
Name = "Alaaeddine Chakroun",
EmailAddresses = new[]{ "alaaeddine.chakroun@daydevs.com" }
EmailAddresses = new[] { "alaaeddine.chakroun@daydevs.com" }
},
},
ProjectInfo = new ProjectInfo
Expand Down Expand Up @@ -92,6 +92,7 @@ ProcessorOptions options

timelinePathList.Clear();
countingPathList.Clear();
validationCache.Clear();
return new WperfCustomDataProcessorWithSourceParser(
parser,
options,
Expand All @@ -100,9 +101,8 @@ ProcessorOptions options
);
}


private static Dictionary<(string, string), bool> validationCache = new Dictionary<(string, string), bool>();

private static Dictionary<(string, string), bool> validationCache =
new Dictionary<(string, string), bool>();

private static bool ValidateJson(string sourcePath, JsonSchemas.Schemas schema)
{
Expand All @@ -111,7 +111,8 @@ private static bool ValidateJson(string sourcePath, JsonSchemas.Schemas schema)
{
return validationCache[cacheKey];
}
var parsedSchema = JsonSchema.FromSampleJson(JsonSchemas.GetSchemaByKey(schema));
var selectedSchema = JsonSchemas.GetSchemaByKey(schema);
var parsedSchema = JsonSchema.FromJsonAsync(selectedSchema).Result;
var jsonContent = File.ReadAllText(sourcePath);
var errors = parsedSchema.Validate(jsonContent);

Expand Down

0 comments on commit df8361c

Please sign in to comment.