-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
736 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using BDMS.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace BDMS; | ||
|
||
public static class BoreholeExtensions | ||
{ | ||
public static IQueryable<Borehole> GetAllWithIncludes(this DbSet<Borehole> boreholes) | ||
{ | ||
return boreholes.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerColorCodes) | ||
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerDebrisCodes) | ||
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerGrainAngularityCodes) | ||
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerGrainShapeCodes) | ||
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerOrganicComponentCodes) | ||
.Include(b => b.Stratigraphies).ThenInclude(s => s.Layers).ThenInclude(l => l.LayerUscs3Codes) | ||
.Include(b => b.Stratigraphies).ThenInclude(s => s.LithologicalDescriptions) | ||
.Include(b => b.Stratigraphies).ThenInclude(s => s.FaciesDescriptions) | ||
.Include(b => b.Stratigraphies).ThenInclude(s => s.ChronostratigraphyLayers) | ||
.Include(b => b.Stratigraphies).ThenInclude(s => s.LithostratigraphyLayers) | ||
.Include(b => b.Completions).ThenInclude(c => c.Casings).ThenInclude(c => c.CasingElements) | ||
.Include(b => b.Completions).ThenInclude(c => c.Instrumentations) | ||
.Include(b => b.Completions).ThenInclude(c => c.Backfills) | ||
.Include(b => b.Sections).ThenInclude(s => s.SectionElements) | ||
.Include(b => b.Observations).ThenInclude(o => (o as FieldMeasurement)!.FieldMeasurementResults) | ||
.Include(b => b.Observations).ThenInclude(o => (o as Hydrotest)!.HydrotestResults) | ||
.Include(b => b.Observations).ThenInclude(o => (o as Hydrotest)!.HydrotestEvaluationMethodCodes) | ||
.Include(b => b.Observations).ThenInclude(o => (o as Hydrotest)!.HydrotestFlowDirectionCodes) | ||
.Include(b => b.Observations).ThenInclude(o => (o as Hydrotest)!.HydrotestKindCodes) | ||
.Include(b => b.BoreholeCodelists) | ||
.Include(b => b.Workflows) | ||
.Include(b => b.BoreholeFiles) | ||
.Include(b => b.BoreholeGeometry) | ||
.Include(b => b.Workgroup) | ||
.Include(b => b.UpdatedBy); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using BDMS.Models; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BDMS.Controllers; | ||
|
||
/// <summary> | ||
/// Serializes and deserializes <see cref="Observation"/> objects based on their ObservationType. | ||
/// </summary> | ||
public class ObservationConverter : JsonConverter<Observation> | ||
{ | ||
private static readonly JsonSerializerOptions observationDefaultOptions = new JsonSerializerOptions | ||
{ | ||
PropertyNameCaseInsensitive = true, | ||
ReferenceHandler = ReferenceHandler.IgnoreCycles, | ||
}; | ||
|
||
/// <inheritdoc/> | ||
public override Observation? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
using JsonDocument doc = JsonDocument.ParseValue(ref reader); | ||
var jsonObject = doc.RootElement; | ||
|
||
// Deserialize the observation type to determine the observation type | ||
var observation = JsonSerializer.Deserialize<Observation>(jsonObject.GetRawText(), observationDefaultOptions); | ||
|
||
return observation.Type switch | ||
{ | ||
ObservationType.Hydrotest => JsonSerializer.Deserialize<Hydrotest>(jsonObject.GetRawText(), options), | ||
ObservationType.FieldMeasurement => JsonSerializer.Deserialize<FieldMeasurement>(jsonObject.GetRawText(), options), | ||
ObservationType.WaterIngress => JsonSerializer.Deserialize<WaterIngress>(jsonObject.GetRawText(), options), | ||
ObservationType.GroundwaterLevelMeasurement => JsonSerializer.Deserialize<GroundwaterLevelMeasurement>(jsonObject.GetRawText(), options), | ||
_ => observation, | ||
}; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public override void Write(Utf8JsonWriter writer, Observation value, JsonSerializerOptions options) | ||
{ | ||
switch (value) | ||
{ | ||
case Hydrotest hydrotest: | ||
hydrotest.EvaluationMethodCodelistIds = hydrotest.HydrotestEvaluationMethodCodes?.Select(x => x.CodelistId).ToList(); | ||
hydrotest.FlowDirectionCodelistIds = hydrotest.HydrotestFlowDirectionCodes?.Select(x => x.CodelistId).ToList(); | ||
hydrotest.KindCodelistIds = hydrotest.HydrotestKindCodes?.Select(x => x.CodelistId).ToList(); | ||
JsonSerializer.Serialize(writer, hydrotest, options); | ||
break; | ||
case FieldMeasurement fieldMeasurement: | ||
JsonSerializer.Serialize(writer, fieldMeasurement, options); | ||
break; | ||
case WaterIngress waterIngress: | ||
JsonSerializer.Serialize(writer, waterIngress, options); | ||
break; | ||
case GroundwaterLevelMeasurement groundwaterLevelMeasurement: | ||
JsonSerializer.Serialize(writer, groundwaterLevelMeasurement, options); | ||
break; | ||
case Observation observation: | ||
JsonSerializer.Serialize(writer, observation, options); | ||
break; | ||
default: | ||
throw new NotSupportedException("Observation type is not supported"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.