Skip to content

Commit

Permalink
muted warnings in Process, cleaned up Process test
Browse files Browse the repository at this point in the history
  • Loading branch information
jackschonherr committed Aug 28, 2024
1 parent c390072 commit 6cb2f02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
16 changes: 14 additions & 2 deletions Consequences/Consequences/NSIStreamingProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public async Task Process(BoundingBox boundingBox, Action<IConsequencesReceptor>

private static string ConstructURL(BoundingBox boundingBox, string directive)
{
StringBuilder url = new StringBuilder();
StringBuilder url = new();

url.Append("https://nsi.sec.usace.army.mil/nsiapi/structures?bbox=");
url.Append(boundingBox.NSIFormat());
Expand All @@ -31,7 +31,7 @@ private static async Task ProcessCollection(BoundingBox boundingBox, Action<ICon
{
string apiUrl = ConstructURL(boundingBox, "&fmt=fc");

using HttpClient client = new HttpClient();
using HttpClient client = new();
try
{
string jsonResponse = await client.GetStringAsync(apiUrl);
Expand All @@ -43,7 +43,13 @@ private static async Task ProcessCollection(BoundingBox boundingBox, Action<ICon
{
// access the properties of each structure
JsonElement propertiesElement = structure.GetProperty("properties");

// disable the warnings generated by Deserialize
#pragma warning disable IL2026
#pragma warning disable IL3050
Structure s = JsonSerializer.Deserialize<Structure>(propertiesElement.GetRawText());
#pragma warning restore IL2026
#pragma warning restore IL3050

// apply the action to the deserialized structure
ConsequenceReceptorProcess(s);
Expand Down Expand Up @@ -75,7 +81,13 @@ private static async Task ProcessStream(BoundingBox boundingBox, Action<IConsequ
{
using JsonDocument structure = JsonDocument.Parse(line);
JsonElement propertiesElement = structure.RootElement.GetProperty("properties");

// disable the warnings generated by Deserialize
#pragma warning disable IL2026
#pragma warning disable IL3050
Structure s = JsonSerializer.Deserialize<Structure>(propertiesElement.GetRawText());
#pragma warning restore IL2026
#pragma warning restore IL3050

// apply the action to the deserialized structure
ConsequenceReceptorProcess(s);
Expand Down
9 changes: 6 additions & 3 deletions ConsequencesTest/NSIStreamingProcessorTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.Json;
using USACE.HEC.Consequences;
using USACE.HEC.Geography;
using USACE.HEC.Hazards;
using USACE.HEC.Results;

Expand All @@ -8,14 +9,16 @@ namespace ConsequencesTest;
public class NSIStreamingProcessorTest
{
[Fact]
public void Test()
public async Task Test()
{
IBBoxStreamingProcessor sp = new NSIStreamingProcessor();
// int i = 0;
IHazardProvider depthHazardProvider = new RandomDepthHazardProvider(25);
Location upperLeft1 = new Location { X = -122.475275, Y = 37.752394 };
Location lowerRight1 = new Location { X = -122.473523, Y = 37.750642 };
depthHazardProvider.Extent = new BoundingBox(upperLeft1, lowerRight1);
IResultsWriter consoleWriter = new ConsoleWriter();

sp.Process(depthHazardProvider.Extent, (IConsequencesReceptor s) => {
await sp.Process(depthHazardProvider.Extent, (IConsequencesReceptor s) => {
Result r = s.Compute(depthHazardProvider.Hazard(s.GetLocation()));
consoleWriter.Write(r);
});
Expand Down

0 comments on commit 6cb2f02

Please sign in to comment.