Skip to content
Snippets Groups Projects
Commit f136099a authored by Klaus Fischer's avatar Klaus Fischer
Browse files

WIP: resolve warnings

parent 28cfdb89
No related branches found
No related tags found
1 merge request!125Feature/1522 chunking
......@@ -76,7 +76,7 @@ public class Subscriber : FitConnectClient, IReceivedSubmission,
if (Submission?.Id == null || Submission?.Metadata == null)
throw new Exception("No submission available");
var attachments = Submission.Attachments;
var attachments = Submission.Attachments;
return attachments ?? new List<Attachment>();
}
catch (Exception e) {
......@@ -509,7 +509,12 @@ public class Subscriber : FitConnectClient, IReceivedSubmission,
: (JsonConvert.DeserializeObject(jsonString) as JObject)?["$schema"]?.ToString();
}
private record DownloadedAttachment(Guid Id, byte[]? Content, byte[] Hash, string? Filename, string AuthenticationTag) {
private record DownloadedAttachment(
Guid Id,
byte[]? Content,
byte[] Hash,
string? Filename,
string AuthenticationTag) {
public DataHash GetAttachmentHash() {
if (Content != null)
return FitEncryption.CalculateHash(Content);
......@@ -558,12 +563,14 @@ public class Subscriber : FitConnectClient, IReceivedSubmission,
(_, content, hash) = Encryption.Decrypt(encryptedAttachment);
string? filename = null;
if (isFragment) {
if (container == null)
throw new FitConnectSubscriberException("Attachment is fragment but container is null");
var path = Path.Combine(TempFilePath, submission.SubmissionId.ToString(),
container.AttachmentId.ToString());
Directory.CreateDirectory(path);
filename = Path.Combine(path, $"downloaded.{index:0000}");
await File.WriteAllBytesAsync(filename, content);
// continue;
}
downloaded.Add(new DownloadedAttachment(id, content, hash, filename, authenticationTag));
......@@ -592,8 +599,8 @@ public class Subscriber : FitConnectClient, IReceivedSubmission,
}
private Dictionary<Guid, string> CombineLargeAttachments(Submission submission, List<DownloadedAttachment> downloaded) {
private Dictionary<Guid, string> CombineLargeAttachments(Submission submission,
List<DownloadedAttachment> downloaded) {
Dictionary<Guid, string> authenticationTags = new();
var largeAttachments = submission.Metadata?.ContentStructure.Attachments?.Where(a => a.Fragments != null)
?.ToList();
......@@ -602,7 +609,8 @@ public class Subscriber : FitConnectClient, IReceivedSubmission,
foreach (var largeAttachment in largeAttachments) {
var fragments = largeAttachment.Fragments.Select(f => downloaded.First(d => d.Id == f)).ToList();
var filenames = fragments.OrderBy(f => f.Filename).Where(f => f.Filename != null).Select(f => f.Filename).ToList();
var filenames = fragments.OrderBy(f => f.Filename).Where(f => f.Filename != null).Select(f => f.Filename)
.ToList();
if (filenames.Any(f => f == null))
throw new FitConnectSubscriberException("Filename in the fragments is null");
......@@ -617,6 +625,7 @@ public class Subscriber : FitConnectClient, IReceivedSubmission,
downloaded.Add(new DownloadedAttachment(largeAttachment.AttachmentId, null, hash, attachmentPath, ""));
authenticationTags.Add(largeAttachment.AttachmentId, "");
}
return authenticationTags;
}
......@@ -864,7 +873,6 @@ public class Subscriber : FitConnectClient, IReceivedSubmission,
/// <exception cref="SecurityEventException"></exception>
private async Task CheckAttachments(Submission submission,
SecurityEventToken submitEvent) {
if (submission?.Attachments != null) {
// @formatter:off
......@@ -945,4 +953,4 @@ public interface IReceivedReply : ISubmissionBody {
public Metadata Metadata { get; set; }
public AuthenticationTags AuthenticationInformation { get; set; }
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment