diff --git a/MistWX-i2Me/API/Products/AlertDetailsProduct.cs b/MistWX-i2Me/API/Products/AlertDetailsProduct.cs index 8d49e1d..97a7d5a 100644 --- a/MistWX-i2Me/API/Products/AlertDetailsProduct.cs +++ b/MistWX-i2Me/API/Products/AlertDetailsProduct.cs @@ -5,6 +5,7 @@ using MistWX_i2Me.Schema.ibm; using System.Data.SqlTypes; using System.Data.SQLite; using MistWX_i2Me.Schema.System; +using System.Text.Json.Serialization; namespace MistWX_i2Me.API.Products; @@ -42,7 +43,7 @@ public class AlertDetailsProduct : Base using (var stream = StreamFromString(res)) { - AlertDetailResponse? response = await JsonSerializer.DeserializeAsync(stream); + AlertDetailResponse? response = await JsonSerializer.DeserializeAsync(stream, new JsonSerializerOptions() {DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull}); if (response != null) { results.Add(new GenericResponse(headline.Location, res, response)); diff --git a/MistWX-i2Me/RecordGeneration/AlertBulletin.cs b/MistWX-i2Me/RecordGeneration/AlertBulletin.cs index 72571e2..ad934e7 100644 --- a/MistWX-i2Me/RecordGeneration/AlertBulletin.cs +++ b/MistWX-i2Me/RecordGeneration/AlertBulletin.cs @@ -352,6 +352,7 @@ public class AlertBulletin : I2Record { "WV", "West Virginia" }, { "WI", "Wisconsin" }, { "WY", "Wyoming" }, + { "INTL", "International" }, }; @@ -362,10 +363,19 @@ public class AlertBulletin : I2Record /// The vocal code as a string private string? MapVocalCode(string vocalCheck) { + string? output = ""; try { - string vocalKey = _vocalCodes[vocalCheck]; - return vocalKey; + if (_vocalCodes.TryGetValue(vocalCheck, out output)) + { + string vocalKey = output; + return vocalKey; + } + else + { + Log.Warning($"Vocal check failed for key {vocalCheck}."); + return ""; + } } catch (Exception ex) { @@ -404,12 +414,12 @@ public class AlertBulletin : I2Record // Timestamp parsing if (detail != null) { - string endTime = DateTimeOffset.FromUnixTimeSeconds(detail.endTimeUTC).ToString("yyyy MM dd HH mm").Replace(" ", ""); - string expireTime = DateTimeOffset.FromUnixTimeSeconds(detail.expireTimeUTC).ToString("yyyy MM dd HH mm").Replace(" ", ""); + string endTime = DateTimeOffset.FromUnixTimeSeconds((int)(detail.expireTimeUTC ?? 0)).ToString("yyyy MM dd HH mm").Replace(" ", ""); + string expireTime = DateTimeOffset.FromUnixTimeSeconds((int)(detail.expireTimeUTC?? 0)).ToString("yyyy MM dd HH mm").Replace(" ", ""); string issueTime = DateTime.Parse(detail.issueTimeLocal ?? "").ToString("yyyy MM dd HH mm").Replace(" ", ""); - string processTime = DateTimeOffset.FromUnixTimeSeconds(detail.processTimeUTC).ToString("yyyy MM dd HH mm ss").Replace(" ", ""); + string processTime = DateTimeOffset.FromUnixTimeSeconds((int)(detail.processTimeUTC ?? 0)).ToString("yyyy MM dd HH mm ss").Replace(" ", ""); - EActionCd eActionCd = new() {EActionPriority = detail.messageTypeCode}; + EActionCd eActionCd = new() {EActionPriority = (int)(detail.messageTypeCode ?? 0)}; switch (detail.messageType) { @@ -433,16 +443,31 @@ public class AlertBulletin : I2Record EETN = detail.eventTrackingNumber, EDesc = detail.eventDescription, EEndTmUTC = endTime, - ESvrty = detail.severityCode, + ESvrty = (int)(detail.severityCode ?? 0), EExpTmUTC = expireTime, EStTmUTC = locationInfo.gmtDiff ?? "" }; - BStCd stateInfo = new() + { + BSt = _states["INTL"], + Text = "INTL" + }; + try { - BSt = _states[locationInfo.stCd], - Text = locationInfo.stCd - }; + stateInfo = new() + { + BSt = _states[locationInfo.stCd], + Text = locationInfo.stCd + }; + } catch + { + stateInfo = new() + { + BSt = _states["INTL"], + Text = "INTL" + }; + } + BLocCd loc = new() { diff --git a/MistWX-i2Me/Schema/ibm/AlertDetails.cs b/MistWX-i2Me/Schema/ibm/AlertDetails.cs index 2e138f1..e8a1e53 100644 --- a/MistWX-i2Me/Schema/ibm/AlertDetails.cs +++ b/MistWX-i2Me/Schema/ibm/AlertDetails.cs @@ -3,7 +3,7 @@ namespace MistWX_i2Me.Schema.ibm; public class AlertDetail { public string? detailKey { get; set; } - public int messageTypeCode { get; set; } + public long? messageTypeCode { get; set; } public string? messageType { get; set; } public string? productIdentifier { get; set; } public string? phenomena { get; set; } @@ -15,20 +15,20 @@ public class AlertDetail public string? officeAdminDistrictCode { get; set; } public string? officeCountryCode { get; set; } public string? eventDescription { get; set; } - public int severityCode { get; set; } + public long? severityCode { get; set; } public string? severity { get; set; } public List? categories { get; set; } public List? responseTypes { get; set; } public string? urgency { get; set; } - public string? urgencyCode { get; set; } + public long? urgencyCode { get; set; } public string? certainty { get; set; } - public string? certaintyCode { get; set; } - public DateTime? effectiveTimeLocal { get; set; } + public long? certaintyCode { get; set; } + public string? effectiveTimeLocal { get; set; } public string? effectiveTimeLocalTimeZone { get; set; } - public DateTime? expireTimeLocal { get; set; } + public string? expireTimeLocal { get; set; } public string? expireTimeLocalTimeZone { get; set; } - public long expireTimeUTC { get; set; } - public DateTime? onsetTimeLocal { get; set; } + public long? expireTimeUTC { get; set; } + public string? onsetTimeLocal { get; set; } public string? onsetTimeLocalTimeZone { get; set; } public Flood? flood { get; set; } public string? areaTypeCode { get; set; } @@ -47,10 +47,9 @@ public class AlertDetail public string? issueTimeLocal { get; set; } public string? issueTimeLocalTimeZone { get; set; } public string? identifier { get; set; } - public long processTimeUTC { get; set; } - public DateTime? endTimeLocal { get; set; } + public long? processTimeUTC { get; set; } + public string? endTimeLocal { get; set; } public string? endTimeLocalTimeZone { get; set; } - public long endTimeUTC { get; set; } public List? texts { get; set; } public List? polygon { get; set; } public string? synopsis { get; set; } @@ -60,7 +59,7 @@ public class AlertDetail public class Category { public string? category { get; set; } - public int? categoryCode { get; set; } + public long? categoryCode { get; set; } } public class Flood @@ -90,7 +89,7 @@ public class Polygon public class ResponseType { public string? responseType { get; set; } - public int? responseTypeCode { get; set; } + public long? responseTypeCode { get; set; } } public class AlertDetailResponse