-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Reporting Service #2218
Fix Reporting Service #2218
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,17 +77,29 @@ public static string ToJson(this JsonElement element, JsonWriterOptions? options | |
|
||
if (property == null) return defaultValue; | ||
var node = (JsonElement)property; | ||
var type = typeof(T); | ||
return node.ValueKind switch | ||
{ | ||
JsonValueKind.String => !typeof(T).IsEnum ? | ||
(T)Convert.ChangeType($"{node.GetString()}".Trim(), typeof(T)) : | ||
(T)Enum.Parse(typeof(T), node.GetString() ?? ""), | ||
JsonValueKind.String => ((Func<T?>)(() => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed parsing issue with nullable enum values |
||
{ | ||
var isNullableEnum = type.IsNullable() && Nullable.GetUnderlyingType(type)?.IsEnum == true; | ||
if (isNullableEnum) | ||
{ | ||
var eType = Nullable.GetUnderlyingType(type); | ||
if (eType != null && Enum.TryParse(eType, node.GetString(), true, out var value)) | ||
{ | ||
return (T)value; | ||
} | ||
return defaultValue; | ||
} | ||
return type.IsEnum ? (T)Enum.Parse(type, node.GetString() ?? "") : (T)Convert.ChangeType($"{node.GetString()}".Trim(), type); | ||
}))(), | ||
JsonValueKind.Null or JsonValueKind.Undefined => defaultValue, | ||
JsonValueKind.Number => node.ConvertNumberTo<T>(), | ||
JsonValueKind.True or JsonValueKind.False => (T)(object)node.GetBoolean(), | ||
JsonValueKind.Object => node.Deserialize<T>(options), | ||
JsonValueKind.Array => node.Deserialize<T>(options), | ||
_ => (T)Convert.ChangeType($"{node}", typeof(T)), | ||
_ => (T)Convert.ChangeType($"{node}", type), | ||
}; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,24 +118,5 @@ public string GetEmail() | |
{ | ||
return String.IsNullOrWhiteSpace(this.PreferredEmail) ? this.Email : this.PreferredEmail; | ||
} | ||
|
||
/// <summary> | ||
/// Get the preferred email if it has been set. | ||
/// </summary> | ||
/// <returns></returns> | ||
public string[] GetEmails() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not needed |
||
{ | ||
if (this.AccountType == Entities.UserAccountType.Distribution) | ||
{ | ||
var addresses = this.Preferences.GetElementValue<API.Models.UserEmailModel[]?>(".addresses"); | ||
if (addresses != null) return addresses.Select(a => a.Email).ToArray(); | ||
return Array.Empty<string>(); | ||
} | ||
else | ||
{ | ||
var email = String.IsNullOrWhiteSpace(this.PreferredEmail) ? this.Email : this.PreferredEmail; | ||
return new string[] { email }; | ||
} | ||
} | ||
#endregion | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,7 +153,7 @@ public override async Task RunAsync() | |
} | ||
else | ||
{ | ||
// Auto-reset time delay hasnt passed yet. | ||
// Auto-reset time delay hasn't passed yet. | ||
this.Logger.LogWarning("Ingest [{name}] has reached maximum failure limit. Auto-reset will occur at [{timestamp}]", ingest.Name, ingest.LastRanOn!.Value.AddMilliseconds(ingest.ResetRetryAfterDelayMs).ToLocalTime()); | ||
continue; | ||
} | ||
|
@@ -182,7 +182,7 @@ public override async Task RunAsync() | |
// Reached limit return to ingest manager, send email. | ||
if (manager.Ingest.FailedAttempts >= manager.Ingest.RetryLimit) | ||
{ | ||
await this.SendEmailAsync($"Ingest [{ingest.Name}] failed. Reached [{manager.Ingest.RetryLimit}] maximum retries.", ex); | ||
await this.SendErrorEmailAsync($"Ingest [{ingest.Name}] failed. Reached [{manager.Ingest.RetryLimit}] maximum retries.", ex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed method to make it clear |
||
} | ||
} | ||
catch (Exception ex) | ||
|
@@ -195,7 +195,7 @@ public override async Task RunAsync() | |
// Reached limit return to ingest manager, send email. | ||
if (manager.Ingest.FailedAttempts >= manager.Ingest.RetryLimit) | ||
{ | ||
await this.SendEmailAsync($"Ingest ['{ingest.Name}'] failed. Reached [{manager.Ingest.RetryLimit}] maximum retries.", ex); | ||
await this.SendErrorEmailAsync($"Ingest ['{ingest.Name}'] failed. Reached [{manager.Ingest.RetryLimit}] maximum retries.", ex); | ||
} | ||
} | ||
} | ||
|
@@ -281,7 +281,7 @@ public virtual async Task<IEnumerable<IngestModel>> GetIngestsAsync() | |
{ | ||
this.Logger.LogError(ex, "Failed to fetch ingests for ingest type '{type}'", ingestType); | ||
this.State.RecordFailure(); | ||
await this.SendEmailAsync($"Failed to fetch ingests for ingest type '{ingestType}", ex); | ||
await this.SendErrorEmailAsync($"Failed to fetch ingests for ingest type '{ingestType}", ex); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to change to JsonDocument because it was being used inconsistently with a dynamic object.