Skip to content

Commit 0d3a702

Browse files
committed
Fix databse payload serialization issue (#76)
Signed-off-by: Victor Chang <[email protected]>
1 parent 4633527 commit 0d3a702

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

src/Api/Storage/FileStorageInfo.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public abstract record FileStorageInfo
5050
/// <summary>
5151
/// Gets a list of workflows designated for the file.
5252
/// </summary>
53-
public string[] Workflows { get; private set; }
53+
public List<string> Workflows { get; private set; }
5454

5555
/// <summary>
5656
/// Gets or sets the DateTime that the file was received.
@@ -99,6 +99,7 @@ protected FileStorageInfo(string fileExtension)
9999
DateReceived = DateTime.UtcNow;
100100
DateUploaded = DateTime.MinValue;
101101
IsUploaded = false;
102+
Workflows = new List<string>();
102103
}
103104

104105
/// <summary>
@@ -109,7 +110,7 @@ public void SetWorkflows(params string[] workflows)
109110
{
110111
Guard.Against.NullOrEmpty(workflows, nameof(workflows));
111112

112-
Workflows = workflows.Clone() as string[];
113+
Workflows.AddRange(workflows);
113114
}
114115

115116
public virtual BlockStorageInfo ToBlockStorageInfo(string bucket)

src/Api/Storage/Payload.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public enum PayloadState
3232

3333
public const int MAX_RETRY = 3;
3434
private readonly Stopwatch _lastReceived;
35-
private readonly List<FileStorageInfo> _files;
3635
private bool _disposedValue;
3736

3837
public Guid Id { get; }
@@ -47,24 +46,23 @@ public enum PayloadState
4746

4847
public PayloadState State { get; set; }
4948

50-
[BackingField(nameof(_files))]
51-
public IReadOnlyList<FileStorageInfo> Files { get => _files; }
49+
public List<FileStorageInfo> Files { get; init; }
5250

5351
public string CorrelationId { get; init; }
5452

55-
public int Count { get => _files.Count; }
53+
public int Count { get => Files.Count; }
5654

5755
public bool HasTimedOut { get => ElapsedTime().TotalSeconds >= Timeout; }
5856

59-
public string CallingAeTitle { get => _files.OfType<DicomFileStorageInfo>().Select(p => p.CallingAeTitle).FirstOrDefault(); }
57+
public string CallingAeTitle { get => Files.OfType<DicomFileStorageInfo>().Select(p => p.CallingAeTitle).FirstOrDefault(); }
6058

61-
public string CalledAeTitle { get => _files.OfType<DicomFileStorageInfo>().Select(p => p.CalledAeTitle).FirstOrDefault(); }
59+
public string CalledAeTitle { get => Files.OfType<DicomFileStorageInfo>().Select(p => p.CalledAeTitle).FirstOrDefault(); }
6260

6361
public Payload(string key, string correlationId, uint timeout)
6462
{
6563
Guard.Against.NullOrWhiteSpace(key, nameof(key));
6664

67-
_files = new List<FileStorageInfo>();
65+
Files = new List<FileStorageInfo>();
6866
_lastReceived = new Stopwatch();
6967

7068
CorrelationId = correlationId;
@@ -80,7 +78,7 @@ public void Add(FileStorageInfo value)
8078
{
8179
Guard.Against.Null(value, nameof(value));
8280

83-
_files.Add(value);
81+
Files.Add(value);
8482
_lastReceived.Reset();
8583
_lastReceived.Start();
8684
}
@@ -107,7 +105,7 @@ protected virtual void Dispose(bool disposing)
107105
if (disposing)
108106
{
109107
_lastReceived.Stop();
110-
_files.Clear();
108+
Files.Clear();
111109
}
112110

113111
_disposedValue = true;

src/Database/PayloadConfiguration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal class PayloadConfiguration : IEntityTypeConfiguration<Payload>
1616
{
1717
public void Configure(EntityTypeBuilder<Payload> builder)
1818
{
19-
var fileStorageInfoComparer = new ValueComparer<IReadOnlyList<FileStorageInfo>>(
19+
var fileStorageInfoComparer = new ValueComparer<List<FileStorageInfo>>(
2020
(c1, c2) => c1.SequenceEqual(c2),
2121
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())),
2222
c => c.ToList());
@@ -34,7 +34,7 @@ public void Configure(EntityTypeBuilder<Payload> builder)
3434
builder.Property(j => j.Files)
3535
.HasConversion(
3636
v => JsonConvert.SerializeObject(v, jsonSerializerSettings),
37-
v => JsonConvert.DeserializeObject<IReadOnlyList<FileStorageInfo>>(v, jsonSerializerSettings))
37+
v => JsonConvert.DeserializeObject<List<FileStorageInfo>>(v, jsonSerializerSettings))
3838
.Metadata.SetValueComparer(fileStorageInfoComparer);
3939

4040
builder.Ignore(j => j.CalledAeTitle);

src/InformaticsGateway/Services/Connectors/PayloadNotificationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private async Task Upload(Payload payload, CancellationToken cancellationToken)
211211
}
212212
}
213213

214-
private async Task UploadPayloadFile(Guid payloadId, string destinationPath, string sourcePath, string source, string[] workflows, string contentType, CancellationToken cancellationToken)
214+
private async Task UploadPayloadFile(Guid payloadId, string destinationPath, string sourcePath, string source, List<string> workflows, string contentType, CancellationToken cancellationToken)
215215
{
216216
Guard.Against.Null(payloadId, nameof(payloadId));
217217
Guard.Against.NullOrWhiteSpace(destinationPath, nameof(destinationPath));

0 commit comments

Comments
 (0)