10 internal enum CanUploadResult
31 internal class UploadInformation
34 private long byteCount;
35 private int fileCount;
36 private DateTime startedAt;
37 private readonly
object synchObject;
38 private LinkedList<SpecialFile> specialFiles;
46 this.bareJid = BareJid;
49 this.startedAt = DateTime.MinValue;
50 this.synchObject =
new object();
51 this.specialFiles =
null;
66 public CanUploadResult CanUploadFile(
long Size,
FilePurpose Purpose, HttpFileUploadSettings Settings)
68 lock (this.synchObject)
73 DateTime Now = DateTime.Now;
74 TimeSpan TS = Now - this.startedAt;
76 if (TS.TotalMinutes >= 1.0)
83 if (this.fileCount >= Settings.MaxFilesPerMinute)
84 return CanUploadResult.FileQuotaReached;
86 if (this.byteCount + Size > Settings.MaxBytesPerMinute)
87 return CanUploadResult.ByteQuotaReached;
92 if (
string.IsNullOrEmpty(Settings.KeyFolder) ||
string.IsNullOrEmpty(Settings.BackupFolder))
93 return CanUploadResult.FileQuotaReached;
97 if (
string.IsNullOrEmpty(Settings.EncryptedStorageFolder) ||
string.IsNullOrEmpty(Settings.EncryptedStorageRoot))
98 return CanUploadResult.FileQuotaReached;
102 if (
string.IsNullOrEmpty(Settings.PubSubStorageFolder) ||
string.IsNullOrEmpty(Settings.PubSubStorageRoot))
103 return CanUploadResult.FileQuotaReached;
107 if (
string.IsNullOrEmpty(Settings.InternalTransferFolder) ||
string.IsNullOrEmpty(Settings.InternalTransferRoot))
108 return CanUploadResult.FileQuotaReached;
113 this.byteCount += Size;
127 public bool TryGetSpecialFile(
string FileName,
string FileContentType,
long FileSize, out SpecialFile Result)
129 lock (this.synchObject)
131 if (!(this.specialFiles is
null))
133 foreach (SpecialFile Rec
in this.specialFiles)
135 if (Rec.FileName == FileName && Rec.FileContentType == FileContentType && Rec.FileSize == FileSize)
155 public void AddSpecialFile(
string FileName,
string FileContentType,
long FileSize,
FilePurpose Purpose)
157 lock (this.synchObject)
159 if (!(this.specialFiles is
null))
161 foreach (SpecialFile Rec
in this.specialFiles)
163 if (Rec.FileName == FileName && Rec.FileContentType == FileContentType && Rec.FileSize == FileSize)
165 Rec.Purpose = Purpose;
171 if (this.specialFiles is
null)
172 this.specialFiles =
new LinkedList<SpecialFile>();
174 this.specialFiles.AddLast(
new SpecialFile(Purpose, FileName, FileContentType, FileSize));
185 public bool RemoveSpecialFile(
string FileName,
string FileContentType,
long FileSize)
187 lock (this.synchObject)
189 if (!(this.specialFiles is
null))
191 LinkedListNode<SpecialFile> Loop = this.specialFiles.First;
193 while (!(Loop is
null) &&
194 (Loop.Value.FileName != FileName ||
195 Loop.Value.FileContentType != FileContentType ||
196 Loop.Value.FileSize != FileSize))
203 this.specialFiles.Remove(Loop);
Represents a case-insensitive string.
FilePurpose
Purpose of file uploaded