Try Catch on Serialize
Better Relation Data
This commit is contained in:
@ -88,30 +88,13 @@ internal class Record
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int? GetIdFromUrl(string relationName, Relation relation)
|
||||
{
|
||||
int? result;
|
||||
string[] segments = relation?.Attributes is null || relation.Attributes.Name != relationName ? Array.Empty<string>() : relation.URL.Split('/');
|
||||
if (segments.Length < 2)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
if (!int.TryParse(segments[segments.Length - 1], out int id))
|
||||
result = null;
|
||||
else
|
||||
result = id;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static ReadOnlyCollection<Record> GetKeyValuePairs(ReadOnlyDictionary<int, WorkItem> keyValuePairs, WorkItem workItem, string relationName, List<bool> nests, bool keepRelations)
|
||||
{
|
||||
List<Record> results = new();
|
||||
int? childId;
|
||||
Record record;
|
||||
nests.Add(true);
|
||||
WorkItem? childWorkItem;
|
||||
WorkItem? parentWorkItem;
|
||||
WorkItem? relationWorkItem;
|
||||
List<WorkItem> collection = new();
|
||||
ReadOnlyCollection<Record> childRecords;
|
||||
ReadOnlyCollection<Record> relatedRecords;
|
||||
@ -121,12 +104,13 @@ internal class Record
|
||||
collection.Clear();
|
||||
foreach (Relation relation in workItem.Relations)
|
||||
{
|
||||
childId = GetIdFromUrl(relationName, relation);
|
||||
if (childId is not null && workItem.Parent is not null && relation?.URL is not null && relation.URL.Contains(workItem.Parent.Value.ToString()))
|
||||
if (relation.Attributes.Name != relationName)
|
||||
continue;
|
||||
if (childId is null || !keyValuePairs.TryGetValue(childId.Value, out childWorkItem))
|
||||
if (workItem.Parent is not null && relation.Id == workItem.Parent.Value)
|
||||
continue;
|
||||
collection.Add(childWorkItem);
|
||||
if (!keyValuePairs.TryGetValue(relation.Id, out relationWorkItem))
|
||||
continue;
|
||||
collection.Add(relationWorkItem);
|
||||
}
|
||||
collection = (from l in collection orderby l.State != "Closed", l.Id select l).ToList();
|
||||
foreach (WorkItem w in collection)
|
||||
@ -138,14 +122,9 @@ internal class Record
|
||||
else
|
||||
_ = keyValuePairs.TryGetValue(w.Parent.Value, out parentWorkItem);
|
||||
childRecords = GetKeyValuePairs(keyValuePairs, w, "Child", nests, keepRelations); // Forward
|
||||
// records = GetKeyValuePairs(keyValuePairs, w, "Predecessor", nests); // Reverse
|
||||
// successorRecords = GetKeyValuePairs(keyValuePairs, w, "Successor", nests); // Forward
|
||||
// if (successorRecords.Count > 0)
|
||||
// {
|
||||
// if (successorRecords.Count > 0)
|
||||
// { }
|
||||
// }
|
||||
successorRecords = new(Array.Empty<Record>());
|
||||
// predecessorRecords = GetKeyValuePairs(keyValuePairs, w, "Predecessor", nests); // Reverse
|
||||
relatedRecords = GetKeyValuePairs(keyValuePairs, w, "Related", nests, keepRelations); // Related
|
||||
record = Get(w, parentWorkItem, childRecords, relatedRecords, successorRecords, keepRelations);
|
||||
results.Add(record);
|
||||
@ -160,4 +139,10 @@ internal class Record
|
||||
[JsonSerializable(typeof(Record))]
|
||||
internal partial class RecordSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSerializable(typeof(Record[]))]
|
||||
internal partial class RecordCollectionSourceGenerationContext : JsonSerializerContext
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user