Skip to content

Commit

Permalink
Writing extended update metadata to the query result JSON is now opti…
Browse files Browse the repository at this point in the history
…onal. This greatly reduces the JSON size when update applicability rules not required in the output.
  • Loading branch information
Almost-Done committed Sep 26, 2022
1 parent f46d325 commit 576d0ef
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/tools/upsync/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ public class QueryMetadataOptions : IMetadataStoreOptions, IMetadataFilterOption

[Option("json-out-path", Required = false, HelpText = "Save results as JSON to the specified path")]
public string JsonOutPath { get; set; }

[Option("include-extended-metadata", Required = false, Default = false, HelpText = "Include extended metadata when saving to JSON query result.")]
public bool IncludeExtendedMetadata { get; set; }
}

[Verb("match-driver", HelpText = "Find drivers")]
Expand Down
29 changes: 19 additions & 10 deletions src/tools/upsync/PackageMetadataPrint/MicrosoftUpdateMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,32 @@ public static void PrintMicrosoftUpdatePackages(QueryMetadataOptions options, IM
{
var packagesList = filteredPackages.ToList();

if (!options.IncludeExtendedMetadata)
{
// Remove extended metadata unless explicitly requested.
// Applicability rules can be very large but of little interest
packagesList.ForEach(p => p.ApplicabilityRules.Clear());
}

Console.WriteLine("-----------------------------");
Console.WriteLine($"Query returned {packagesList.Count} entries.");

Console.WriteLine($"Writing results to {options.JsonOutPath}.");

using (var targetJsonFile = File.Create(options.JsonOutPath))
if (!options.CountOnly)
{
var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Formatting = Formatting.Indented });
using (var jsonWriter = new StreamWriter(targetJsonFile))
Console.WriteLine($"Writing results to {options.JsonOutPath}.");

using (var targetJsonFile = File.Create(options.JsonOutPath))
{
serializer.Serialize(jsonWriter, packagesList);
var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Formatting = Formatting.Indented });
using (var jsonWriter = new StreamWriter(targetJsonFile))
{
serializer.Serialize(jsonWriter, packagesList);
}

}

}


Console.WriteLine($"Query result saved to {options.JsonOutPath}.");
Console.WriteLine($"Query result saved to {options.JsonOutPath}.");
}
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/tools/upsync/upsync.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<Description></Description>
<BaseOutputPath>..\..\..\out\upsync</BaseOutputPath>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<FileVersion>3.0.2.0</FileVersion>
<AssemblyVersion>3.0.2.0</AssemblyVersion>
<ProductVersion>3.0.2.0</ProductVersion>
<FileVersion>3.0.3.0</FileVersion>
<AssemblyVersion>3.0.3.0</AssemblyVersion>
<ProductVersion>3.0.3.0</ProductVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 576d0ef

Please sign in to comment.