-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSharedFileData.cs
More file actions
83 lines (63 loc) · 2.2 KB
/
SharedFileData.cs
File metadata and controls
83 lines (63 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using ByteSync.Common.Business.SharedFiles;
using ByteSync.Common.Helpers;
namespace ByteSync.ServerCommon.Business.Sessions;
public class SharedFileData
{
public SharedFileData()
{
}
public SharedFileData(SharedFileDefinition sharedFileDefinition, ICollection<string> recipients)
{
SharedFileDefinition = sharedFileDefinition;
UploadedPartsNumbers = new HashSet<int>();
Recipients = new List<string>();
foreach (var recipient in recipients)
{
var cleanedData = recipient;
if (recipient.StartsWith("CIID_"))
{
cleanedData = recipient.Substring("CIID_".Length);
}
Recipients.Add(cleanedData);
}
DownloadedBy = new Dictionary<int, HashSet<string>>();
}
public SharedFileDefinition SharedFileDefinition { get; set; } = null!;
public HashSet<int> UploadedPartsNumbers { get; set; } = null!;
public bool IsFullyUploaded
{
get
{
return TotalParts != null && UploadedPartsNumbers.Count == TotalParts;
}
}
public int? TotalParts { get; set; }
public List<string> Recipients { get; set; } = null!;
public Dictionary<int, HashSet<string>> DownloadedBy { get; set; } = null!;
public bool IsFullyDownloaded
{
get
{
return IsFullyUploaded && Recipients.Count > 0
&& DownloadedBy.Keys.Count == TotalParts
&& DownloadedBy.Values.All(v => Recipients.HaveSameElements(v));
}
}
public void SetDownloadedBy(string clientInstanceId, int partNumber)
{
if (!DownloadedBy.ContainsKey(partNumber))
{
DownloadedBy.Add(partNumber, new HashSet<string>());
}
DownloadedBy[partNumber].Add(clientInstanceId);
}
public bool IsPartFullyDownloaded(int partNumber)
{
if (DownloadedBy.TryGetValue(partNumber, out var value))
{
return Recipients.HaveSameElements(value);
}
return false;
}
public StorageProvider StorageProvider { get; set; }
}